How to create a swap partition in Linux ?

1. Run the following command to create a file of 1 GB, for example:

# dd if=/dev/zero of=/swapfile bs=1M count=1000 

2. Run the following command to modify the file permissions :

 # chmod 600 /swapfile 

3.Run the following command to configure the file as swap space:

 # mkswap /swapfile 

4.Run the following command to activate the swap file:

 # swapon /swapfile 

5. To mount the swap partition automatically upon system startup, add an entry for the swap file to /etc/fstab.

 # echo "/swapfile swap swap defaults 0 0" >>/etc/fstab 

6. Run the following command to mount the swap partition:

 # mount -a 

Follow me

Contact us for Training/ Job Support

Caution: Your use of any information or materials on this website is entirely at your own risk. It is provided for educational purposes only. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.