How to add or remove swap space

Swap space refers to the portion of the virtual memory which is reserved as a temporary storage location.

Check memory and available space

$ free -mh
$ df -h

Enable the swap file

# create a 2G swap file
$ dd if=/dev/zero of=/myswap bs=1024 count=2048000
# mark the file as swap space
$ mkswap /myswap
# enable the swap file
$ swapon /myswap

Make the swap file permanent

$ echo '/myswap none swap sw 0 0' >> /etc/fstab

Disable the swap space

$ swapoff /var/swap
$ rm /swap

Then you should remove the line includes ‘/swap’ from /etc/fstab


[1] How To Add Swap Space on Ubuntu 16.04

本文作者: Vincent0700
版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!