How to Configure an 8GB Swap Space on Rocky Linux and Encourage System Usage

Rocky Linux 9 is designed to be robust and compatible with most configurations out of the box. Typically, setting up a swap space as detailed earlier does not require any additional dependencies. However, it’s always good practice to ensure your system is up-to-date before proceeding with any significant changes.

🔄 Step 1: Update Your System

Before setting up the swap space, update your system to ensure all packages are up-to-date. This can help avoid any compatibility issues. Run the following command in your terminal:

sudo dnf update -y

🛠️ Step 2: Create an 8GB Swap File

Proceed to create the swap file by following these commands:

sudo dd if=/dev/zero of=/swapfile bs=512M count=16 status=progress
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

##sudo dd if=/dev/zero of=/swapfile bs=256M count=32 status=progress#

📝 Step 3: Make the Swap File Permanent

To ensure the swap file remains active across reboots, add it to the /etc/fstab file:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

⚙️ Step 4: Adjust the Swappiness Value

Set the swappiness value to control how aggressively your system uses the swap space:

echo 'vm.swappiness=70' | sudo tee /etc/sysctl.d/99-swappiness.conf
sudo sysctl -p /etc/sysctl.d/99-swappiness.conf
echo 'vm.swappiness = 70' | sudo tee -a /etc/sysctl.conf

🏁 Conclusion

Your Rocky Linux 9 system is now equipped with an 8GB swap file, with the system fully updated and configured to use the swap efficiently. This setup will enhance the performance, especially in scenarios requiring extensive memory usage.

Scroll to Top