How to Move Swap From Disk Partition to LVM Volume in Linux

There is no command or method exists that allows you to move swap space from one location to another. You can turn off the current swap space with swapoff command in the original location.

1. Turn swapoff on old disk:

# swapoff /dev/device
Note – Assuming there is free space in volume group, we will continue with LVM volume creation. Also, ensure that you do this when you have a maintenance window. (All applications are not running)

2. Create LVM Partition:

# lvcreate -L  -n logical_volume vol_group

3. Format the new swap space:

# mkswap /dev/[vg_name]/[lv_name]

4. Test that the swap has been created on logical volume.

# cat /proc/swaps

5. Enable the extended logical volume:

# swapon /dev/[vg_name]/[lv_name]

6. Add the swap entry in /etc/fstab.

Related Post