8/12/2018 - 9:31 AM

Ubuntu enable swap file #linux

Ubuntu enable swap file #linux

Ubuntu 18.04 enable swap file

check Swap

swapon --show

Check free memory and disk

free -h
// or 
df -h
a) Make swap off
# swapoff /var/swapfile

b) Resize the swapfile (increase or decrease). 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

c) Make swapfile usable
# mkswap /var/swapfile

d) Make swapon 
# swapon /var/swapfile

d-1) change permission to 0600
# chmod 0600 /var/swapfile

e) Verify the swapfile 
# swapon -show

Make swap file permanent

echo '/var/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab