[GUIDE] How to hibernate to a swap file in Linux Mint 19.x

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
BrunoMiranda
Level 4
Level 4
Posts: 359
Joined: Thu Jun 24, 2010 2:22 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by BrunoMiranda »

nooblinx wrote: Tue Jul 06, 2021 11:11 am hibernate shutdown successfully but after reboot do not restore session. instead, display login.
Do you mean login asking for your username and password, and starting a new session losing all your data from the hibernated session (a fresh reboot in practice); or just asking for your password after resuming successfully and get back to your previous session?

I have this on an old 32bits Acer laptop running LMDE2, but I just use it offline to watch videos and never fixed the problem that started to happen after a BIOS update.
I don't know how things are nowadays regarding BIOS updates and this new Acer machine I am currently on, but after BIOS updates botching hibernation on two separate Acer laptops, I won't take the risk in this new one and just let it be...

Can I be confusing the latter as a configuration setting instead of a real problem?

Can I suggest installing uswsusp and check if hibernation works well with s2disk from a terminal?
uswsusp has, in its configuration, two methods to switch off the computer: Platform and Shutdown. One of them might work better for you.
You can access uswsusp's configuration by running:

Code: Select all

sudo dpkg-reconfigure uswsusp
Just keep on pressing Enter to accept the given values until you reach the screen to change the shutdown method and don't forget to reboot your computer afterwords to check how your changes work.
Bye for now,
Bruno


(Always backup before you screw up :)
User avatar
nooblinx
Level 2
Level 2
Posts: 67
Joined: Sat Jul 03, 2021 4:13 am

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by nooblinx »

BrunoMiranda wrote: Tue Jul 06, 2021 11:51 am
nooblinx wrote: Tue Jul 06, 2021 11:11 am hibernate shutdown successfully but after reboot do not restore session. instead, display login.
Do you mean login asking for your username and password, and starting a new session losing all your data from the hibernated session (a fresh reboot in practice); or just asking for your password after resuming successfully and get back to your previous session?

I have this on an old 32bits Acer laptop running LMDE2, but I just use it offline to watch videos and never fixed the problem that started to happen after a BIOS update.
I don't know how things are nowadays regarding BIOS updates and this new Acer machine I am currently on, but after BIOS updates botching hibernation on two separate Acer laptops, I won't take the risk in this new one and just let it be...

Can I be confusing the latter as a configuration setting instead of a real problem?

Can I suggest installing uswsusp and check if hibernation works well with s2disk from a terminal?
uswsusp has, in its configuration, two methods to switch off the computer: Platform and Shutdown. One of them might work better for you.
You can access uswsusp's configuration by running:

Code: Select all

sudo dpkg-reconfigure uswsusp
Just keep on pressing Enter to accept the given values until you reach the screen to change the shutdown method and don't forget to reboot your computer afterwords to check how your changes work.
yes, session not restore. uswsusp methods not working too but I saw that uswsusp reconfigured kernel 77 only and I use kernel 58. so I suspected for resume options too... I used grub customizer and find that resume options only applied to kernel 77 not the one main I used (58) when I updated grub!! so that was the problem and I added resume options manually and hibernate works great now :D I also siwtched to new kernel and that works great too :)
still noob in linux :~$ echo "my english is not good"
BrunoMiranda
Level 4
Level 4
Posts: 359
Joined: Thu Jun 24, 2010 2:22 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by BrunoMiranda »

You had something messing up with your GRUB, regarding all your available kernels.
I personally see this if I have 2 OSs, and only one of them can effectively change GRUB properly. The "other" OS can change its own GRUB stuff but rebooting ignores them, I have to boot the "main" OS and update GRUB so it can see the "other" OS's GRUB changes and updates them. I believe I have GRUB installed on the boot sector of the drive and not on a partition but it still behaves like this. I can live with this and know my workarounds, so it's a meh.

Regarding GRUB-customizer, most people recommend against it and personally so do I.
On one side it can fix things, on the other hand it can do it in an unorthodox way and complicate things very much.
It can insert files out of the traditional GRUB paths and even after purging GRUB-customizer it left its chaos around. I would do stuff right but they would not work because there were some files scattered around that made "official" things being ignored and I just kept on thinking "But is this Windows?!?"
I had a lot of trouble digging around until I found those configurations left behind and deleted them, and things finally worked fine again. So beware if in the future you have similar GRUB weird behaviors, it might be GRUB-customizer leftovers creating havoc.

But for now you seem to be having your problem fixed, so that's good! Cheers.
Bye for now,
Bruno


(Always backup before you screw up :)
kaefert
Level 3
Level 3
Posts: 110
Joined: Sun Jan 08, 2012 12:08 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by kaefert »

I've been trying to follow your guide to enable hibernation.

Strangely my system tells me there's not enough space:

Code: Select all

# systemctl hibernate
Failed to hibernate system via logind: Not enough swap space for hibernation
But clearly there is:

Code: Select all

$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7,4Gi       1,3Gi       4,1Gi       170Mi       2,0Gi       5,7Gi
Swap:         8,0Gi          0B       8,0Gi

Code: Select all

$ swapon
NAME        TYPE SIZE USED PRIO
/.swap/swap file   8G   0B   -2

Code: Select all

# grep swap /etc/fstab
/dev/mapper/nvme0n1p3_crypt /.swap          btrfs   defaults,noatime,nodiratime,space_cache,ssd,nodatacow,subvol=@swap     0       0
/.swap/swap                                 none            swap    sw              0       0

Code: Select all

# cat /etc/default/grub.d/resume.conf 
GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT resume=UUID=3ed12f1a-faeb-47dd-b840-09a54c410765 resume_offset=4009476"
I'm using a BTRFS system partiton, though as far as I understood it starting with linux 5.0.x swapfiles on BTRFS are supported as well.
I successfully followed this guide to get this to work on my Manjaro system.
BrunoMiranda
Level 4
Level 4
Posts: 359
Joined: Thu Jun 24, 2010 2:22 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by BrunoMiranda »

Can you please post the output of

Code: Select all

blkid
so we can be sure your configuration matches that swap file's UUID.

But yes, at first sight it should have enough room to properly hibernate.

I believe above in this topic I have instructions for uswsusp and s2disk. It compresses RAM and its configuration allows to check for some swap and hibernation configurations, if you wish and decide to give it a try.


Have you tried rebooting and hibernating soon after doing it? Without opening any applications there won't be much RAM consumed and it should, for sure, fit inside all that swap file. Let us know.
Bye for now,
Bruno


(Always backup before you screw up :)
kaefert
Level 3
Level 3
Posts: 110
Joined: Sun Jan 08, 2012 12:08 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by kaefert »

Hey there @BrunoMiranda !
Thanks for the reply! :)

Here you go:

Code: Select all

# blkid
/dev/mapper/nvme0n1p3_crypt: UUID="3ed12f1a-faeb-47dd-b840-09a54c410765" UUID_SUB="774890ce-b112-46ea-9200-7958deb0dbdd" TYPE="btrfs"
/dev/nvme0n1p1: UUID="A93B-7DDC" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="a57f0fa5-6af7-4899-852a-9e6e2242a606"
/dev/nvme0n1p2: UUID="6c30af54-947c-44f5-923d-85e619ef8626" TYPE="ext4" PARTUUID="20580adf-62a6-46b9-8cc3-b0301a5cf0ce"
/dev/nvme0n1p3: UUID="a7645d48-cbaf-4505-a517-1951cba56c00" TYPE="crypto_LUKS" PARTUUID="d01a81f6-ba61-4483-84b5-2941f16360ab"
Personally I prefer this command for checking UUIDs:

Code: Select all

# lsblk --fs
NAME                FSTYPE      LABEL                 UUID                                 FSAVAIL FSUSE% MOUNTPOINT
nvme0n1                                                                                                   
├─nvme0n1p1         vfat                              A93B-7DDC                              51,2M    13% /boot/efi
├─nvme0n1p2         ext4                              6c30af54-947c-44f5-923d-85e619ef8626  313,1M    24% /boot
└─nvme0n1p3         crypto_LUKS                       a7645d48-cbaf-4505-a517-1951cba56c00                
  └─nvme0n1p3_crypt btrfs                             3ed12f1a-faeb-47dd-b840-09a54c410765  451,6G     5% /run/timeshift/backup
