Skip to content

Instantly share code, notes, and snippets.

@henri
Last active January 23, 2025 23:09
Show Gist options
  • Save henri/bd1f9aece821e0693d8488393e599cfe to your computer and use it in GitHub Desktop.
Save henri/bd1f9aece821e0693d8488393e599cfe to your computer and use it in GitHub Desktop.
linux swap cheatsheet
# NOTES
#
# - this approach has been tested on mint (will work on many other distributions as well - YMMV)
# - this approach uses swap files not partitions
#
# create a 5GB swap disk to use - run as root!
swapon --show
mkdir /swapfiles ; chmod 700 /swapfiles
fallocate -l 5G /swapfiles/swap1
chmod 600 /swapfiles/swap1 ; ls -la /swapfiles/swap1
mkswap /swapfiles/swap1
swapon /swapfiles/swap1
swapon --show
# optionally append to /etc/fstab
/swapfiles/swap1 none swap sw 0 0
# ADDITIONL NOTES
#
# - if you do not append to /etc/fstab
# then the file will *** NOT *** be clearned up automatically after reboot.
#
# - if you did not appened to /etc/fstab
# best to manually remove file or consider adding to fstab (instructions above)
# so you are not chewing up disk space unessasarly
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment