SWAP Space Management


A SWAP space is an area of a disk which can be used for memory management subsystem. Swap space are used to supplement the system RAM by holding inactive pages of memory.

How to create a swap space: 

To create a swap space, needs to do three things:
1. Create partition.
2. Set the type of the partition as 82 Linux Swap.
3. Format the type signature on the device.

How to create SWAP space

Create a 500 MiB SPAP space:
1. Create a 500 MiB partition on /dev/vdb on Linux swap.
            # fdisk /dev/vdb
2. Print the table, and then create a new partition that is 500 MiB in size.
            # p
            # n
            # p
            # 1
            # +500M         (Enter size we want to create SWAP Space)
            # p
3. Set new created partition to type Linux swap.
            # t
            # 1
            # L
            # 82
            # p
4. Save the partition table changes.
            # w
5. Run the partprobe to make the kernel aware of the partition table change.
            # partprobe
6. Initiate the newly created partition as swap space.
            # mkswap /dev/vdb1
7. Enable newly created swap space.
   7.1 To See created swap space is enable use following command.
            # free 
   7.2 Enable created space as a SWAP space.
            # swapon /dev/vdb1
   7.3 Verify that the newly created swap space is available.
            # free
8. Configure new swap space so that it is enable at boot.
    8.1 Determine UUID of the new swap partition on the first disk.
            # blkid /dev/vdb1
    8.2 Add an entry to /etc/fstab
            # vim /etc/fstab
            Paste here UUID        swap    swap    defaults           0          0         
    8.3 Test enabling the swap space using the entry.
            # swapon –a
    8.4 Verify that the new swap space was enabled.
            # free

Most Reading