I had a brief try with `uswsusp` but probably I'd need to have a better look at what has been written about it:

Code: Select all

# s2disk 
s2disk: Could not stat the resume device file. Reason: No such file or directory
During installation of `uswsusp` I got this discouraging error:

Code: Select all

Setting up uswsusp (1.0+20120915-6.2) ...
You have a strange /dev layout.
I couldn't find a node with devid 0:54
Here I found a utility that tried hibernating my system:

Code: Select all

apt install pm-utils && pm-hibernate
That turned off my computer, but booting again gave me a fresh session. `journalctl --since=-30m` shows the error:

Code: Select all

PM: Swap header not found!
Interestingly, 3 lines before that it writes:

Code: Select all

PM: Image saving done
BrunoMiranda
Level 4
Level 4
Posts: 359
Joined: Thu Jun 24, 2010 2:22 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by BrunoMiranda »

Hi! you're welcome.


The UUIDs do match, but I think I've found a catch:

/dev/nvme0n1p3: UUID="a7645d48-cbaf-4505-a517-1951cba56c00" TYPE="crypto_LUKS"

I'm assuming you're using Mint 19. Are you using home folder encryption? There's an issue with it relating hibernation:
https://www.linuxmint.com/rel_tara_cinnamon.php

There's some fixes for it in the above link.
I don't think this applies to Mint 20, at least I haven't seen it on its release notes.


Or if you're not using home folder encryption, can you try setting up a swap file on a non-BTFS partition so you can rule this one out? Also, without encryption.
Bye for now,
Bruno


(Always backup before you screw up :)
kaefert
Level 3
Level 3
Posts: 110
Joined: Sun Jan 08, 2012 12:08 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by kaefert »

Hey there @BrunoMiranda,

sorry for the pause. I've messed up the systems boot-ability by adding an external disk in RAID1 configuration to my BTRFS system partition (on the internal SSD).
Today I managed to make it boot again, but now the swapfile doesn't work at all anymore. I found the reason is, swapfiles on BTRFS-partitons are only supported on single-disk setups, see also: https://bbs.archlinux.org/viewtopic.php?id=246960

So now I guess I'll have to come up with a new swap layout plan. If you're interested in how the story turns out, I can report back once I've decided on the course to take.

