Results 1 to 4 of 4

Thread: HOWTO hibernate in 18.04

  1. #1
    Join Date
    Feb 2016
    Beans
    5

    HOWTO hibernate in 18.04

    Enabling hibernate in Ubuntu 18.04

    This is one of the probably many ways to enable hibernate in Ubuntu.

    Unfortunately, hibernate still does not work out-of-the-box. And while it is a highly desired feature for laptop users, there is also no easy way to switch it on.

    Here I will describe the steps which I needed to take to enable hibernate on my Lenovo ThinkPad E580, with Xubuntu 18.04.

    I hope this will aid others in their hibernate quest.


    Step 1: Secure Boot
    Before doing anything with hibernate, something about secure boot: these two do not go well together. There is a plethora of reasons which I will not discuss here. There are 2 options: 1) disable secure boot in your BIOS, or 2) use a non-signed kernel.

    If you are dual-booting Windows with Ubuntu, disabling secure boot is annoying: Windows will not boot normally. Without secure boot, you will have to enter your Bitlocker decryption key on each boot. Alternatively, you will have to toggle the secure boot option for each switch between the operating systems.

    My solution: use a non-signed kernel. I am honestly not sure what the consequences are of using an unsigned kernel: I guess it completely disables the concept of “secure boot” for Linux, but otherwise we have to disable it anyway. Also: this works for my system, maybe this approach does not work on other systems. It is also disputed whether GRUB should allow booting unsigned kernels: https://bugs.launchpad.net/ubuntu/+s...2/+bug/1401532

    Either way, go to: http://kernel.ubuntu.com/~kernel-ppa/mainline/ where you can download “official” Ubuntu-build kernels. Pick one, download the deb files for you architecture (you can skip the -lowlatency ones), and install them using:
    Code:
    sudo dpkg -i *.deb
    Reboot.

    Check if hibernate is supported now by:
    Code:
    cat /sys/power/state
    If “disk” is one of them: congratulations! Step 1 achieved!



    Step 2: Enabling encrypted swap with fixed key
    I prefer to write the state of my system to an encrypted disk: in case someone steals your laptop, your memory dump will not be readable. For this, we need to create an encrypted swap which can be unlocked by a fixed key, rather than a random key.

    For enabling encrypted swap, I followed this guide: https://help.ubuntu.com/community/En...hEncryptedSwap

    Some details are different. For example, encrypted swap is not enabled by default anymore after installing Ubuntu. The steps I took are the following, please consult the link above for details on each step.

    NOTE: MY SWAP PARITION WAS /dev/nvme0n1p7 CHECK THE OUTPUT OF THE FIRST COMMAND FOR YOUR LOCATION!
    Code:
    swapon –summary # Check and record your swap partition
    sudo swapoff -a
    sudo cryptsetup luksFormat --cipher aes-xts-plain64 --verify-passphrase --key-size 256 /dev/nvme0n1p7
    sudo cryptsetup luksOpen /dev/nvme0n1p7 cryptswap1
    sudo mkswap /dev/mapper/cryptswap1
    Now edit /etc/fstab:
    Code:
    sudo nano -w /etc/fstab
    and replace the original line with information on the swap parition with:
    Code:
    /dev/mapper/cryptswap1 none swap sw 0 0
    Save the file and continue with:
    Code:
    sudo swapon -a
    Then edit /etc/crypttab and add the following line:
    Code:
    cryptswap1    /dev/nvme0n1p7    none    luks
    Also edit /etc/initramfs-tools/conf.d/resume , and replace the existing line with:
    Code:
    RESUME=/dev/mapper/cryptswap1
    Finally, edit /etc/default/grub and add:
    Code:
    resume=/dev/mapper/cryptswap1
    to the GRUB_CMDLINE_LINUX_DEFAULT options.

    Now run:
    Code:
    
    sudo update-initramfs -u -k all
    sudo update-grub
    to update grub.


    NOW REBOOT!

    When booting, the screen will ask you for your passphrase. If everything went well, the login-prompt will appear, and the encrypted swap is mounted (check with: swapon –summary).



    Step 3: Test hibernate
    You can now test if hibernate works. Issue:
    Code:
    sudo pm-hibernate
    and your system should go to sleep.


    If your system wakes up properly, resuming works!



    Step 4: Enabling the option in the menu
    Now that hibernate works, let’s integrate the functionality in the system, so you can access is from the menu.

    Edit or create: /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla with the following contents:
    Code:
    [Re-enable hibernate by default in upower]
    Identity=unix-user:*
    Action=org.freedesktop.upower.hibernate
    ResultActive=yes
    
    [Re-enable hibernate by default in logind]
    Identity=unix-user:*
    Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
    ResultActive=yes
    Depending on your window manager, the options are readily available or not. Rebooting is the easy option.



    Step 5: Waking up problems
    On some systems, resuming does not work properly. On my ThinkPad E580, I initially had 3 problems: the LAN adapter did not work, the Bluetooth connection at some point simply died, and I sometimes had a black screen after resume.

    These are 3 different problems.

    Problem 1:
    For the LAN adapter, unloading the module prior to hibernate and reloading on resume was sufficient. To achieve this, I followed this guide:
    https://ubuntuforums.org/showthread.php?t=2314905

    My LAN module is the r8169, so I created a file /etc/suspend-modules.conf with:
    Code:
      
    r8169
    Then create a file /lib/systemd/system-sleep/suspend-modules with content:
    Code:
      
    #!/bin/bash
    
    case $1 in
        pre)
            for mod in $(</etc/suspend-modules.conf); do
                modprobe -r $mod
            done
        ;;
        post)
            for mod in $(</etc/suspend-modules.conf); do
                modprobe $mod
            done
        ;;
    esac


    and make it executable:
    Code:
    sudo chmod a+x /lib/systemd/system-sleep/suspend-modules

    Problem 2:
    The other issue was a result from xHCI dying at some point, also resulting in disabling all USB devices. My /var/log/syslog showed these messages:


    Code:
    May 17 19:11:51 my kernel: [23775.839044] xhci_hcd 0000:00:14.0: xHC is not running.
    May 17 19:11:51 my kernel: [23775.856855] xhci_hcd 0000:00:14.0: xHCI host controller not responding, assume dead
    May 17 19:11:51 my kernel: [23775.856877] xhci_hcd 0000:00:14.0: HC died; cleaning up
    I figured out that I needed these options to my GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub (see also this bugreport: https://bugs.launchpad.net/ubuntu/+s...x/+bug/1413440 ):
    Code:
    pci=nomsi iommu=soft
    and running
    Code:
    sudo update-grub
    This solved the problem for me.


    Problem 3:
    Only when you are running the XFCE desktop (like with Xubuntu):
    Sometimes, XFCE returns a black screen after logging in, mainly after resuming from suspend (see bug: https://bugs.launchpad.net/ubuntu/+s...s/+bug/1431149 ).

    The following command returns the XFCE desktop:
    Code:
    xfsettingsd --replace
    which I added as a keyboard shortcut, so I could easily restore my desktop when needed.


    Epilogue
    Putting your computer to hibernate requires some effort, but is fairly straightforward. Waking-up problems are much harder to debug, and may have different sources/solutions.

    Good luck!

    edit 1: added update-grub command for updating GRUB
    edit 2: added XFCE resume bug fix
    Last edited by s-breedveld; May 23rd, 2018 at 01:56 PM.

  2. #2
    Join Date
    Nov 2009
    Beans
    7

    Re: HOWTO hibernate in 18.04

    This guide is really useful, especially all the commands, thinking process, debug process, which of the logs you used to investigate problems, etc. The most annoying part of linux stuff is the random seemingly unrelated things that fail (eg. your LAN or bluetooth dying, intermittently). So, thanks for the thorough instructions and investigation notes. I will be trying this out next weekend...

  3. #3
    Join Date
    Nov 2019
    Beans
    1

    Re: HOWTO hibernate in 18.04

    I followed all the above mentioned steps but still my screen just flashes when I do sudo pm-hibernate.

  4. #4
    Join Date
    May 2010
    Beans
    2

    Re: HOWTO hibernate in 18.04

    This works, thanks. (HP 840 G3)

    Is it possible to integrate hibernate into the Ubuntu options? I would like to make my laptop hibernate on time-out, instead of just standby.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •