Archives For hibernate

Computer hibernate does not work in your Ubuntu? Here’s step by step complete guide shows how to enable this feature.

Similar to suspend, hibernate can be used to save your system work. It moves the content from RAM memory into swap area in hard disk, then shutdown your machine completely. Next time you boot the computer, it restores the system status exactly as it was.

NOTE: This tutorial is tested and works in Ubuntu on default GNOME desktop. For other desktop environments, you need to replace gedit in following commands with your favorite text editor, or use the universal nano command line editor.

Check if hibernate works:

Hibernate does not work in my laptop since Ubuntu 20.04 (maybe, can’t remember it), though it works in Debian 11 bullseye.

To verify if the functions works, open terminal (Ctrl+Alt+T) and run command:

systemctl hibernate

Save you work before running the command!! Then type user password when it asks.

The command will turn off your computer/laptop. Next boot the machine again, and see if it restore your system status after login.

Enable Hibernate on Swap Partition:

So it does not work and just log into blank desktop? Try enable this feature via following steps.

Check Swap Area:

The swap area is used when the memory is getting full. It can also be used to save your system status via hibernate.

Open terminal (Ctrl+Alt+T) and run command tell the swap area:

swapon --show

If it outputs “/dev/sdax partition …” continue this step. Or if it says no swap or a file, go next step: ‘Enable Hibernate on Swap File

Find swap area UUID

In my case the swap is a partition: “/dev/sda3”. Now find the UUID (universally unique identifier) for the area via command:

blkid

In case it does not show the id for swap partition. You can alternatively check in “/etc/fstab” file. To do so, run command:

cat /etc/fstab |grep swap

Copy the UUID for /dev/sda3 in my case. It will be used in next step.

Resume from swap via Kernel parameter

By adding a Kernel parameter into boot menu entry enables the hibernate in my case in both HP and ASUS laptops.

You can do this either via “Grub Customizer -> General Settings” or by editing the Grub boot-loader configuration file.

Run command in terminal to open the config file:

sudo gedit /etc/default/grub

When it opens, add resume=UUID=xxxx (replace xxxx with the id you copied in previous step) as value of “GRUB_CMDLINE_LINUX_DEFAULT”.

Save the file and update the Grub via command:

sudo update-grub

Finally reboot your computer, open a few app windows, and run systemctl hibernate command to test if it works now!

Enable Hibernate on Swap File:

This step is only for those who don’t have a swap partition, since a swap file can also be used for hibernation.

Create Swap File:

To create a file for swap if you don’t have it, run following commands one by one:

a.) Pre-allocate a disk place for a file via command:

sudo fallocate -l 4G /swapfile

Replace 4G to your desired size. As large as RAM is recommended for swap.

b.) Change the file permission to only read & write for root:

sudo chmod 600 /swapfile

c.) Set the file as swap area:

sudo mkswap /swapfile

d.) Finally enable it by running command:

sudo swapon /swapfile

e.) And write it into ‘/etc/fstab’, so Ubuntu will mount it automatically on startup.

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Find the UUID & Offset:

Since the file is created on Ubuntu file-system. It can be located via root UUID as well as physical offset.

To see your Ubuntu partition, run command and find the one mounted on ‘/‘:

df -h

Then find its UUID via command:

blkid

In my case, it’s ‘/dev/sda5’ and UUID is marked in white background.

To find the physical offset for /swapfile, run command:

sudo filefrag -v /swapfile

Copy the start number under physical_offset. It’s 927744 in my case.

Resume on Swap file via Kernel parameter:

Finally edit the Grub configuration file (or use Grub-Customizer) via command:

sudo gedit /etc/default/grub

Then add resume=UUID=xxx resume_offset=xxx as value of “GRUB_CMDLINE_LINUX_DEFAULT”. Also replace ‘xxx’ with the id and/or offset value.

And update grub to apply change via command:

sudo update-grub

