SWAP Partition in Linux: How to?

What is SWAP ? Why we need SWAP Partition ?

Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the physical memory is full, inactive pages in memory are moved to the swap space.

Swap space is located on hard drives, which have a slower access time than physical memory.


How to create SWAP Partition ?
1. Create a file system on disk

#fdisk /dev/cciss/c?d?

Note : Make the new partition as swap. Change toggle id to 82 (for swap).

2. Make the FS as Swap partition

#mkswap /dev/cciss/c?d?p?

3. Run swapon commad to enable swap space

#swapon /dev/cciss/c?d?p?

4.Verify the new swap partition

    #cat /proc/swap


    #swapon -s

5. Add this new swap partion entry to /etc/fstab

vi /etc/fstab

/dev/cciss/c?d?p? swap swap defaults 0 0

How to remove the swap partion ?

1.swapoff -v /dev/VolGroup00/swap_vol

2.lvremove /dev/VolGroup00/swap_vol

3. Remove the entry from /etc/fstab


How to increase / extend SWAP partion ?

Follow the below steps to increase the Swap for LVM

    # swapoff -v /dev/rootvg/swapvol
    # lvextend -L +8G /dev/rootvg/swapvol
    # mkswap /dev/rootvg/swapvol
    # swapon -va

Post a Comment