How to add swap file in linux

This entry was posted in Linux and tagged on June 17, 2012, by

Sometime its necessary to add swap space after installation. Follow the steps to add it.

1. Login as the root user.

2. Type following command to create 512 MB swap file. i.e (512*1024=524288 block size)

# dd if=/dev/zero of=/swapfile bs=1024 count=524288

3. Setup the swap file

# mkswap /swapfile

4. Activate the swap file

# swapon /swapfile

5 .To see if the swap space is added run the following command

# cat /proc/swaps

You will see the swap file is added.

6. To activate the swap file when the system boots, edit into  /etc/fstab file

# vi /etc/fstab

/swapfile swap swap defaults 0 0

Save and quit ( :wq)

7.So when the system reboots next time , it will enable swap file automatically. Verify is the swap activated after reboot

# free -m

How to remove swap file

1. First disable the swap file

# swapoff -v /swapfile

2. Remove the enty from /etc/fstab file

3. Remove the actual file

# rm /swapfile

4. To see if it is removed

# cat /proc/swaps

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright 2017 ©Aceadmins. All rights reserved.