Create a swap file, swapfile must not be copy-on-write

file='/swapfile'
# create file
touch "$file"
# No Copy-on-Write
chattr +C "$file"
# Allocate 10 GB  (much faster than dd)
fallocate -l 10G "$file"
# Set permissions to make mkswap happy
chmod 600 "$file"
# Set swap file signature
mkswap "$file"
# change owner if not already root to make swapon happy
sudo chown root "$file"
# Activate
sudo swapon "$file"
To set at startup add to /etc/fstab
echo '/swapfile none swap sw 0 0' | sudo tee --append /etc/fstab
Reload init config:
systemctl daemon-reload

No comments: