Skip to content

Swapon Fails With read swap header failed or Invalid argument: Causes and Fix

Updated 5 min read

Updated: 9 October 2026 · Applies to: util-linux 2.41.5 (Debian 13), 2.41.3 (Ubuntu 26.04), 2.39.3 (Ubuntu 24.04), 2.40.2 (AlmaLinux 10.2) and 2.37.4 (Rocky Linux 9.8)

swapon: /dev/sdb2: read swap header failed means swapon found no swap signature on that partition or file. Either it was never prepared with mkswap, the signature was overwritten (a new filesystem, a repartitioned or wiped disk), or /etc/fstab points to the wrong device. Check what is on it, and only if it really is your swap area, write a new signature and turn it on:

sudo blkid /dev/sdb2        # no output or TYPE="swap": safe to continue
sudo mkswap /dev/sdb2       # overwrites the start of the device
sudo swapon /dev/sdb2
swapon --show

Replace /dev/sdb2 with your swap device or file. If blkid shows a filesystem such as TYPE="ext4" or TYPE="xfs", stop: that device holds data and your fstab entry is wrong.

What the error means

Before swapon asks the kernel for anything, it reads the first 64 KiB of the device and looks for the swap signature (SWAPSPACE2, or the marker hibernation leaves behind) at the end of the first page, trying each page size from 4 KiB to 64 KiB. If the read fails or no signature is there, it prints read swap header failed and stops. We got exactly this for a file full of zeros on all five tested releases, and for an empty file and a 4 KiB file on Debian 13:

# swapon /root/zero.img
swapon: /root/zero.img: read swap header failed

blkid printed nothing for that file, while a prepared swap file shows its type:

# blkid good.img zero.img
good.img: UUID="ebf5044f-7427-48a4-b8d4-92ff7a9a4572" TYPE="swap"

Fix it step by step

  1. Find the swap entries the system tries to use: grep swap /etc/fstab. Run lsblk -f to see every device with its filesystem type and UUID.
  2. Run sudo blkid DEVICE on the failing one. No output means there is no signature. TYPE="swap" means the header is fine, and the problem is elsewhere (see Invalid argument below). Any other type means the wrong device.
  3. If a device name changed (for example after adding a disk, sdb became sdc), point fstab at the swap by UUID instead of by name: UUID=the-uuid none swap defaults 0 0.
  4. Recreate the signature with sudo mkswap DEVICE (add -c on a partition to check for bad blocks first; on a file mkswap says this is not supported). mkswap prints the new UUID:
    # mkswap good.img
    Setting up swapspace version 1, size = 64 MiB (67104768 bytes)
    no label, UUID=ebf5044f-7427-48a4-b8d4-92ff7a9a4572
  5. Each mkswap run creates a new UUID. If fstab uses UUID=, either update fstab or keep the old one with sudo mkswap -U OLD-UUID DEVICE (tested: the UUID stayed the same).
  6. Turn it on with sudo swapon DEVICE, or sudo swapon -a for everything in fstab, and check:
    $ swapon --show
    NAME      TYPE      SIZE USED PRIO
    /dev/sda2 partition 1.2G 6.6M   -2

Encrypted swap with a random key is a special case: the swap option in /etc/crypttab runs mkswap on the mapped device at every boot, according to the crypttab manual, so a missing signature there points to a crypttab problem. See how to encrypt swap with a random key.

Other swapon messages and what they mean

We triggered each of these with test files:

  • skipping - it appears to have holes.
    The swap file was made with truncate or copied with cp. Recreate it (below).
  • insecure permissions 0644, 0600 suggested.
    Only a warning: sudo chmod 600 /swapfile.
  • swap format pagesize does not match. (Use --fixpgsz to reinitialize it.)
    The area was made on a system with a different memory page size, such as 64 KiB pages. sudo swapon --fixpgsz DEVICE runs mkswap again.
  • software suspend data detected. Rewriting the swap signature.
    Leftover hibernation data; swapon repairs the signature itself.
  • cannot find the device for UUID=...
    The UUID in fstab no longer exists (disk replaced or mkswap run again). Put the current UUID from blkid in fstab.
  • swapon failed: Operation not permitted
    You are not root, or you are inside a container: swap needs the CAP_SYS_ADMIN capability, so containers cannot add swap.

swapon failed: Invalid argument

This comes from the kernel after swapon's own checks have passed. According to the swapon manual pages, the usual causes are:

  • a swap file with holes or a preallocated file the filesystem treats as one (preallocated swap files work on XFS since Linux 4.18);
  • a copy-on-write file on Btrfs (swap files need the nocow attribute, supported since Linux 5.0);
  • a file on tmpfs, or on NFS ("swap over NFS may not work");
  • a device without a valid signature.

Device or resource busy means that area is already in use: check swapon --show. For a swap file, the reliable fix is to create it again with dd, which writes every block:

sudo swapoff /swapfile
sudo rm /swapfile
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048 status=progress
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

On Debian 13, Ubuntu 26.04 and AlmaLinux 10, sudo mkswap --file --size 2G /swapfile does the same in one step: our test file came out fully allocated with mode 0600. Older versions lack the option: Rocky Linux 9 answers mkswap: unrecognized option '--file', and the mkswap help on Ubuntu 24.04 does not list it either.

The old advice to run mke2fs -c before mkswap is not needed: mkswap writes its own signature, and mkswap -c checks a partition for bad blocks. If that check finds errors, replace the disk.

More on swap: create a Linux swap file, add a new swap partition and swap space management for beginners.

Official documentation: swapon(8), swapon(2) and mkswap(8).

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket