Root Cause Diagnosis
Swap is activated at boot by systemd from /etc/fstab entries (via systemd-fstab-generator, which creates dev-disk-by\x2duuid-<UUID>.swap units) or from native .swap units. If the swap area is absent from /etc/fstab, the fstab entry references a stale UUID or device name (/dev/sdXN names change between boots), or the swap signature is missing, the unit never starts and swapon is never called. Manual swapon works until the next reboot because it modifies only the running kernel state, not persistent configuration.
Quick Fix
Find the swap partition’s UUID, add it to /etc/fstab, and activate it:
lsblk -f
sudo blkid | grep -i swap
echo 'UUID=<your-swap-uuid> none swap sw 0 0' | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
sudo swapon -a
swapon --show
Replace <your-swap-uuid> with the value from blkid. If blkid shows no TYPE="swap", the partition has no swap signature; run sudo mkswap /dev/sdXN first (destroys any data on it) and use the new UUID.
Step-by-Step Resolution
1. Check current swap state and boot logs
swapon --show
free -h
systemctl list-units --type=swap --all
journalctl -b -u '*.swap' --no-pager
journalctl -b | grep -iE "swap|fstab"
No output from swapon --show confirms swap is inactive. Failed or missing .swap units in the journal identify whether the entry is absent or broken.
2. Identify the swap partition and its UUID
lsblk -o NAME,SIZE,TYPE,FSTYPE,UUID,PARTUUID,MOUNTPOINTS
sudo fdisk -l | grep -i swap
A valid swap partition shows FSTYPE = swap. Partition type GUID on GPT disks is 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F; on MBR it is type 82. The type flag is informational, and the signature is what matters.
3. Create the swap signature if it is missing
Only when FSTYPE is empty and you have confirmed the partition holds no data:
sudo mkswap /dev/sdXN
Note the UUID= printed in the output. To set a label as an alternative identifier:
sudo mkswap -L swap0 /dev/sdXN
4. Add or correct the entry in /etc/fstab
Edit /etc/fstab and keep exactly one line per swap area:
UUID=3f7c1a2e-8b4d-4e6a-9c21-5d0b7a1e9f44 none swap sw 0 0
Use UUID= or PARTUUID= instead of /dev/sdXN. Device names are assigned in probe order and change with added disks, NVMe/SATA enumeration order, or USB devices. Fields must be separated by whitespace, and none is the mount point for swap.
For a swap file:
/swapfile none swap sw 0 0
5. Validate before rebooting
sudo systemctl daemon-reload
sudo findmnt --verify --verbose
sudo swapoff -a
sudo swapon -a
swapon --show
findmnt --verify reports syntax errors and unresolvable UUIDs. swapon -a activates everything in fstab with the sw option. Errors here are the same errors that occur at boot.
6. Optionally set priority and boot behavior
UUID=3f7c1a2e-8b4d-4e6a-9c21-5d0b7a1e9f44 none swap sw,pri=10,nofail 0 0
nofail lets boot continue if the device is absent, and pri= orders multiple swap areas (higher is used first; equal priority values stripe across areas).
7. Use a native systemd unit as an alternative
Create /etc/systemd/system/dev-disk-by\x2duuid-3f7c1a2e\x2d8b4d\x2d4e6a\x2d9c21\x2d5d0b7a1e9f44.swap. Generate the escaped name with:
systemd-escape -p --suffix=swap /dev/disk/by-uuid/3f7c1a2e-8b4d-4e6a-9c21-5d0b7a1e9f44
[Unit]
Description=Swap partition
[Swap]
What=/dev/disk/by-uuid/3f7c1a2e-8b4d-4e6a-9c21-5d0b7a1e9f44
[Install]
WantedBy=swap.target
sudo systemctl daemon-reload
sudo systemctl enable --now dev-disk-by\\x2duuid-3f7c1a2e\\x2d8b4d\\x2d4e6a\\x2d9c21\\x2d5d0b7a1e9f44.swap
8. Reboot and verify
sudo reboot
# after boot
swapon --show
systemctl status '*.swap'
Why This Fails for Some Users
- Reinstalled or cloned system with old UUID: Reformatting swap with
mkswapgenerates a new UUID. The old UUID in /etc/fstab no longer resolves, and systemd waits for a device that never appears (up to 90 s by default). Update fstab with the new UUID, or pass-U <old-uuid>tomkswapto reuse it. - Debian/Ubuntu
initramfsresume config: The file /etc/initramfs-tools/conf.d/resume containsRESUME=UUID=.... If it points at a stale swap UUID, boot delays by several seconds and hibernate breaks. Fix and rebuild:sudo update-initramfs -u -k allOn Fedora, RHEL, and Arch, check theresume=kernel parameter in /etc/default/grub and regenerate the bootloader config (grub2-mkconfig -o /boot/grub2/grub.cfgorupdate-grub). - Swap on LVM: Use the logical volume path (
/dev/mapper/vg0-swap) or its UUID. The volume group must be active early; a brokenlvm2initramfs hook or a missingrd.lvm.lv=parameter (Fedora/RHEL) leaves the LV inactive at swap activation. - Encrypted swap (
crypttab): Random-key swap requires a /etc/crypttab entry and an fstab entry that points at the mapper device:cryptswap /dev/disk/by-partuuid/<partuuid> /dev/urandom swap,cipher=aes-xts-plain64,size=512/dev/mapper/cryptswap none swap sw 0 0UsePARTUUIDor a stableby-idpath in crypttab, since a random-key swap has no persistent filesystem UUID (mkswapruns on every boot and generates a new one). - Swap file on Btrfs: Btrfs swap files must be created with copy-on-write disabled and no compression. Use
btrfs filesystem mkswapfile --size 4g /swapfile(btrfs-progs 6.1+) orchattr +Con an empty file before allocating. Swap files also cannot span multiple devices or sit on a snapshotted subvolume. - Swap file with holes or wrong permissions: Files created with
fallocatefail on some filesystems (XFS on older kernels, F2FS) and produceswapon: skipping - it appears to have holes. Create withdd if=/dev/zero of=/swapfile bs=1M count=4096, thenchmod 600 /swapfileandmkswap /swapfile. Permissions looser than0600produce a warning; and on newerutil-linux, the swap file must be owned by root. - Filesystem mounted late: If the swap file lives on a separate mount (/data/swapfile), systemd starts the swap unit only after that mount is ready. A mount failure or
noautoon the parent silently prevents swap activation. Addx-systemd.requires-mounts-for=/dataif ordering is wrong. - Cloud images and containers: Many cloud images ship without swap and manage it through
cloud-init. Themounts:orswap:module in /etc/cloud/cloud.cfg can overwrite /etc/fstab on each boot. Also,cloud-initand Azure/WALinuxAgent (ResourceDisk.EnableSwap=yin /etc/waagent.conf) may recreate swap on the ephemeral disk, which is wiped on redeploy. - Swap as ZRAM:
zram-generator(Fedora, Arch) orzram-config(Ubuntu) provides in-RAM swap and may replace or coexist with disk swap. Checkzramctland /etc/systemd/zram-generator.conf. Priority conflicts cause the disk swap to be unused even when active. swapoffon shutdown andnofailhidden failures: Withnofail, activation errors do not surface in boot output. Checkjournalctl -b -u '*.swap'explicitly.- SELinux/AppArmor: Not a normal cause, but a mislabeled swap file (
swapfile_tmissing on RHEL-family) may generate AVC denials. Checkausearch -m avc -ts bootand restore withrestorecon -v /swapfile. - Kernel or partition table changes: Resizing the partition or changing the GPT table after
mkswapinvalidates the swap header size.swaponfails withread swap header failed. Re-runmkswapon the resized partition.