How to create a swap partition in Linux

Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
  • User AvatarANKUSH THAVALI
  • 15 Oct, 2022
  • 0 Comments
  • 35 Secs Read

How to create a swap partition in Linux

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