Skip to content

Instantly share code, notes, and snippets.

@tjvr
Last active March 13, 2024 17:06
Show Gist options
  • Save tjvr/f82004565139a5b13031af1ce5a50a02 to your computer and use it in GitHub Desktop.
Save tjvr/f82004565139a5b13031af1ce5a50a02 to your computer and use it in GitHub Desktop.
Hibernate on Ubuntu 18.04 with LVM full-disk encryption
sda5_crypt UUID=c66880c1-c2f1-40fc-9580-f25d493876ef none luks,discard
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/ubuntu--vg-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/sda1 during installation
UUID=3a4152dc-b401-4ae3-96b7-b8da7d918023 /boot ext4 defaults 0 2
/dev/mapper/ubuntu--vg-swap_1 none swap sw 0 0
$ swapon -s
Filename				Type		Size	Used	Priority
/dev/dm-2                              	partition	16777212	0	-2
texas:~$ sudo lvdisplay
[sudo] password for tim: 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                vEByY0-UUvE-OgLU-caQo-gku0-yt05-9l70KP
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2018-07-07 15:08:49 +0100
  LV Status              available
  # open                 1
  LV Size                420.00 GiB
  Current LE             107520
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                L3AKIc-rK4X-uy4l-jFuM-C1fc-TrNt-yodzsL
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2018-07-07 15:08:49 +0100
  LV Status              available
  # open                 2
  LV Size                16.00 GiB
  Current LE             4096
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

The fix

Edit /etc/initramfs-tools/conf.d/resume:

RESUME=/dev/mapper/ubuntu--vg-swap_1

Edit /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=/dev/mapper/ubuntu--vg-swap_1"
sudo update-initramfs -u -k all
sudo update-grub
HandleSuspendKey=hibernate
HandleLidSwitch=hybrid-sleep
@zerkms
Copy link

zerkms commented Feb 29, 2020

with LVM full-disk encryption

is your /boot not encrypted though?

@OlegSmelov
Copy link

This works on 20.04 as well, but I had to boot from Live USB to shrink root and extend swap_1 first.

@StarGW-net
Copy link

Good guide, thanks. Worked fine on my Ubuntu 20.10.

Some juggling required to get the swap partition to the same size as the memory:

https://www.stargw.net/wiki/Lenovo%20Yoga%20Slim%207/index.html#Relayout

@iambumblehead
Copy link

this works using arch linux as well

@davidhackn
Copy link

Anyone know if this works on Ubuntu 22.04? Also, I'm new to Linux, can anyone translate some of the commands up top, ie. can you go through what needs to be done in the steps above to set up my machine to do this?

@zerkms
Copy link

zerkms commented Aug 2, 2022

@davidhackn for me 20.04 and 22.04 did not require to do anything at all to have hibernation working (I install ubuntu's using this guide: https://help.ubuntu.com/community/Full_Disk_Encryption_Howto_2019)

ps: gnight :-D

@tebaly
Copy link

tebaly commented Dec 20, 2023

I suspect that all data in memory will be saved to disk unencrypted. then why would you need to encrypt the entire disk? for safety? this way you save all the RAM in unencrypted form... for safety?..

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