ErrorFixDB Logo
โ† Back to Database

How to Fix Failed to activate swap

Topic: Linux Ubuntu Boot Errors | Status: Updated

What is this error?

The "Failed to activate swap" error in Linux Ubuntu typically occurs during the boot process when the system is unable to initialize the swap space. This can prevent the system from effectively using memory and may lead to performance issues or system instability.

How to Fix It

  1. Check Swap Status: Open a terminal (Ctrl + Alt + T) and run the command: swapon --show. This will display the current status of swap partitions.
  2. Verify Swap File or Partition: If no swap is listed, check if a swap file or partition exists. To locate a swap file, run: cat /etc/fstab. Ensure thereโ€™s a line that references a swap file (e.g., /swapfile) or a swap partition like /dev/sdX.
  3. Create a Swap File (if missing): If no swap file or partition exists, create a swap file with the following commands: sudo fallocate -l 2G /swapfile (for a 2GB swap file)
  4. Set Correct Permissions: Set the correct permissions for the swap file by running: sudo chmod 600 /swapfile.
  5. Initialize the Swap File: Activate the swap file with: sudo mkswap /swapfile and then enable it using: sudo swapon /swapfile.
  6. Add to fstab: To ensure the swap file is activated on boot, edit /etc/fstab with sudo nano /etc/fstab and add the line: /swapfile none swap sw 0 0.
  7. Reboot the System: Finally, reboot your machine using sudo reboot to confirm that the error is resolved and that swap space is being used successfully.
Disclaimer: This is an educational guide. We are not responsible for data loss. Always backup your system.