Skip to main content

HowTo make swapfile

Script creates swapfile in current dir with size of physical RAM
(you can just CopyPaste to terminal)

ram=$(($(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*')/1024/1024+1))

touch ./swapfile
chattr +C ./swapfile #btrfs fix
sudo fallocate -l ${ram}G ./swapfile
sudo chmod 600 ./swapfile
sudo mkswap ./swapfile
sudo swapon ./swapfile

swapon --show

Swap is not permanent, to make it permanent:

sudo cp /etc/fstab /etc/fstab.bak

echo "$PWD/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

Sources