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 7: Line 8:
sudo mkswap /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon /swapfile
</syntaxhighlight><syntaxhighlight lang="shell" line="1">
sudo nano /etc/fstab
sudo nano /etc/fstab
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang="shell-session">
<syntaxhighlight lang="bash" start="3">
/swapfile swap swap defaults 0 0
/swapfile swap swap defaults 0 0
</syntaxhighlight>Check the swap and its usage:<syntaxhighlight lang="shell" line="1">
</syntaxhighlight>
'''Swap Off'''
<syntaxhighlight lang="shell" line="1">
sudo swapoff -a    # sudo swapoff /swapfile
sudo rm -f /swapfile
sudo nano /etc/fstab
</syntaxhighlight>
<syntaxhighlight lang="bash" start="3">
#/swapfile swap swap defaults 0 0
</syntaxhighlight>'''Check'''<syntaxhighlight lang="shell" line="1">
sudo swapon --show
sudo swapon --show
sudo free -h
sudo free -h

Revision as of 17:36, 17 August 2022

Add/​​​Remove Swap­file 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

sudo swapon --show
sudo free -h