Extend or create new swap file

I'm scared of dd, I use fallocate

  • Create the swap file:

    sudo fallocate -l XG /swapfile

    Where X is the swapfile size in GB

    sudo mkswap /swapfile
    sudo chmod 0600 /swapfile
    sudo swapon /swapfile
    
  • Reboot:

    sudo reboot
    
  • There is a slight possibility of getting holes in a swapfile when creating it with fallocate. /var/log/syslog can be searched for the phrase swapon: swapfile has holes to ensure there will be no data loss.