(About the question of the Linux Mint Version used: I've started out with 20.1 and upgraded to 20.2 soon after the initial installation)

(And about the encryption question: I'm using LUKS encryption around the BTRFS filesystems and an unencrypted ext4 /boot partition with dropbear-initramfs + cryptroot-unlock to unlock those LUKS partitions. No additional home folder encryption.)
BrunoMiranda
Level 4
Level 4
Posts: 359
Joined: Thu Jun 24, 2010 2:22 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by BrunoMiranda »

Hi,

Don't worry as we all mess up our systems every once in a while and need time to find solutions and fix them. I have a spare OS and treat my everyday one like chewing gum, sometimes I can fix it and some other ones it's just a restart from restore.

I know nothing about encryption as I don't use it but I might start needing it someday, so I'll keep your links for future reference.

I assumed you were using Mint 19 because you had home folder encryption problems and I remembered reading something about it when 19 came out, but it seems this is not the issue.

Sure, keep us posted. I might not be of greater help but someone else might, and add up to the knowledge base that is this very useful forum. If needed you can open your own topic and leave us the link here.

All the best, cheers.
Bye for now,
Bruno


(Always backup before you screw up :)
kaefert
Level 3
Level 3
Posts: 110
Joined: Sun Jan 08, 2012 12:08 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by kaefert »

I now posted my system's story and my deliberations on how to proceed from here over there:
viewtopic.php?f=46&t=353135

Thanks for your help so far!
I'll probably be coming back to the swapfile hibernation topic once I've figured out the disk setup I want to use ;)

UPDATE: So I've settled on a disk setup (for now ;)) and redid the swapfile+hibernation setup. This time it worked on my first try. The thing I believe I did differently this time round was to bypass the memory check because systemd does not support it on btrfs:

Code: Select all

mkdir -p /etc/systemd/system/systemd-logind.service.d/
mkdir -p /etc/systemd/system/systemd-hibernate.service.d/
echo "Environment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1" >> /etc/systemd/system/systemd-logind.service.d/bypass_hibernation_memory_check.conf
echo "Environment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1" >> /etc/systemd/system/systemd-hibernate.service.d/bypass_hibernation_memory_check.conf
User avatar
SMG
Level 25
Level 25
Posts: 31907
Joined: Sun Jul 26, 2020 6:15 pm
Location: USA

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by SMG »

Moderator note: sokolas's question can now be found here Problem hibernating to a swap file in Linux Mint 20.1.
Image
A woman typing on a laptop with LM20.3 Cinnamon.
jero
Level 1
Level 1
Posts: 26
Joined: Mon Sep 27, 2021 7:47 am

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by jero »

Thanks a lot for writing this guide, gm10. I just tried it under Linux Mint 20.3 and it looks to be working perfectly.
billk
Level 1
Level 1
Posts: 8
Joined: Wed Aug 17, 2022 9:44 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by billk »

I've been wanting to do this for several years and I finally got the chance with a new Dell 5490 laptop (for me) and Linux Mint 21. It works great. Thanks so much for the clear directions.
wyse
Level 1
Level 1
Posts: 3
Joined: Tue Jun 02, 2015 5:37 am

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by wyse »

Thanks for this guide.
It worked for me on LM 21 (dot not forget to make swapfile and remove swap partition).
Quitté Windows pour Mint (reste un dual boot pour quelques applis)
jahirju30
Level 1
Level 1
Posts: 28
Joined: Sun Mar 03, 2019 12:19 am

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by jahirju30 »

This worked perfectly on LM 21 Cinnamon! Super easy to follow. Thanks a lot for this guide.
BaDaHe
Level 1
Level 1
Posts: 13
Joined: Mon Aug 24, 2020 4:16 am

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x - and Mint MATE 21

Post by BaDaHe »

Works for me on a Surface Pro 5 that I recently acquired and loaded with Mint MATE 21 today.
Nice work, thanks.
BdH
Australia
21-Sep-22 19:13
wyse
Level 1
Level 1
Posts: 3
Joined: Tue Jun 02, 2015 5:37 am

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by wyse »

Thanks,
works for my laptop with swap file and removing swap partition
Quitté Windows pour Mint (reste un dual boot pour quelques applis)
80_T
Level 1
Level 1
Posts: 2
Joined: Wed Mar 01, 2023 11:28 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by 80_T »

Thank you gm10! This just worked for me to set up hibernation on Linux Mint 21.1.
User avatar
PaulL
Level 6
Level 6
Posts: 1056
Joined: Mon Apr 24, 2023 10:57 am
Location: Connecticut

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by PaulL »

I too want to say thank you for this tutorial. My computer is still using a lot of power on Suspend, so it's great to be able to Hibernate instead.

I found this tutorial informative, and the links to background material were very interesting. I had no idea of what the technical challenges were in making hibernate work, so this has been a great learning experience. My mind doesn't absorb material as well as it did back in the MS-DOS and early Windows days, but I enjoy having it stretched.

I wanted to point out that the Ubuntu link recommends a 15 G swap file for hibernating with my 12 G of RAM, which seems a bit excessive, but I followed their advice anyway, because I have plenty of disk space to spare and don't want to be messing with things. But it might be fun, when I have time, to fiddle with the size of /swapfile and see just how small I can get it and still hibernate.

Again, many, many thanks for this tutorial.
choco
Level 1
Level 1
Posts: 1
Joined: Wed Jul 26, 2023 8:48 pm

Re: [GUIDE] How to hibernate to a swap file in Linux Mint 19.x

Post by choco »

Still worked no problem in 21.2 cinnamon.
Thank you for this guide. It's so quick and easy. Surprising so.
Locked

Return to “Tutorials”