(Solved) How To Add Swap Space on Ubuntu 16.04

How To Add Swap Space on Ubuntu

How to increase swap space


A swap file can help you avoid these issues by utilizing hard drive space as virtual memory when regular memory is not immediately available.

First check swap is available by typing: 
# sudo swapon --show
We can check swap in MB Size.
# free -h
We can check all partition in MB Size.
# free –h
# parted –l
# sfdisk -l –uM
# df –h
# df -h | grep ^/dev
# lsblk
Create the Swap File:
We will create a 4 GiB file (/var/swapfile.img) to use as swap:
fallocate size suffixes: g = Giga, m = Mega, etc.
# sudo fallocate -l 4g /var/swapfile.img
Make the file only accessible to root by typing:
# sudo chmod 600 /var/swapfile.img
Verify the permissions change by typing:
# ls -alsh /var/swapfile.img
Format the file as swap:
# sudo mkswap /var/swapfile.img
Enable use of Swap File
# sudo swapon /var/swapfile.img
We can verify that the procedure was successful by checking whether our system reports swap space and priority.
# sudo swapon -s
Enable Swap File at Bootup
# echo '/var/swapfile.img none swap defaults,pri=100 0 0' | sudo tee -a /etc/fstab
Check Swap File at Bootup
# grep swap /etc/fstab
Verify swap is available by typing:
# sudo swapon --show
We can check the free utility again.
# free -h
Enjoy




SHARE

Ibrar Ansari

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment