Configure Swap File

Guide to create and configure a swap file on a Linux machine.


Configuring a Swap File on a Linux machine

Swap files provide more efficient resource allocation by allowing the operating system to prioritize memory usage based on application requirements

  1. Check your current swap file storage. Run command free -h
  2. Create a swapfile. Run command sudo fallocate -l 1G /swapfile
  3. Only the root user should have permissions to read and write to the swap file. Update permissions by running the command sudo chmod 600 /swapfile
  4. Use the mkswap command to setup the file as a swap area. Run command sudo mkswap /swapfile
  5. Enable the swap file with the swapon command. Run command sudo swapon /swapfile
  6. Verify that the swapfile is on and configured correctly. Run command sudo swapon --show
  7. Running the command from step 1 will now show the new available swap memory.

Additional Guide Links