Increase Linux Swap Space

To expand the swap space in Linux, you can follow these steps:

  1. Firstly, check the current system’s swap space usage using the command free -h.
  2. Create a new swap file to expand swap space. You can use the sudo fallocate -l [size] [file path] command to create a new swap file. The size can be a number followed by G (GB) or M (MB). For example, sudo fallocate -l 2G /swapfile2 creates a 2GB swap file.
  3. Use the command “sudo chmod 600 [file path]” to set the correct permissions for the newly created swap file.
  4. Convert the swap file to a swap partition by using the command sudo mkswap [file path]. For example, sudo mkswap /swapfile2.
  5. Enable new swap space with the command sudo swapon [file path]. For example, sudo swapon /swapfile2.
  6. Open the /etc/fstab file for editing using the command sudo nano /etc/fstab.
  7. Add a line to the /etc/fstab file to automatically enable the new swap space. For example, add /swapfile2 none swap sw 0 0.
  8. Save and close the /etc/fstab file.
  9. Check if the new swap space has been successfully enabled by using the command sudo swapon –show.
  10. Check the system’s swap space usage again with the free -h command to make sure that the new swap space has been successfully extended.

Please note that increasing swap space may impact system performance, so it is recommended to adjust it accordingly based on the actual needs of the system.

bannerAds