Linux Swap and Swapfile: Difference between revisions
From WikiMLT
Line 32: | Line 32: | ||
=== Swap On/Off Scripts === | === Swap On/Off Scripts === | ||
<syntaxhighlight lang="shell"> | <syntaxhighlight lang="shell" class="mlw-continue"> | ||
swap-on.sh | swap-on.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 48: | Line 48: | ||
echo | echo | ||
sudo free -h | sudo free -h | ||
</syntaxhighlight> | |||
</syntaxhighlight><syntaxhighlight lang="shell"> | <syntaxhighlight lang="shell" class="mlw-continue"> | ||
swap-off.sh | swap-off.sh | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 63: | Line 63: | ||
echo | echo | ||
sudo free -h | sudo free -h | ||
</syntaxhighlight> | |||
<noinclude> | |||
<div id='devStage'> | <div id='devStage'> | ||
{{devStage | {{devStage |
Revision as of 16:45, 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