How can I increase the swap partition in Linux?

To increase the swap partition of Linux, you can follow these steps:

  1. Check if there is an existing swap partition in the current system. You can use the following command to check the status of the swap partition:
sudo swapon --show

If there are no displayed swap partitions, it means that there are no swap partitions in the current system.

  1. Create a file for swapping partitions. You can use the following command to create a swap partition file (for example, 4GB):
sudo fallocate -l 4G /swapfile
  1. Set the file permissions to only allow the root user to read and write.
sudo chmod 600 /swapfile
  1. Convert the file into a swap partition.
sudo mkswap /swapfile
  1. Enable swap partition.
sudo swapon /swapfile
  1. Check if the swap partition is enabled.
sudo swapon --show

The newly added swap partition should be visible.

  1. To enable the swap partition to automatically start at system boot, you need to add it to the /etc/fstab file. Open the file:
sudo nano /etc/fstab

Add the following lines at the end of the file.

/swapfile none swap sw 0 0

Save and close the file.

After completing the above steps, the partition swap has been successfully added to the Linux system.

bannerAds