Many Ubuntu Server administrators have encountered this frustrating scenario: after a fresh installation, the system hangs indefinitely during boot with the message:
Adding 524284k swap on /dev/mapper/test--vg-swap_1. Priority:-1 extents:1 across:524284k
While the recovery mode workaround exists (dropping to recovery and resuming normal boot), this isn't a sustainable solution for production environments.
The issue typically stems from LVM (Logical Volume Manager) configuration problems during swap space initialization. Several factors can contribute:
- Incorrect UUID mapping in /etc/fstab
- Missing or corrupt swap signature
- Race conditions in device initialization
- Filesystem check failures on LVM volumes
First, verify your current swap configuration:
sudo swapon --show
sudo blkid | grep swap
sudo cat /proc/swaps
Check your fstab entries:
sudo cat /etc/fstab | grep swap
Option 1: Reinitialize Swap Space
sudo swapoff -a
sudo mkswap /dev/mapper/test--vg-swap_1
sudo swapon /dev/mapper/test--vg-swap_1
Then update fstab with the new UUID:
sudo nano /etc/fstab
Option 2: Modify Systemd Swapon Service
Create an override file to add dependencies:
sudo systemctl edit dev-mapper-test\x2d\x2dvg\x2dswap_1.swap
Add these lines:
[Unit]
After=systemd-udev-settle.service
After=lvm2-activation.service
Edit your grub configuration:
sudo nano /etc/default/grub
Add to GRUB_CMDLINE_LINUX_DEFAULT:
resume=/dev/mapper/test--vg-swap_1 noresume
Update grub and reboot:
sudo update-grub
sudo reboot
Post-reboot, verify the swap is active:
free -h
lsblk -f
systemctl status dev-mapper-test\\x2d\\x2dvg\\x2dswap_1.swap
Check dmesg for swap-related messages:
sudo dmesg | grep -i swap
Remember to test these solutions in a staging environment before applying to production systems. The exact approach may vary based on your specific LVM configuration and Ubuntu Server version.
Recently while deploying a fresh Ubuntu Server 22.04 LTS instance, I encountered an unusual boot hang during system initialization. The system would consistently freeze at:
[ 3.451236] Adding 524284k swap on /dev/mapper/test--vg-swap_1. Priority:-1 extents:1 across:524284k
Interestingly, booting into recovery mode and selecting "Resume normal boot" would bypass the issue, suggesting this is specifically related to swap activation during early boot.
After examining the LVM setup, here's what I found in /etc/fstab
:
/dev/mapper/test--vg-swap_1 none swap sw 0 0
And the corresponding output from lvdisplay
:
--- Logical volume --- LV Path /dev/test-vg/swap_1 LV Name swap_1 VG Name test-vg LV UUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx LV Write Access read/write LV Creation host, time ubuntu-server, 2023-08-15 14:32:15 +0000 LV Status available # open 0 LV Size 512.00 MiB Current LE 128 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
Temporary solution was to edit grub and add noswap
to boot parameters, but this wasn't ideal for production. After deeper investigation, I discovered the system was trying to activate swap before the LVM devices were fully available.
Here's how I modified the boot sequence:
# First, backup the original initramfs sudo cp /boot/initrd.img-$(uname -r) /boot/initrd.img-$(uname -r).bak # Then update it with proper LVM hooks sudo update-initramfs -u -k all
The root cause was missing LVM dependencies in the initramfs. Here's the complete fix procedure:
- Edit the LVM configuration:
- Rebuild the initramfs:
- Update grub:
sudo nano /etc/lvm/lvm.conf
Find and uncomment or add:
use_lvmetad = 0
sudo update-initramfs -u
sudo update-grub
After applying these changes, verify the boot process:
# Check initramfs contents lsinitramfs /boot/initrd.img-$(uname -r) | grep lvm # Test the new configuration sudo systemctl daemon-reload sudo systemctl restart lvm2-lvmetad.service
For more reliable swap activation, consider using UUID instead of device mapper path. First find your swap UUID:
sudo blkid /dev/mapper/test--vg-swap_1
Then modify /etc/fstab
:
# Old entry # /dev/mapper/test--vg-swap_1 none swap sw 0 0 # New entry UUID=xxxx-xxxx-xxxx-xxxx-xxxx none swap sw 0 0
Remember to update initramfs after making these changes.