Regenerate initramfs:

Hibernate now works in my case after reboot. If not working for you, try regenerating initramfs via a new rule.

Firstly, open terminal (Ctrl+Alt+T) and run command to create a config file:

sudo gedit /etc/initramfs-tools/conf.d/resume

Then paste the line “RESUME=UUID=xxx resume_offset=xxx” (replace xxx with correct id) and save it.

After saving the file, regenerate initramfs via command:

sudo update-initramfs -c -k all

Finally reboot and test hibernate function again.

Enable Hibernate option in Power-Off Menu:

After enabled the function, you can now add a menu option into the system tray shutdown menu.

1.) Firstly, open terminal (Ctrl+Alt+T) and run command to create & edit a config file:

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

When the file opens, paste following lines and save it.

[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

For non-Gnome desktop, e.g., XUbuntu and Ubuntu MATE, there’s now a hibernate option after log-out and back in.

2.) For default GNOME desktop, go to the link button below and install the extension for the menu option:

For those first time installing Gnome extension, you need to run command to install “chrome-gnome-shell” package first:

sudo apt install chrome-gnome-shell

And click the “click here to install browser extension” link in the extension page and refresh the page if you don’t see the toggle icon.

Moreover:

If everything goes well after this tutorial, you can get more, including hibernate when lid is closed, and automatic hibernate on system idle.

This quick tutorial is going to show you how to enable hibernate option in the top-right corner power menu in Ubuntu 18.04. So you’ll get a similar menu as the picture shows:

Test if hibernate works

First of first, you have to make sure hibernate works in command line.

1. Open terminal via Ctrl+Alt+T or by searching for ‘terminal’ from app launcher. When it opens, run command:

sudo systemctl hibernate

Please SAVE all of your work before hitting enter, in case something goes wrong and your open applications and documents cannot be recovered.

2. After you computer turns off, switch it back on. Did your open applications re-open?

If hibernate doesn’t work, take a look at this question on askubuntu.

UPDATE: Hibernate does not work out-of-the-box since Ubuntu 20.04, at least in my case, you have to enable it by adding Kernel parameter in boot menu. See this tutorial for Ubuntu 20.04 & higher.

Enable Hibernate in Menus

If hibernate works in command line, continue enable it in the menus via following steps.

1. Open terminal (Ctrl+Alt+T) and run command to create a configuration file:

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

When the file opens, paste following content and save it.

[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

2. Restart your computer and click the link to install the gnome extension: Hibernate Status Button.

For those who never installed a gnome extension, see this how to tutorial for details.

How to Enable Hibernate in Ubuntu 17.10

Last updated: October 15, 2017

The hibernate functionality is disabled in Ubuntu by default because it might not work on some machines. For those who want to re-enable the feature, here’s how to do it in Ubuntu 17.10.

1. Test if hibernate works on your machine.

Open terminal either via Ctrl+Alt+T keyboard shortcut or by searching ‘terminal’ from application launcher. When it opens, run command:

sudo apt install pm-utils && sudo pm-hibernate

After you computer turns off, switch it back on. Did your open applications re-open? If hibernate doesn’t work, check if your swap partition is at least as large as your available RAM.

2. To re-enable hibernate, run the command to edit the configuration file:

sudo nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

When the file opens in the terminal window, scroll down to find out the section started as:

“[Disable hibernate by default in upower]” and “[Disable hibernate by default in logind]”

Change the both values of ResultActive to yes.

Save the changes by pressing Ctrl+X and then typing y and finally hitting Enter.

To make Hibernate working for multiple users, you can add following lines into the configuration file:

[Re-enable hibernate for multiple users by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate-multiple-sessions
ResultActive=yes

And for some machines you may replace the command in step 2, in case it doesn’t work, with following one:

sudo nano /etc/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

Press power button to hibernate:

After enabled the hibernate functionality, you can launch Settings from application tool. In the ‘Power’ settings, you are able to set ‘Hibernate’ when the power button is pressed.

Hibernate when laptop lid is closed:

You can also make your laptop automatically hibernate when the lid is closed.

To do so, open terminal (Ctrl+Alt+T) and run command to edit the logind.conf file:

xhost +local: && sudo gedit /etc/systemd/logind.conf

When it opens, change the line #HandleLidSwitch=suspend into HandleLidSwitch=hibernate.

Tip, you can replace the value of HandleLidSwitch to poweroff, ignore for other lid closed actions.

To apply all the changes, restart your computer.

Enable Hibernate Option in Ubuntu 14.10 Unity

Last updated: October 24, 2014

Ubuntu 14.10 Hibernate

The Hibernate option is available in Beta and Alpha releases of Ubuntu 14.10, but the final release removed this option in the Unity desktop.

This quick guide is going to show you how to re-enable this feature so that you can hibernate your machine from the shutdown menu (top-right gear button).

hibernate ubuntu 14.10

1. Before getting started, you may run command below in terminal (Ctrl+Alt+T) to test if hibernate works in your case:

sudo pm-hibernate

After you computer turns off, switch it back on. Did your open applications re-open? If hibernate doesn’t work, check if your swap partition is at least as large as your available RAM.

2. To re-enable hibernate, run command below to edit the configuration file:

sudo nano /var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

When the file opens in the terminal window, scroll down to find out the section started as:

“[Disable hibernate by default in upower]” and “[Disable hibernate by default in logind]”

Change the value of ResultActive to yes in both.

enable-hibernate-conf

3. To save the changes, press Ctrl+X and type y and finally hit Enter.

When everything’s done, restart your computer.

Tips:

1. If previous steps do not work for you, replace the command in step 2 with:

sudo nano /etc/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla

2. Thanks to Cruz, you can add below lines into the configuration file to make Hibernate work for multiple users:

[Re-enable hibernate for multiple users by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate-multiple-sessions
ResultActive=yes

3. If you want to hibernate your laptop when lid is closed, run command to edit the configuration file:

sudo nano /etc/systemd/logind.conf

Add HandleLidSwitch=hibernate as a new line into the end and save the file. It will work at next boot.

How to Enable Hibernation in Ubuntu 14.04

Last updated: May 27, 2016

ubuntu hibernate

This simple and brief tutorial is going to show you how to enable the hibernate feature in Ubuntu 14.04 Trusty Tahr.

Hibernate is disabled by default in Ubuntu, when the computer hibernates, all of your applications and documents are stored and the computer completely switches off so it does not use any power, but the applications and documents will still be open when you switch on the computer again.

hibernate ubuntu 14.04

Test if hibernate works in your case:

Before getting started, press Ctrl+ALt+T on your keyboard to open the terminal. When it opens, run:

sudo pm-hibernate

After you computer turns off, switch it back on. Did your open applications re-open? If hibernate doesn’t work, check if your swap partition is at least as large as your available RAM.

Enable Hibernate in System Tray Menu:

The indicator-session was updated to use logind instead of upower. Hibernate is disabled by default in both upower and logind.

To re-enable hibernate, run the commands below one by one to edit the config file:

sudo -i

cd /var/lib/polkit-1/localauthority/50-local.d/

gedit com.ubuntu.enable-hibernate.pkla

Tips: if the config file does not work for you, try another one by changing /var/lib to /etc in the code.

Copy and paste below lines into the file and save it.

[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
ResultActive=yes

enable hibernate ubuntu 14.04

Restart your computer and done.

Hibernate your laptop when lid is closed:

1.Edit “/etc/systemd/logind.conf” via command:

sudo gedit /etc/systemd/logind.conf

2. Change the line #HandleLidSwitch=suspend to HandleLidSwitch=hibernate and save the file.

3. Run command below or just restart your computer to apply changes:

sudo restart systemd-logind

That’s it. Enjoy!