Linux Swap and Swapfile: Difference between revisions
From WikiMLT
Line 64: | Line 64: | ||
sudo free -h | sudo free -h | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==References== | |||
*[https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/ How To Add Swap Space on Ubuntu 18.04] | |||
*[https://askubuntu.com/q/969296/566421 How to delete a swap file in Ubuntu?] | |||
<noinclude> | <noinclude> |
Revision as of 16:48, 17 August 2022
Add/Remove Swapfile Short Guide
Swap On
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo nano /etc/fstab
/swapfile swap swap defaults 0 0
Swap Off
sudo swapoff -a # sudo swapoff /swapfile
sudo rm -f /swapfile
sudo nano /etc/fstab
#/swapfile swap swap defaults 0 0
Check the swap and its usage
sudo swapon --show
sudo free -h
Swap On/Off Scripts
swap-on.sh
#!/bin/bash
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo sed 's_^#/swapfile_/swapfile_' /etc/fstab -i
echo
sudo swapon --show
echo
sudo free -h
swap-off.sh
#!/bin/bash
sudo swapoff /swapfile
sudo rm -f /swapfile
sudo sed 's_^/swapfile_#/swapfile_' /etc/fstab -i
echo
sudo swapon --show
echo
sudo free -h
References