Create swap on linux

Date Posted: 01-08-2017

Swap space will usually be a disk partition but can also be a file. Users may create a swap space during installation of Linux or at any later time should it become necessary. Swap space is generally recommended for users with less than 1 GB of RAM

Implemetation:

Follow these steps to create swap space for your server.

Run these commands to make a swapfile:-

sudo dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
sudo mkswap /var/swap.img
sudo swapon /var/swap.img

Run free again to confirm you now have a swapfile.
free -m

To make the swap file persist if the server is rebooted:
sudo chmod 0600 /var/swap.img
sudo chown root:root /var/swap.img

Open fstab file
sudo nano /etc/fstab

Append the following line to the end of the file:
/var/swap.img none swap sw 0 0

Save the file and exit

Leave a Reply

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny