Resolving Linux Swap Partition Not Mounting Automatically on System Reboot

Root Cause Diagnosis

This issue occurs when the /etc/fstab configuration file contains an invalid, outdated, or missing UUID reference for the swap partition, often caused by repartitioning or OS reinstalls that regenerate disk identifiers. It can also stem from systemd mount timeouts, uninitialized swap headers on the partition, or fast-boot settings skipping secondary storage initialization during cold boots. Consequently, the kernel bypasses the swap target during startup, leaving system memory unassisted.

Quick Fix

Identify the active swap partition block device and enable it instantly for the current session without rebooting:

Bash

# Locate swap partition and enable it immediately
sudo swapon $(lsblk -no PATH,FSTYPE | grep -i swap | awk '{print $1}')

Step-by-Step Resolution

Step 1: Identify the Swap Partition and Its Current UUID

Locate the block device designated for swap and retrieve its file system UUID:

Bash

# List all block devices and check for swap type
lsblk -f

Look for a partition labeled with FSTYPE="swap" (e.g., /dev/sda2 or /dev/nvme0n1p3). Note down its UUID.

Step 2: Initialize the Swap Structure (If Missing)

If lsblk shows the partition but lacks a valid swap signature or UUID, write the swap header:

Bash

sudo mkswap /dev/sdXN

(Replace /dev/sdXN with your actual swap partition, such as /dev/sda2.) Output will print the newly generated UUID.

Step 3: Update the /etc/fstab Mount Entry

Open the file system table in a text editor:

Bash

sudo nano /etc/fstab

Locate the swap entry line, or append it if missing. Ensure it points to the correct UUID:

Plaintext

# <file system>                           <mount point>   <type>  <options>       <dump>  <pass>
UUID=12345678-abcd-1234-abcd-123456789abc none            swap    sw              0       0

Save and close the file.

See also  Fixing SSH Error: Host Key Verification Failed After VPS Re-installation

Step 4: Test and Verify the Configuration

Test mounting all entries in /etc/fstab without restarting:

Bash

# Activate all swap devices listed in /etc/fstab
sudo swapon -a

# Verify swap status
free -h
# OR
swapon --show

If free -h reflects your swap capacity, the /etc/fstab configuration is valid.

Why This Fails for Some Users

  • Encrypted Swap (LUKS/dm-crypt): If swap resides on an encrypted partition, /etc/fstab cannot mount it directly at boot without an entry in /etc/crypttab. Without a configured keyfile or initramfs hook, the decryption step fails silently before the swap mount target executes.
  • Systemd Masked Swap Units: On systemd-managed distributions (Ubuntu, Fedora, Arch), systemd dynamically generates units like dev-sdXN.swap. If a unit is masked or disabled (systemctl is-enabled dev-sdXN.swap), systemd ignores /etc/fstab instructions on boot.
  • NVMe/SATA Controller Driver Delay in Initramfs: Fast-boot systems or custom kernels may fail to load storage controller drivers inside initramfs before systemd executes the swap mount task, triggering a systemd mount timeout (Job dev-disk-by\x2duuid-...\x2eswap/start timed out).
  • Btrfs/LVM Volume Group Inactivity: When swap is hosted on a logical volume (LVM) or software RAID array, missing systemd target dependencies (lvm2-monitor.service or mdadm) cause the volume group to remain inactive during the early boot phase when swap assembly runs.

Leave a Comment