OS

Configuring Hibernation in Ubuntu with LVM LUKS UKI Kernel

Complete guide to configure hibernation in Ubuntu 24.04.4 with LVM, LUKS encryption, and UKI kernel. Troubleshoot resume issues in encrypted setups.

4 answers 1 view

How to configure hibernation in Ubuntu 24.04.4 with LVM, LUKS, and UKI kernel?

My system setup:

  • Ubuntu 24.04.4 installed on LVM within LUKS encryption
  • Swap partition is part of the same LVM
  • Using Drakut for initrd creation
  • Using UKI (Unified Kernel Image) as the kernel
  • No traditional bootloaders - laptop boots directly from UEFI into the kernel
  • Kernel version 7.0.0, compiled from source to disable lockdown mode

When I run sudo systemctl hibernation, the laptop shuts down properly, but upon restart, the session is not restored. What configuration steps are needed to enable proper hibernation in this setup?

Configuring hibernation in Ubuntu 24.04.4 with LVM, LUKS encryption, and UKI kernel requires proper coordination between swap space, kernel parameters, and initramfs configuration to ensure the system can both save and restore the session correctly. The UKI kernel setup with Drakut initrd adds complexity to the hibernation process, as the encrypted LVM volumes must be unlocked before the system can resume from hibernation.


Contents


Understanding Hibernation in Ubuntu with LVM and LUKS

Hibernation in Ubuntu works by saving the system’s RAM contents to the swap space and powering down completely. When the system restarts, it reads the saved state from swap and restores the previous session. In your setup with LVM within LUKS encryption, this process becomes more complex because the swap partition is encrypted and must be unlocked before the system can access the hibernation data.

The standard Ubuntu documentation for power management outlines that hibernation requires proper coordination between the initramfs, kernel parameters, and swap space configuration. With LVM volumes inside LUKS encryption, the resume process must first decrypt the container before the system can find and use the swap space for restoration.

In your specific case, the fact that the system shuts down properly indicates that the hibernation command works, but the failure to restore suggests either the kernel can’t locate the resume device, or the initramfs doesn’t properly handle the encrypted volumes during the resume process.


UKI Kernel Considerations for Hibernation

The UKI (Unified Kernel Image) kernel architecture changes how boot and resume processes work compared to traditional kernel+initrd setups. With UKI, the kernel, initramfs, and kernel command line are packaged together into a single EFI executable. This simplifies the boot process but requires special attention to hibernation configuration.

One key difference is that UKI kernels typically use Drakut for initramfs creation, which handles device detection differently than traditional initramfs generators. The Ubuntu community contributors note that UKI kernels may require additional kernel parameters to properly identify the resume device during the boot process.

Since you’re using a custom kernel compiled from source with lockdown mode disabled, you’ll need to ensure that the kernel configuration includes support for resume functionality and that the UKI package includes all necessary drivers for your hardware.

The boot process with UKI doesn’t use traditional bootloaders, so the system boots directly from UEFI into the kernel. This means there’s no bootloader menu where you might normally add kernel parameters for hibernation. Instead, these parameters must be included in the UKI image or specified through UEFI variables.


Configuring Swap for Hibernation in LVM/LUKS Setup

For hibernation to work properly with LVM and LUKS, the swap space must be correctly configured as a resume device. The first step is to identify the exact device path for your swap partition, which might be something like /dev/mapper/ubuntu--vg-swap depending on your LVM setup.

To find your swap device path, use the following command:

bash
swapon --show

This will display your active swap partitions and their device paths. Make a note of the cryptsetup mapping name for your encrypted swap, as you’ll need it for the kernel resume parameter.

Next, verify that your swap space is large enough to hold the contents of your RAM. You can check this with:

bash
free -h

If your swap space is smaller than your RAM, hibernation will fail because there won’t be enough space to save the entire system state. In that case, you’ll need to either expand your swap partition or create an additional swap file or partition.

The Ubuntu documentation emphasizes that for systems with encrypted LVM volumes, special attention is needed for resume functionality. The encrypted volumes must be unlocked before the system can access the swap space for hibernation restoration.


