How to enable hibernation with swap partition on Linux Mint 19

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
goebbe
Level 1
Level 1
Posts: 16
Joined: Sun Jun 02, 2013 8:29 am

How to enable hibernation with swap partition on Linux Mint 19

Post by goebbe »

Hello,
this howto should help you to set up working hibernation with a swap partition on a fresh install of LM19.
For a guide on howto use a swap file, see viewtopic.php?f=42&t=284100.

Short background:
a. Hibernation basically writes the content of your memory into the swap space of your computer - when you start your computer, after hibernation, it should load/ read the content of the swap partition in order to resume.
b. There are two different methods to set up a swap-space on your disk. First: The use of a separate swap partition (set up when formatting your disk during install). Second, the use of a swap file (this is the new default).
c. Hibernation is known to cause problems on some computers. Be sure that you know howto boot and restore your system, before you enable hibernation. It is probably a good idea to have a working usb-stick with Linux Mint 19 around. :D

There may be different reasons, why some users use a separate swap partition. One reason could be that you want to use btrfs as a file system (and swap-files on btrfs is a new/experimental feature, that requires a linux kernel 5.0 or newer).
This howto should guide you, when setting up hibernation and using a separate swap partition.

1. Step - Make sure, that the kernel will look at the right place when booting (after hibernation):
In order to achieve this, one has to add the option "resume=UUID= " to the file /etc/default/grub

1a. Copy your UUID of the swap partition from fstab:

Code: Select all

cat /etc/fstab
1b. Add the boot option to grub (your boot loader):

Code: Select all

xed admin:///etc/default/grub
Add the following boot option "resume=UUID=putYourSwapUUIDhere" to GRUB_CNMDLINE_LINUX_DEFAULT.
Example:

Code: Select all

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=putYourSwapUUIDhere"
Note that you have to copy your UUID from fstab to replace putYourSwapUUIDhere.

Save the grub file and update grub:

Code: Select all

sudo update-grub
2. Now check if hibernation works from the command line:
Open terminal and run command:

Code: Select all

systemctl hibernate
If hibernate works from the command line - but is not visible in the shutdown menu,
enable it in the menus via the following steps.

3. Enable hibernation in the shutdown menu
Open terminal and run the following commands to create and edit the configuration file:

Code: Select all

sudo touch /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
xed admin:///etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
When the file opens, copy and paste the following content into the file and save it:

Code: Select all

[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
Hibernation should show up in the menu and the "Power Management" settings of LM19.
Comments are welcome.
Last edited by karlchen on Sat Apr 13, 2019 6:28 am, edited 8 times in total.
Reason: title: corrected "partion" to read "partition
gm10

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by gm10 »

goebbe wrote: Fri Jul 13, 2018 9:21 am Comments are welcome.
You should really use xed admin://</path/file>, there's no reason to run the editor itself with elevated privileges. Also sudo with GUI programs is just generally bad practice and can lead to issues in some cases.

Otherwise looking good, although hibernation had to be disabled in Mint 19 because it is really problematic with the Ubuntu 18.04 base, so good luck to those trying it.
Last edited by gm10 on Sun Aug 05, 2018 11:17 am, edited 1 time in total.
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by catweazel »

goebbe wrote: Fri Jul 13, 2018 9:21 am c. Hibernation is known to cause problems on some computers.
The only thing I would suggest is that you add a small section on how to test if hibernate is supported on a particular machine. See, for example: http://ubuntuhandbook.org/index.php/201 ... ntu-17-10/ as there's no point if hibernation isn't supported.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
goebbe
Level 1
Level 1
Posts: 16
Joined: Sun Jun 02, 2013 8:29 am

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by goebbe »

The only thing I would suggest is that you add a small section on how to test if hibernate is supported on a particular machine. See, for example: http://ubuntuhandbook.org/index.php/201 ... ntu-17-10/ as there's no point if hibernation isn't supported.
Thank you!

Is there a good way to check if hibernation is supported?
The only suggestion is to search in the internet for bug reports.
However this is likely to give false results, since hibernation depends on the version of the kernel, the version of the driver, the configuration, the implementation details.

In the end it always comes down to trial an error - which is basically what is suggested in your link: "sudo pm-hibernate" <- the equivalent to "sudo systemctl hibernate" in step 2.
However if one does not implement step 1 - hibernation will always fail. :-)
Last edited by goebbe on Fri Jul 13, 2018 10:56 am, edited 1 time in total.
goebbe
Level 1
Level 1
Posts: 16
Joined: Sun Jun 02, 2013 8:29 am

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by goebbe »

gm10 wrote: Fri Jul 13, 2018 9:51 am You should really use xed admin://</path/file>, there's no reason to run the editor itself with elevated privileges. Also sudo with GUI programs is just generally bad practice and can lead to issues in some cases.
Thank you! I edited my little howto, as suggested. :-)
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by catweazel »

goebbe wrote: Fri Jul 13, 2018 10:53 am Is there a good way to check if hibernation is supported?
The only suggestion is to search in the internet for bug reports.
It's in the link I gave you. Step 1...
In the end it always comes down to trial an error
No, it does not.
which is basically what is suggested in your link: "sudo pm-hibernate"
An explicit step is not trial and error, it's a test or check. Nevertheless, if it's the same step as you say then leave it. No worries.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
gm10

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by gm10 »

catweazel wrote: Fri Jul 13, 2018 10:58 amAn explicit step is not trial and error, it's a test or check.
That really is exactly the same thing. ;)

OP, one more: sudo systemctl hibernate -- there's no reason to sudo that one, either. Don't be so generous with your sudo. Elevated privileges should be given sparingly. A program that runs elevated basically owns your system. Never forget. ;)
goebbe
Level 1
Level 1
Posts: 16
Joined: Sun Jun 02, 2013 8:29 am

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by goebbe »

OP, one more: sudo systemctl hibernate -- there's no reason to sudo that one, either. Don't be so generous with your sudo. Elevated privileges should be given sparingly. A program that runs elevated basically owns your system. Never forget. ;)
Good catch! Thank you. I changed the howto.
sour_diesel

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by sour_diesel »

I just wanted to say thank you for this post. Worked perfectly for me! So glad I decided to visit the Mint Forums today!!

I recently migrated from Ubuntu to Mint and need hibernation .... can't live without it. The last part of your post for enabling the hibernation option in the quit menu did not work me.


However this is how I accomplished that:

Use this command in a terminal to create a text file:

Code: Select all

 sudo nano /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkl 
Copy and paste this into your newly created file, save, and exit.

Code: Select all

[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
Restart your computer and then click the Menu / Quit / Hibernate :)
goebbe
Level 1
Level 1
Posts: 16
Joined: Sun Jun 02, 2013 8:29 am

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by goebbe »

sour_diesel wrote: Mon Jul 16, 2018 11:41 am Use this command in a terminal to create a text file:

Code: Select all

 sudo nano /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkl 
Thank you!
xed admin:// can only edit an existing file! So when using xed admin:/// one has to add an additional step, in order to create the file.
I edited the howto. :-) Of course, one can also use the nano editor, as suggested.
Last edited by goebbe on Mon Jul 16, 2018 2:01 pm, edited 1 time in total.
gm10

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by gm10 »

goebbe wrote: Mon Jul 16, 2018 12:44 pm
sour_diesel wrote: Mon Jul 16, 2018 11:41 am Use this command in a terminal to create a text file:

Code: Select all

 sudo nano /var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkl 
Thank you!
xed admin:// can only edit an existing file! So when using xed admin:/// one has to add an additional step, in order to create the file.
I edited the howto. :-) Or one can use the nano editor, as suggested.
You can even do it without an editor all in one go:

Code: Select all

