Linux – Howto Increase swap Space In Runtime?

You can increase swap space in runtime as below. Below example shows howto add 1 GB swap space in existing swap space.

Steps :

1.  First check existing swap space.

# free -mt

2. Create new zero filled file as below.

# dd if=/dev/zero of=/var/swapfile-1G.swp bs=1M count=1024

3. Change the permissions of file.

# chmod 600 /var/swapfile-1G.swp

4. Convert this file as file drive.

# mkswap /var/swapfile-1G.swp

5. Now attach this file drive in existing swap.

# swapon /var/swapfile-1G.swp

6. You can also detach this file drive using following command.

# swapoff /var/swapfile-1G.swp