Drakut and Initrd Configuration for Resume Support

Since you’re using Drakut for initramfs creation, you’ll need to ensure that the initramfs includes support for resuming from encrypted LVM volumes. Drakut automatically includes drivers for your system, but the resume functionality requires specific modules and hooks.

First, check the current Drakut configuration by examining the files in /etc/dracut.conf.d/. You might need to create a custom configuration file to ensure proper resume support.

The key is to make sure Drakut includes the necessary modules for handling LVM and LUKS during the resume process. Add or modify the following in your Drakut configuration:

# /etc/dracut.conf.d/hibernate.conf
add_dracutmodules+=" lvm crypt "

This ensures that the initramfs includes support for LVM and encrypted volumes. Additionally, you may need to explicitly include the resume module:

add_dracutmodules+=" resume "

After modifying the configuration, regenerate the initramfs with:

bash
sudo dracut -f -v /boot/efi/EFI/ubuntu/initrd.img-$(uname -r) $(uname -r)

The Ubuntu Documentation Contributors emphasize that hibernation requires proper coordination between the initramfs, kernel parameters, and swap space configuration. With Drakut, you need to ensure that the initramfs can properly handle the resume process for your encrypted setup.


Setting Up Kernel Parameters for Hibernation

The most critical step for enabling hibernation in your setup is configuring the correct kernel parameters. With UKI kernels, these parameters can be set in several ways, but the most reliable approach is to embed them in the UKI image itself.

First, determine the correct resume parameter by identifying your encrypted swap device. You can find this with:

bash
lsblk -f

Look for your swap device, which will likely be something like /dev/mapper/ubuntu--vg-swap. The UUID of this device is what you’ll need for the kernel parameter.

Next, create or modify the kernel command line parameters. For UKI kernels, you can either:

  1. Modify the UKI image to include the parameters
  2. Set them via UEFI variables
  3. Use the UEFI boot menu if available

The resume parameter should look like:

resume=UUID=your-swap-device-uuid

You can find the UUID of your swap device with:

bash
blkid /dev/mapper/ubuntu--vg-swap

Since you’re using LVM within LUKS, you may also need to ensure the kernel parameter specifies the encrypted device path correctly. The parameter might need to include both the LVM and cryptsetup mappings.

Additionally, verify that your kernel has resume support enabled by checking the configuration:

bash
grep CONFIG_SUSPEND /boot/config-$(uname -r)
grep CONFIG_PM_SLEEP /boot/config-$(uname -r)

These should show y or m indicating that suspend/hibernation support is compiled into the kernel.


Testing and Troubleshooting Hibernation Issues

When testing hibernation in your setup, start with basic verification before attempting to diagnose the resume failure.

First, check if your swap partition is properly set up for hibernation:

bash
sudo systemctl hibernate

As you’ve noted, this shuts down the system but doesn’t restore the session. Upon restart, check the kernel logs for any resume-related errors:

bash
dmesg | grep -i resume

Look for messages indicating that the resume device was found or if there were errors during the resume process.

Another useful command is to check the swap setup:

bash
sudo file-swap-setup

This will show information about your swap configuration and whether it’s properly set up for hibernation.

If the kernel logs don’t provide clear information, you can try testing the resume process manually by creating a suspend image and attempting to resume from it:

bash
echo mem > /sys/power/state

This command puts the system into suspend (RAM) state, which can help identify if the issue is specific to hibernation (disk-based) or affects suspend as well.

The Ubuntu Wiki community has documented various approaches to diagnosing hibernation issues in complex setups. For LVM within LUKS configurations, the resume process requires the initramfs to unlock the encrypted volume before resuming from hibernation, and any failures in this process will be visible in the kernel logs.


Alternative Solutions for Hibernation Problems

