Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Iwwww/008ef082a52cc509d186889118412aa6 to your computer and use it in GitHub Desktop.
Save Iwwww/008ef082a52cc509d186889118412aa6 to your computer and use it in GitHub Desktop.
Enabling hibernation on Arch Linux with LUKS LVM encryption using a swap partition

Introduction

Enabling hibernation on Arch Linux is a useful feature that allows you to save your current system state to your hard disk and power off your computer. When you turn your computer back on, you can resume from where you left off, which is a great way to save time and improve productivity.

Here is a step-by-step guide on how to enable hibernation on Arch Linux.

My setup

I used this installation instruction.

My disk partition structure:

lsblk -o NAME,SIZE,TYPE,MOUNTPOINTS,UUID

NAME            SIZE TYPE  MOUNTPOINTS UUID
nvme0n1       476.9G disk
├─nvme0n1p1      16M part
├─nvme0n1p2   186.2G part              01D8F6AC42C2CC60
├─nvme0n1p3     685M part
├─nvme0n1p4     500M part  /efi        2F12-A09A
├─nvme0n1p5   289.4G part              a2709dc3-66d7-4d68-8719-1f32e17e5e85
│ └─cryptlvm  289.4G crypt             8w6gNW-bECu-oX6g-yDRS-sXNV-x1QU-4CWYh5
│   ├─vg-swap    20G lvm   [SWAP]      b016fde8-8380-4f68-a63b-03c7773b2e06
│   ├─vg-root    85G lvm   /           010f7fa0-c679-459e-9b10-ea44c5f33793
│   └─vg-home 184.4G lvm   /home       4b38b2fe-3f6b-4643-b679-603aec1bd693
└─nvme0n1p9     200M part              10DA-8844

Setup hibernation

1. Chack swap partition

Check if your swap partition is already set up by running the following command:

sudo swapon --show

If your swap partition is not listed, activate it with the following command:

sudo swapon /dev/mapper/vg-swap

Before activation, you may need to turn off the existing swap partitions with the following command:

sudo swapoff -a

2. Configure mkinitcpio.conf

Edit the /etc/mkinitcpio.conf file and add the resume module to the MODULES line and the resume hook to the HOOKS line. The resume hook allows the system to resume from hibernation by setting up the swap partition.

sudo nano /etc/mkinitcpio.conf
MODULES=(amdgpu encrypt resume filesystems)
HOOKS="base udev autodetect modconf block keyboard keymap encrypt lvm2 resume filesystems fsck"

Regenerate the initramfs image using the mkinitcpio command:

sudo mkinitcpio -p linux

3. Configure GRUB

Edit the /etc/default/grub file and add the resume parameter to the GRUB_CMDLINE_LINUX_DEFAULT line. This parameter specifies the location of the swap partition.

sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="cryptdevice=/dev/sdaX:cryptlvm resume=/dev/mapper/vg-swap"

Replace /dev/sdaX with the partition that contains the encrypted system and replace /dev/mapper/vg-swap with the logical volume name for the swap partition.

In my case:

GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 quiet cryptdevice=UUID=a2709dc3-66d7-4d68-8719-1f32e17e5e85:cryptlvm resume=/dev/mapper/vg-swap root=/dev/vg/root"

Regenerate the GRUB configuration file using the grub-mkconfig command.

sudo grub-mkconfig -o /boot/grub/grub.cfg

4. Reboot the system

Reboot your system before hibernate.

How to use hibernation

  1. Use sudo systemctl hibernate to hibernate.

    You can also go into hibernation mode without sudo after some configuration tweaking.

  2. Lock your screen before hibernation.

    If you do not do this, then you will not need a password after booting from hibernation.

    Read about session lock.

    You could use some utilities to lock your screen:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment