Linux swapfile with systemd
by rusty-snake
Preliminary notes:
- This is a short transcript of the steps necessary to add a swapfile under linux. For a more detailed explanation I refer to the ArchWiki page.
- Unlike the most other tutorials for swapfiles you will find in the internet that add the swapfile to fstab, we will create a swapfile.swap systemd unit.
- This tutorial assumes that you have a working zram swap device with priority 100.
Create the swapfile
mkswap --check -U clear --size 4G --file /swapfile
Create a systemd swap unit for it
systemctl edit --full --force swapfile.swap
systemctl enable --now swapfile.swap
[Unit]
Description=Disk Swap on /swapfile
[Swap]
What=/swapfile
Priority=50
Options=discard
[Install]
WantedBy=swap.target