Linux Swap and Swapfile: Difference between revisions
From WikiMLT
mNo edit summary |
|||
Line 2: | Line 2: | ||
== Add/Remove Swapfile Short Guide == | == Add/Remove Swapfile Short Guide == | ||
=== Swap On === | |||
<syntaxhighlight lang="shell" line="1"> | <syntaxhighlight lang="shell" line="1"> | ||
sudo fallocate -l 4G /swapfile | sudo fallocate -l 4G /swapfile | ||
Line 13: | Line 14: | ||
/swapfile swap swap defaults 0 0 | /swapfile swap swap defaults 0 0 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Swap Off === | |||
<syntaxhighlight lang="shell" line="1"> | <syntaxhighlight lang="shell" line="1"> | ||
sudo swapoff -a # sudo swapoff /swapfile | sudo swapoff -a # sudo swapoff /swapfile | ||
Line 21: | Line 23: | ||
<syntaxhighlight lang="bash" start="3"> | <syntaxhighlight lang="bash" start="3"> | ||
#/swapfile swap swap defaults 0 0 | #/swapfile swap swap defaults 0 0 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Check the swap and its usage === | |||
<syntaxhighlight lang="shell" line="1"> | |||
sudo swapon --show | |||
sudo free -h | |||
</syntaxhighlight> | |||
=== Swap On/Off Scripts === | |||
<syntaxhighlight lang="shell"> | |||
swap-on.sh | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="bash" start="3" line="1"> | |||
#!/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 | sudo swapon --show | ||
echo | |||
sudo free -h | sudo free -h | ||
</syntaxhighlight><syntaxhighlight lang="shell"> | |||
swap-off.sh | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="bash" start="3" line="1"> | |||
#!/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 | |||
<noinclude> | </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