Monday, December 19, 2016

Managing Swap space in Red Hat Linux

1. To extend a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Extend the logical volume by 1GB
# lvm lvresize /dev/VolGroup00/LogVol05 -L +1G

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


2. To reduce a swap logical volume

a. Disable swapping for the concerned logical volume
# swapoff -v /dev/VolGroup00/LogVol05

b. Reduce the logical volume by 512MB
# lvm lvresize /dev/VolGroup00/LogVol05 -L -512M

c. Format the logical volume
# mkswap /dev/VolGroup00/LogVol05

d. Enable the swap device
# swapon -va


3. To list all the configured swap devices:

# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mapper/VolGroup00-LogVol05         partition       6062072 2180    -1


4. To list the total/used/free swap space:

# free -tm
             total       used       free     shared    buffers     cached
Mem:          7983       7918         65          0        585       4943
-/+ buffers/cache:       2389       5594
Swap:         5919          2       5917
Total:       13903       7920       5982


5. To create a swap file of size 100MB :

# dd if=/dev/zero of=/swap1 bs=1024 count= 102400
# chmod 0600 /swap1
# mkswap /swap1
# swapon /swap1

Finally add the below entry in /etc/fstab so that it enables on every boot.

/swap1          swap            swap    defaults        0 0


6. To enable swap space on a file :

# swapon -v /swap1


7. To disable swap space on a file :

# swapoff -v /swap1

No comments: