How to Change a Swap File on AlmaLinux 9

To change a swap file on AlmaLinux 9, follow these steps:

Step 1 : Check the current swap configuration by running the command:

Step 2 : Turn off the current swap by executing:

Step 3 : Edit the /etc/fstab file and comment out the line related to the old swap file (usually the line containing swap).

Step 4 : Create a new swap file with the desired size (in this case, 4GB):

Step 5 : Set the proper permissions for the swap file:

Step 6 : Set up the swap area on the newly created file:

Step 7 : Enable the new swap file:

Step 8 : Verify that the new swap file is active:

Step 9 : Edit the /etc/fstab file to add the new swap file configuration so it persists after reboot:

Add the following line:

Congratulations, you have successfully changed the swap file on AlmaLinux 9!