To create a swap file on CentOS Stream 9, follow these steps.
Step 1 : Begin by checking the current free memory on your system using the following command:
Step 2 : Verify the available disk space on your system using:
Step 3 : Create Swap File. Allocate space for the swap file. In this example, a 2GB swap file is created:
Step 4 : Adjust the permissions of the swap file for security:
Step 5 : Mark the file as swap space:
Step 6 : Activate the swap file:
Step 7 : Confirm that the swap file is active:
Step 8 : To ensure the swap file is activated on boot, add the following line to /etc/fstab
:
Congratulations! You have successfully created a swap file on CentOS Stream 9.