How to Enable Swap Memory on Linux
If your system shows Swap: 0B 0B 0B, it means there is no active swap space. Follow these steps to check and enable swap.
1️⃣ Check If a Swap Partition Exists
Run:
lsblk | grep swap
If no output appears, you don't have a swap partition.
2️⃣ Check If Swap Is Configured in /etc/fstab
Run:
cat /etc/fstab | grep swap
If there is no output, swap is not set up.
3️⃣ Create a Swap File (If No Swap Exists)
If there is no swap partition, create a swap file manually:
Step 1: Create a 2GB Swap File
sudo fallocate -l 2G /swapfile # Create a 2GB swap file
sudo chmod 600 /swapfile # Secure it
sudo mkswap /swapfile # Format as swap
sudo swapon /swapfile # Enable swap
Step 2: Verify Swap is Active
free -mh
swapon --show
Step 3: Make Swap Persistent
To make the swap file persist after reboot, add this line to /etc/fstab:
/swapfile none swap sw 0 0
4️⃣ If You Have a Swap Partition, Enable It
If lsblk shows a swap partition (e.g., /dev/sdX), activate it with:
sudo swapon /dev/sdX # Replace /dev/sdX with the actual partition name
5️⃣ Disable Swap Temporarily (Optional)
If you need to disable swap for a while, use:
sudo swapoff -a
To re-enable it:
sudo swapon -a
Now your system should have active swap memory! 🚀
Written by A.M. Rinas