Mohan pd.
Mohan pd. Author of The Coders Blog. Also a professional fullstack javascript developer working with various tech company and client around world.

How to enable swap in ubuntu and debian?

Sep 14, 2019 · 1 min
How to enable swap in ubuntu and debian?
What is swap space?

Swap space in any operating system is amount of disk space reserve for moving inactive pages from RAM. Swap space are of two type dedicate swap or of swap files in linux OS. Here we will create a swap file for the linux system.

We assume that the system does have not swap partition for this guide.

Check if your system already exist swap partition.

Open the terminal, and enter the following command to check.

swapon --show
Check free memory and disk.
 free h
 df -h

If you have sufficient space in you hard-disk then lets continue.

Step:1 Make swap off
swapoff /var/swapfile
Step 2: Resize the swapfile

Here let us increase to 2GB (assuming existing one has 1GB space as given in the article)

 dd if=/dev/zero of=/var/swapfile bs=1024k count=2000
Step 3: Make swapfile usable
 mkswap /var/swapfile
Step 4: Make swapon
 swapon /var/swapfile
Step 5: Change permission to 0600
 chmod 0600 /var/swapfile

Step 6: Verify the swapfile
 swapon -show
Step 7: Make swap file permanent
echo '/var/swapfile none swap sw 0 0' | tee -a /etc/fstab

comments powered by Disqus