Creating an LVM2 Logical Volume for Swap
To add a swap volume group (assuming /dev/VolGroup00/LogVol02 is the swap volume you want to add):
Create the LVM2 logical volume of size 256 MB:
# lvcreate -L 1G -n LogVol02 VolGroup00
Format the new swap space:
# mkswap /dev/VolGroup00/LogVol02
Add the following entry to the /etc/fstab file:
/dev/VolGroup00/LogVol02 swap swap defaults 0 0
Enable the extended logical volume:
# swapon -va
Test that the logical volume has been extended properly:
# cat /proc/swaps # free
swapoff /dev/hda3 mkswap /dev/hda4 swapon /dev/hda4
and edit swap entry in /etc/fstab
Check the current swap space
[root@lnxb080 etc]# free -h total used free shared buff/cache available Mem: 7.4Gi 1.4Gi 784Mi 384Mi 5.3Gi 5.0Gi Swap: 2.0Gi 211Mi 1.8Gi [root@lnxb080 ~]# swapon --show NAME TYPE SIZE USED PRIO /dev/dm-6 partition 2G 211.4M -2 [root@lnxb080 ~]# ll /dev/dm-6 brw-rw---- 1 root disk 253, 6 Jan 8 21:00 /dev/dm-6 [root@lnxb080 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 10M 0 part ├─sda2 8:2 0 1005M 0 part ├─sda3 8:3 0 39G 0 part └─mpathd 253:0 0 40G 0 mpath ├─mpathd1 253:2 0 10M 0 part ├─mpathd2 253:3 0 1005M 0 part /boot └─mpathd3 253:4 0 39G 0 part ├─rootvg-root 253:5 0 3G 0 lvm / ├─rootvg-swap 253:6 0 2G 0 lvm [SWAP] ├─rootvg-usr 253:7 0 3G 0 lvm /usr
Disable the swap
# swapoff -v /dev/{swap_partition}
Resize the partition
Format the ne swap space
# mkswap /dev/{swap_partition}
Enable the swap
# swapon /dev/{swap_partition}
Check fstab
[root@lnxb080 etc]# cat fstab ... /dev/mapper/rootvg-swap none swap defaults 0 0
Create the swap file with 4GB
# fallocate -l 4G /swap/swapfile01 or # mkswap -U clear --size 4G --file /swap/swapfile01
Change the permissions
# chmod 600 /swap/swapfile01
Format the swap
# mkswap /swap/swapfile01
Add to /etc/fstab
/swapfile none swap defaults 0 0