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

References

[1] How To Add Swap Space on Ubuntu 16.04


本文作者: Vincent0700
本文地址: https://vincentstudio.info/2019/02/03/009_How_to_add_or_remove_swap_space/
版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!