Linux Swap and Swapfile: Difference between revisions
From WikiMLT
Line 35: | Line 35: | ||
swap-on.sh | swap-on.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="bash" start=" | <syntaxhighlight lang="bash" start="1" line="1"> | ||
#!/bin/bash | #!/bin/bash | ||
Line 52: | Line 52: | ||
swap-off.sh | swap-off.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="bash" start=" | <syntaxhighlight lang="bash" start="1" line="1"> | ||
#!/bin/bash | #!/bin/bash | ||
Revision as of 16:46, 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