Increasing Swap Space Using a Swap File on Linux
Follow these steps to increase the swap space on your Linux system by creating a swap file.
Step 1: Turn Off the Existing Swap
First, you need to turn off the existing swap. This can be done with the following command:
Step 2: Create a New Swap File
Next, create a new swap file. For example, to create an 8GB swap file, use:
Adjust the count
value to change the size of the swap file.
Step 3: Set the Correct Permissions
Set the correct permissions for the swap file to ensure that only the root user can read and write to it:
Step 4: Set Up the Swap Area
Prepare the file to be used as swap:
Step 5: Enable the Swap File
Turn the swap on:
Step 6: Make the Swap File Permanent
To ensure the swap file is used after a reboot, add the following line to /etc/fstab
: