I'm on Ubuntu 13.04 using full disk encryption (LVM on top of LUKS).

I would like to incorporate luksSuspend into the suspend procedure (and later use luksResume) so that I can suspend to RAM without leaving key material on memory and the root unlocked.

I've been trying for the last 7 hours to port a script for Arch Linux, so far without success: I honestly have no idea of what I'm doing...

Can anyone help me port this (or create something like this from scratch)? Or, at least, can anyone point me to documentation about how to hook stuff into the suspend procedures and how to keep the necessary binaries and scripts (such as cryptsetup) available even after all IO to root has been blocked (by luksSuspend)?

Concerning how to keep the necessary binaries and scripts available for resume, this other blog post (also for Arch) copied them to /boot; I would like however to use something more in the lines what Vianney used in the script I mentioned before, because that approach appears to be a bit more elegant in this aspect.

  • I spend a few more hours on this... Sep 23, 2013 at 7:38
  • I edited the scripts that make up pm-suspend and it appeared that I was almost there. However, I found out that I can't just suspend the system (echo -n "mem" > /sys/power/state) after freezing the root fs (cryptsetup luksSuspend ...), for that requires some i/o still... Sep 23, 2013 at 7:51
  • 1
    I read a few discussions on Debian lists (and some other lists that linked or were linked to these ones) and, so far, it appears that on solution would require something like a "deinitramfs": the kernel would handle control over to the deinitramfs just before actually suspending the system, so that this tmpfs could perform the final cleanup actions (such as wiping the encryption key for the rootfs). Sep 23, 2013 at 7:52
  • I'd really like to see this question answered too. Oct 10, 2013 at 20:12

3 Answers 3


I've come across the same problem, so I took another shot at porting the same script, which you can see here. It doesn't touch any non-volatile storage after luksSuspend, so it works even with real full-disk encryption with an encrypted /boot. However, you'll need to be careful -- it might not work as expected occasionally!

The ported script does the following:

  • Create a ramfs mount somewhere
  • Extract the contents of initramfs there (including the initramfs suspend script)
  • Bind mount relevant directories (e.g. /sys, /proc, /dev, /run) to the ramfs mount
  • Stop any services that may interfere (systemd-udevd, systemd-journald)
  • Remount the root filesystem (ext4 or btrfs) with nobarrier so Linux doesn't hang while trying to go into S3, then sync
  • Chroot into the initramfs mount, which syncs again, runs luksSuspend, and puts the computer to sleep
  • After wake, luksResume, remount filesystems, restart services, unmount bind mounts in the initramfs mount
  • Finally, unmount the initramfs mount so that we free the RAM used for the initramfs files

I've yet to do extensive testing on my script, but it seems to work reliably for me. If you use another filesystem (i.e. not ext4 or btrfs), then you might experience issues with barrier, so you'll need to modify the script too.

Either way, it's good to test and verify that the scripts work first. If you experience hangs while attempting to put Linux into S3 (i.e. at echo mem > /sys/power/state), then you should be able to recover:

  • Before suspending, open a tty or other terminal (that will be accessible, so ideally a tty)
  • Load cryptsetup and relevant libraries into RAM: sudo cryptsetup luksResume anything_here
  • Suspend using the script
  • If it hangs after the chroot (e.g. after starting version xxx is displayed on the new vt), switch to the tty you opened earlier and run sudo cryptsetup luksResume your_luks_device_name_here
  • If that hangs too, open another vt and chroot into /run/initramfs: sudo chroot /run/initramfs /bin/ash
  • Try to run luksResume: cryptsetup luksResume your_luks_device_name_here && exit
  • Your computer should then suspend. You can then wake it up, kill the script(s) if they are still running, unmount the bind mounts and /run/initramfs, and remount your root filesystem with barrier if applicable.

I don't have experience with this setup, but many people claim success in this. Here are a couple of them.

dm-crypt with LUKS - Encrypting the Swap partition
Howto: Completly encrypted harddisk including the suspend to disk partition with Ubuntu 6.10 Edgy Eft

However none of them uses luksSuspend (which might be why they work).

  • Thanks for the links... I'm using a setup similar to the last link (auto generated by the 13.04 installer). Nov 16, 2013 at 3:33
  • No luksSuspend so far, must power off to clear the keys from memory... Nevertheless, thanks for the links! Maybe by understanding how to configure this manually I can gain some insight on how to use luksSuspend for suspeding to ram. Nov 16, 2013 at 3:39
  • 1
    luksSuspend seems extremely difficult to use. As it freezes all I/O, one needs a very acrobatic suspend script. I could find only one success-story in German which can be (badly) translated into English. Try using it as a template.
    – harrymc
    Nov 16, 2013 at 8:31
  • 2
    You might also need to use a ram-disk and a statically-linked cryptsetup.
    – harrymc
    Nov 16, 2013 at 8:55

I spent some time getting this fully functional on Ubuntu 15.10. If you are trying to make this work on ext2, ext3, or ext4 you will need to update /etc/fstab to mount the volume with the 'nobarrier' option. Otherwise, I suggest using BTRFS.

Once your filesystem is prepped, use the script here: https://github.com/Microcentillion/ubuntu-lukssuspend

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .