Expanding a Swap Partition

Before You Begin 

Make sure you know the name of the swap volume and the KeyControl clear text path to it. If you do not, use the hcl status command and look at the Registered Devices section. For example:

# hcl status
...

Registered Devices
--------------------------------------------------------------------------------
Disk Name     Cipher       Status                 Clear 
--------------------------------------------------------------------------------
sda3         AES-256      Attached                /dev/mapper/clear_htswap (swap)
 '--> auto_attach=ENABLED, attach_handler=DEFAULT, detach_handler=DEFAULT
sda2            AES-256      Attached                 /dev/mapper/clear_htroot (/)
 '--> auto_attach=ENABLED, attach_handler=DEFAULT, detach_handler=DEFAULT

Procedure 

  1. Log into the VM as root.
  2. Get the UUID of the swap device by using the blkid swap-clear-text-path command. For example:

    # blkid /dev/mapper/clear_htswap
    /dev/mapper/clear_htswap: UUID="62e5b7ca-cc50-409f-ba7d-5f0645c85588" TYPE="swap"
  3. Turn the swap off by entering the command swapoff -a.

    # swapoff -av
    swapoff on /dev/mapper/clear_htswap
    Tip: If the swapoff command does not work, applications are probably using the swap file. You can make a temporary swap space and move the swap there until this procedure is finished. For example:
    # fallocate --length 2GiB /swapfile
    # mkswap /swapfile
    # swapon /swapfile

    You can also try dropping stopping all main applications and then dropping all caches from memory. For details, see your Linux documentation.

  4. Increase the size of the swap device as desired. How you do this depends on the partition type.

  5. Run the partprobe command to reread the partition table. If this command fails because the device is busy, you need to reboot the VM.

    # partprobe /dev/sdb
    Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
    
    # reboot
  6. If you had to reboot the VM in the previous step, turn the swap off again by entering the command swapoff -a.

    # swapoff -av
    swapoff on /dev/mapper/clear_htswap
  7. Recreate the swap device with the same UUID as the old device and turn it back on. For example:

    # mkswap -U "62e5b7ca-cc50-409f-ba7d-5f0645c85588" /dev/mapper/clear_htswap
    mkswap: /dev/mapper/clear_htswap: warning: don't erase bootbits sectors
            on whole disk. Use -f to force.
    Setting up swapspace version 1, size = 2090768 KiB
    no label, UUID=62e5b7ca-cc50-409f-ba7d-5f0645c85588
    # swapon -a
    
    # swapon -s
    NAME      TYPE      SIZE      USED PRIO
    /dev/dm-3 partition 2090768   0    -1