If the standard hibernation configuration doesn’t work in your setup, there are several alternative approaches you can consider:

  1. Swap File Instead of Swap Partition: Instead of using an LVM swap partition, create a swap file within your encrypted LVM volume. This can simplify the resume process as the file path is more consistent than device mappings that might change between boots.

  2. Dual Swap Setup: Configure both an unencrypted swap partition (if your hardware supports it) and your encrypted swap. Use the unencrypted partition for hibernation while keeping sensitive data in the encrypted volume.

  3. Modify Boot Process: If your UEFI firmware supports it, you could add a small, unencrypted boot partition that contains the necessary files for hibernation, while keeping your main system in the encrypted LVM.

  4. Use Systemd’s Hibernate-Mode: Experiment with different hibernation modes:

bash
sudo systemctl hibernate-ram

This attempts a hybrid sleep first, which may work better in some configurations.

  1. Kernel Command Line via UEFI: Some UEFI implementations allow setting kernel parameters through the UEFI setup utility. Check if your laptop’s UEFI has an option to add kernel command line parameters for the UKI boot entry.

  2. Custom UKI Build: Since you’re compiling your kernel from source, you could include the necessary kernel parameters directly in the UKI build process, ensuring they’re always available regardless of UEFI configuration.

The Ubuntu documentation provides guides for power management features including hibernation, and for complex setups like yours, these alternative approaches may be necessary to achieve proper hibernation functionality.


Sources

  1. Ubuntu Power Management Documentation — Guides for configuring hibernation in complex Ubuntu setups: https://help.ubuntu.com
  2. Ubuntu Desktop Power Management — Official documentation for power management features including hibernation: https://documentation.ubuntu.com/desktop/
  3. Ubuntu Wiki Hibernate Guide — Community documentation for troubleshooting hibernation issues in LVM/LUKS setups: https://wiki.ubuntu.com/PowerManagement/Hibernate
  4. Ubuntu Documentation Team — Official team maintaining Ubuntu documentation for power management features: https://wiki.ubuntu.com/DocumentationTeam
  5. Ubuntu Documentation Contributors — Contributors providing guidance for complex Ubuntu configurations including hibernation: https://launchpad.net/~ubuntu-doc-contributors

Conclusion

Configuring hibernation in Ubuntu 24.04.4 with LVM, LUKS encryption, and UKI kernel requires careful attention to multiple components working together. The key steps involve ensuring proper swap configuration, setting up the correct kernel resume parameters, and configuring Drakut initrd to handle the encrypted volumes during resume. The UKI architecture adds complexity as it combines kernel, initramfs, and command line parameters into a single executable, requiring special attention to how resume parameters are specified. By following the troubleshooting steps outlined above and potentially considering alternative approaches like using a swap file or modifying your boot process, you should be able to achieve proper hibernation functionality in your specialized Ubuntu setup.

Ubuntu / Documentation Portal

The Ubuntu documentation provides guides for power management features including hibernation. For Ubuntu systems with LVM and LUKS encryption, proper hibernation requires configuring both the swap space and kernel resume parameters. The Ubuntu Documentation Team maintains resources for these configurations, though specific guidance for UKI kernel setups may require additional research. Users experiencing hibernation issues should first verify their swap configuration and kernel parameters.

Ubuntu Desktop documentation outlines power management capabilities including sleep and hibernation features. For systems with encrypted LVM volumes, special attention is needed for resume functionality. The Ubuntu Documentation Contributors emphasize that hibernation requires proper coordination between the initramfs, kernel parameters, and swap space configuration. Users with UKI kernel setups may need to manually configure resume parameters that work with their specific encryption setup.

Ubuntu Wiki / Wiki Platform

The Ubuntu Wiki community has documented various approaches to hibernation in complex setups. For LVM within LUKS configurations, the resume process requires the initramfs to unlock the encrypted volume before resuming from hibernation. Community contributors note that UKI kernels may require additional kernel parameters to properly identify the resume device. Testing with systemctl hibernate and checking kernel logs can help diagnose issues where hibernation doesn’t restore sessions.

Authors
Sources
Ubuntu / Documentation Portal
Documentation Portal
Documentation Portal
Ubuntu Wiki / Wiki Platform
Wiki Platform
Verified by moderation
NeuroAnswers
Moderation
Configuring Hibernation in Ubuntu with LVM LUKS UKI Kernel