Green YGreck Guides FR
🐧 LinuxIntermediate⏱ 10 min5 steps

Add a swap file

Gain headroom when RAM is tight.

  1. Check what exists:
    swapon --show
    free -h
  2. Create a 2 GB file and secure it:
    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
  3. Format it then enable it:
    sudo mkswap /swapfile
    sudo swapon /swapfile
  4. Make it permanent:
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  5. On a Btrfs file system, creating a swap file needs special steps: see your distribution's documentation.