sudo bash -c "cat >> /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla <<EOB
[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
EOB"
Don't you love Linux?! :lol:
sour_diesel

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by sour_diesel »

Indeed I do. Love Linux sooo much!
dwisatriow

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by dwisatriow »

Hi, i've try

Code: Select all

systemctl hibernate
but it says "Failed to hibernate system via logind: Sleep verb not supported"

and when i try

Code: Select all

sudo pm-hibernate
nothing happen.

Then i try run

Code: Select all

sudo systemctl hibernate
the system off but when i turned it on it doesn't hibernate and there is a javaembeddedframe icon on panel which i can't close.

Can anyone help me?
goebbe
Level 1
Level 1
Posts: 16
Joined: Sun Jun 02, 2013 8:29 am

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by goebbe »

dwisatriow wrote: Fri Jul 27, 2018 9:45 am Hi, i've try

Code: Select all

systemctl hibernate
but it says "Failed to hibernate system via logind: Sleep verb not supported"
There are several known possibilities that could lead to this error message:
1. hibernation might not be supported by your hardware (computer) - did it work before installing Mint 19?
2. hibernation might not be supported by your Linux kernel - use the standard kernel, if possible.
3. hibernation is known to cause problems in combination with "secure boot" - disable secure boot if possible.
Take care: If you need secure boot e.g. in a dual boot setup, for booting Windows, this is not an option.
4. make sure that your swap partition is bigger than your memory (RAM).

Please report back, if you find the source of your problem.
dwisatriow

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by dwisatriow »

goebbe wrote: Tue Jul 31, 2018 9:37 am There are several known possibilities that could lead to this error message:
1. hibernation might not be supported by your hardware (computer) - did it work before installing Mint 19?
2. hibernation might not be supported by your Linux kernel - use the standard kernel, if possible.
3. hibernation is known to cause problems in combination with "secure boot" - disable secure boot if possible.
Take care: If you need secure boot e.g. in a dual boot setup, for booting Windows, this is not an option.
4. make sure that your swap partition is bigger than your memory (RAM).

Please report back, if you find the source of your problem.
Thanks for the reply, after considering the risk about enabling hibernation on dual boot system, i think i'm not going to enable it.
davido_
Level 1
Level 1
Posts: 15
Joined: Sat Oct 27, 2012 7:41 am
Location: Europe, Germany

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by davido_ »

gm10 wrote: Fri Jul 13, 2018 9:51 am Otherwise looking good (if your cat /etc/initramfs-tools/conf.d/resume already has the correct UUID then you can skip most of your steps but no matter), although hibernation had to be disabled in Mint 19 because it is really problematic with the Ubuntu 18.04 base, so good luck to those trying it.
You're giving a null-info. Tell us, what are the "most" steps to skip?

However, I could not skip any step. After finally adding swap UUID to /etc/default/grub everything works.
gm10

Re: Howto enable hibernation with swap partion on Linux Mint 19

Post by gm10 »

davido_ wrote: Sun Aug 05, 2018 10:39 am You're giving a null-info. Tell us, what are the "most" steps to skip?
Valid point. I simply removed that part from my post. Just follow the OP's good tutorial, no reason to potentially cause confusion with a side-discussion.
andrekappert

Re: How to enable hibernation with swap partion on Linux Mint 19

Post by andrekappert »

This will create confusion. The original method speaks of the file “/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla”. The alternative method speaks of the file “/var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkl”. Different directory and different extension!

What worked for me:
if you created the file “/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla”, then delete it.
Create the file “/var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla” with the new text from sour_diesel Mon Jul 16, 2018 11:41 am.

I have taken the original extension. The extension just describes what sort file it is. I believe that just any file in this sort of directory is parsed, whatever the name is. Why the directory var/lib works and etc not, only an expert will know. Using points in filenames is by the way a weird/dangerous habit. Is the extension part after the first or last point. I thought it would be the last, a filename manipulation function of free pascal thinks the first. In the past, this created a strange error for me.
User avatar
BG405
Level 8
Level 8
Posts: 2499
Joined: Fri Mar 11, 2016 3:09 pm
Location: England

Re: How to enable hibernation with swap partion on Linux Mint 19

Post by BG405 »

andrekappert wrote: Tue Aug 07, 2018 11:47 am This will create confusion. The original method speaks of the file “/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla”. The alternative method speaks of the file “/var/lib/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkl”. Different directory and different extension!
Well spotted!

It always pays to double-check commands in case anything has been missed off. Seen this in instructions on other websites, one just missing that final / on the path ...
Dell Inspiron 1525 - LM17.3 CE 64-------------------Lenovo T440 - Manjaro KDE with Mint VMs
Toshiba NB250 - Manjaro KDE------------------------Acer Aspire One D255E - LM21.3 Xfce
Acer Aspire E11 ES1-111M - LM18.2 KDE 64 ----Two ROMS don't make a WRITE
gm10

Re: How to enable hibernation with swap partion on Linux Mint 19

Post by gm10 »

Just do what's written in the OP. No confusion, no problems. ;)
Post Reply

Return to “Tutorials”