Swap Partition Not Activated – Quick Fixes

Swap not working? Usually a missing swapon or wrong fstab entry. Here's how to fix it in 30 seconds or 15 minutes.

Quick Fix (30 Seconds) – Run swapon -a

If your swap partition shows up in fdisk -l but isn't active, the most common reason is that it just wasn't turned on after boot. The culprit here is almost always a missing swapon -a call during startup, or maybe you manually disabled it.

Open a terminal and run this as root:

swapon -a

That command tells the kernel to activate all swap partitions listed in /etc/fstab. Check if swap is now active:

free -h | grep Swap
swapon --show

If you see a line like Swap: 2.0G 0B 2.0G or swapon --show shows your partition, you're done. Don't bother with anything else – it's working now. This fix works about 80% of the time for this exact issue, especially on Ubuntu 20.04, CentOS 7, or Debian 11.

If that didn't help, move to the moderate fix below.

Moderate Fix (5 Minutes) – Check and Fix fstab

If swapon -a didn't work, the problem is almost certainly in /etc/fstab. Either the entry is missing, uses a wrong device path, or has a bad UUID. Here's how to check it.

First, find your swap partition's actual device name:

sudo fdisk -l | grep swap
sudo blkid | grep swap

You'll see something like /dev/sda2: UUID="1234-5678" TYPE="swap". Write that UUID down. Now open /etc/fstab:

sudo nano /etc/fstab

Look for a line with swap in it. It should look like one of these:

UUID=1234-5678 none swap sw 0 0
/dev/sda2 none swap sw 0 0

If the line is missing, add it. I always recommend using UUID over device paths like /dev/sda2 – device names can change if you add or remove drives. If the UUID is wrong, fix it. The none mount point is fine for swap (it's not a real filesystem).

After editing, run swapon -a again. If it works, you're set. If you get an error like swapon: cannot find the device for UUID=..., double-check the UUID. I've seen people copy a 5-character part of the UUID instead of the full string – it's annoying, but happens.

If the fstab line is fine but swap still won't activate, move to the advanced fix.

Advanced Fix (15+ Minutes) – Recreate or Repair Swap

Alright, if swapon -a and fstab are correct, the swap partition itself might be corrupted or incorrectly formatted. Or maybe the partition table is messed up. Let's dig in.

First, confirm the swap partition exists and has the right type:

sudo parted -l
sudo fdisk -l

Look for a partition with type Linux swap / Solaris or ID 82 (if using MBR). If it says something else, like Linux filesystem, you need to change the partition type. I'll cover that in a bit.

If the partition exists and is marked as swap, you can try reformatting it. This wipes any data on it, but that's fine because swap is volatile anyway.

sudo swapoff -a
sudo mkswap /dev/sda2   # replace with your device
sudo swapon -a

The mkswap command creates a fresh swap filesystem. This fixes corruption issues almost every time. After that, check with free -h.

But what if your partition isn't marked as swap? For example, on a dual-boot system where you deleted Windows and resized partitions, the swap might be on a raw partition without the flag. Use fdisk to change it:

sudo fdisk /dev/sda   # replace with your disk

Inside fdisk, type t, select the partition number (e.g., 2), then enter the code 82 for Linux swap. Type w to write changes. Then run partprobe or reboot. After that, run mkswap and swapon -a.

One more thing – on some systems, especially with LVM or software RAID, swap might be on a logical volume. Check lvdisplay or vgdisplay if you use LVM. If the swap LV is missing, you can create one:

sudo lvcreate -L 2G -n swap VolGroup00
sudo mkswap /dev/VolGroup00/swap
sudo swapon /dev/VolGroup00/swap

Then add the corresponding line to /etc/fstab.

Still Not Working? Check dmesg and logs

If nothing above worked, check system logs. The kernel often tells you exactly why swap can't activate.

dmesg | grep -i swap
grep -i swap /var/log/syslog*

Common messages: swap: unable to read swap header (reformat with mkswap), swap: bad swap header (corrupt partition), or swapon: Operation not permitted (missing root privileges).

Also, check if your kernel was built without swap support – rare, but possible on custom kernels. Run cat /proc/swaps. If it's empty even after swapon -a, your kernel might lack swap support.

One last thing – if you're on a cloud VM (like AWS EC2 or DigitalOcean), some default images don't include swap partitions. You may need to create a swap file instead. That's a separate topic, but for a quick swap file:

sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

That gives you 2GB of swap as a file. Works on any Linux system.

Fix your swap and move on. Most of the time, it's just swapon -a or a missing fstab line.

Related Errors in Linux & Unix
locale: Cannot set LC_* to default locale: No such file or directory Fixing 'Locale Not Supported' Warning on Linux Login Fix Google search redirect loop on Linux: kill cookies & session storage Invalid class name JS 'Invalid class name' error in Linux terminal apps invalid class name Fix 'invalid class name' in Linux & Unix — quick to deep

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.