[HowTo] Enable and configure hibernation with BTRFS

Difficulty: ★★★☆☆

Create and activate a Swap Device

  1. Set the root device:
export fs_uuid=$(findmnt / -o UUID -n) && echo ${fs_uuid}
  1. Temporarily mount your btrfs filesystem to a folder, create a subvolume and mount it to the root filesystem.
sudo mount -m -U $fs_uuid /mnt/system-${fs_uuid}
sudo btrfs subvolume create /mnt/system-${fs_uuid}/@swap
sudo umount /mnt/system-${fs_uuid}
sudo mount -m -U ${fs_uuid} -o subvol=@swap,nodatacow /swap
  1. Create a swapfile and set permissions/attributes
sudo touch /swap/swapfile
sudo chattr +C /swap/swapfile
export swp_size=$(echo "$(grep "MemTotal" /proc/meminfo | tr -d "[:blank:],[:alpha:],:") * 1.6 / 1000" | bc ) && echo $swp_size
sudo dd if=/dev/zero of=/swap/swapfile bs=1M count=$swp_size status=progress
sudo chmod 0600 /swap/swapfile
sudo mkswap /swap/swapfile
  1. Add 2 entries and enable the swapfile in /etc/fstab
sudo umount /swap
echo -e "UUID=$fs_uuid\t/swap\tbtrfs\tsubvol=@swap,nodatacow,noatime,nospace_cache\t0\t0" | sudo tee -a /etc/fstab
echo -e "/swap/swapfile\tnone\tswap\tdefaults\t0\t0" | sudo tee -a /etc/fstab
sudo systemctl daemon-reload
sudo mount /swap
sudo swapon -a
swapon -s

Enable Hibernation

  1. Configure hibernation
export swp_uuid=$(findmnt -no UUID -T /swap/swapfile) && echo $swp_uuid
curl -s "https://raw.githubusercontent.com/osandov/osandov-linux/master/scripts/btrfs_map_physical.c" > bmp.c
gcc -O2 -o bmp bmp.c
swp_offset=$(echo "$(sudo ./bmp /swap/swapfile | egrep "^0\s+" | cut -f9) / $(getconf PAGESIZE)" | bc) && echo $swp_offset
echo -e "GRUB_CMDLINE_LINUX_DEFAULT+=\" resume=UUID=$swp_uuid resume_offset=$swp_offset \"" | sudo tee -a /etc/default/grub
echo -e "HOOKS+=( resume )" | sudo tee -a /etc/mkinitcpio.conf
sudo mkdir -pv /etc/systemd/system/{systemd-logind.service.d,systemd-hibernate.service.d}
echo -e "[Service]\nEnvironment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1" | sudo tee /etc/systemd/system/systemd-logind.service.d/override.conf
echo -e "[Service]\nEnvironment=SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1" | sudo tee /etc/systemd/system/systemd-hibernate.service.d/override.conf
  1. If everything has been made, then update initcpio + grub and reboot
sudo mkinitcpio -P && sudo grub-mkconfig -o /boot/grub/grub.cfg 
reboot

Test it with sudo systemctl hibernate after you reboot once.

:warning: This is a wiki article. You are free to copy, share, or edit the content without restrictions as long as it doesn’t miss the main topic.

10 Likes

As far as I remember, swapfile should be created on a special subvolume with CoW disabled.

3 Likes

amazing!
thank you, it works! :smiley:

I have been looking for weeks to get this working, see my previous ramblings about the topic here:

(I even wasted several hours to try to setup an Arch installation, but failed miserable :wink: )

1 Like

If I understood it correctly, CoW can only be disabled globally for the whole btrfs file system or for single files as done by the command:
chattr +C ./swapfile

The nodatacow option is ignored for subvolume mounts, if other subvolumes of the same btrfs filesystem have been mounted before without it. (at least that’s what I read here: [SOLVED] BTRFS: nodatacow on subvolume / Newbie Corner / Arch Linux Forums )

1 Like

The only thing missing is creating this file on a seperate subvolume, in order for things like Timeshift to work correctly. You do not want to include a huge swapfile in snapshots and backups.

Simply add btrfs subvolume create /@swap to the beginning of your script and replace /swapfile for /@swap/swapfile in your script should do it. I will try it out later.
This also corresponds with the Manjaro wiki. It is a requirement for compatibility:
Swap - Manjaro

Also, when you run this script after installing Manjaro and you had already selected “swapfile” during setup, the script deletes the existing swapfile first. All good, but should you not first do swapoff -a otherwise the file is probably locked/in use? Also, should you not first unmount the swapfile?

@megavolt your script misses a closing bracket on line 54.
Also, my /etc/fstab contains the following commented line:
# Created by a script\n/swapfile\tnone\tswap\tsw\t0\t0 nothing below this comment.
The script should have added:
/swapfile none swap sw 0 0
In my case:
/@swap/swapfile none swap sw 0 0

2 Likes

Hello @zilexa :wink:

I added a note so that it makes clear that you can edit the article at any time:

So if you think that a subvolume should be used, then feel free to change or add it there.

@megavolt I updated & tested the script, works fine now (tested on Manjaro Gnome).

It will now first disable swap, backup fstab and remove any lines with “swap” in fstab before creating btrfs swap properly.

However, I do have 1 question: Why do you need to install pm-utils ?
It won’t install when you use the script because it conflicts with tlp. But after running the script (and verifying pm-utils is indeed not installed and tlp is still installed, hibernation works fine?

1 Like

TLP and pm-utils share some symlinks and therefore it conflicts, but I see that I actually use systemd on all systems… FS#38692 : TLP and pm-utils are now conflicts

I will comment it out and remove it after it is clearly verified :wink:

1 Like

Hello, I followed a mix of this tutorial and the arch wiki to make swapfile working on my Manjaro Plasma system.
In particular I followed the arch wiki here and here (the first one links the second one, so read the steps carefully), creating the swapfile on a new dedicated and non-snapshotted subvolume (no compression, discard and autodefrag options).

In particular, on my old pc I had no problems using

filefrag -v /swapfile | awk '{ if($1=="0:"){print substr($4, 1, length($4)-2)} }'

I saw this arch wiki page: https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file_on_Btrfs and I tried to compare the results of both ways and there were identical.

But I have to claim that with my new pc the filefrag command didn’t worked, like wrote in the arch wiki.
So, using the btrfs_map_physical.c method I was able to set up the hibernation correctly.

The part of this HowTo that I found very useful is:

Thank you all for the collaborative effort!

1 Like

@megavolt when installing the latest (stable, from homepage) Manjaro Gnome, your script no longer works. A swapfile is created and is ‘active’, but hibernation is impossible. Tested on an Intel Nuc gen8 and HP Spectre x360 14 (Intel). With both, your script worked when I installed Manjaro in November.

Now that I have done clean install and run it again it no longer works. The errror

apr 07 11:53:26 Idefix kernel: PM: Cannot find swap device, try swapon -a
apr 07 11:53:26 Idefix kernel: PM: Cannot get swap writer

My swapfile is mounted and working. free command shows swap does exist.

Bigger log:

apr 07 11:53:24 Idefix systemd[1]: Reached target Sleep.
apr 07 11:53:24 Idefix systemd[1]: Starting Hibernate...
apr 07 11:53:24 Idefix audit: BPF prog-id=0 op=UNLOAD
apr 07 11:53:24 Idefix systemd-sleep[1902]: Entering sleep state 'hibernate'...
apr 07 11:53:24 Idefix kernel: audit: type=1334 audit(1649325204.666:135): prog-id=0 op=UNLOAD
apr 07 11:53:24 Idefix kernel: PM: hibernation: hibernation entry
apr 07 11:53:24 Idefix wpa_supplicant[638]: p2p-dev-wlo1: CTRL-EVENT-DSCP-POLICY clear_all
apr 07 11:53:24 Idefix wpa_supplicant[638]: p2p-dev-wlo1: CTRL-EVENT-DSCP-POLICY clear_all
apr 07 11:53:24 Idefix wpa_supplicant[638]: nl80211: deinit ifname=p2p-dev-wlo1 disabled_11b_rates=0
apr 07 11:53:24 Idefix wpa_supplicant[638]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
apr 07 11:53:24 Idefix wpa_supplicant[638]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
apr 07 11:53:24 Idefix wpa_supplicant[638]: nl80211: deinit ifname=wlo1 disabled_11b_rates=0
apr 07 11:53:26 Idefix kernel: Filesystems sync: 0.018 seconds
apr 07 11:53:26 Idefix kernel: Freezing user space processes ... (elapsed 0.015 seconds) done.
apr 07 11:53:26 Idefix kernel: OOM killer disabled.
apr 07 11:53:26 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x00000000-0x00000fff]
apr 07 11:53:26 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x0009f000-0x000fffff]
apr 07 11:53:26 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x4de03000-0x4de1bfff]
apr 07 11:53:26 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x50571000-0x50571fff]
apr 07 11:53:26 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x51a11000-0x59efefff]
apr 07 11:53:26 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x59f00000-0xffffffff]
apr 07 11:53:26 Idefix kernel: PM: hibernation: Basic memory bitmaps created
apr 07 11:53:26 Idefix kernel: PM: hibernation: Preallocating image memory
apr 07 11:53:26 Idefix kernel: PM: hibernation: Allocated 550010 pages for snapshot
apr 07 11:53:26 Idefix kernel: PM: hibernation: Allocated 2200040 kbytes in 0.24 seconds (9166.83 MB/s)
apr 07 11:53:26 Idefix kernel: Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
apr 07 11:53:26 Idefix kernel: printk: Suspending console(s) (use no_console_suspend to debug)
apr 07 11:53:26 Idefix kernel: ACPI: EC: interrupt blocked
apr 07 11:53:26 Idefix kernel: ACPI: PM: Preparing to enter system sleep state S4
apr 07 11:53:26 Idefix kernel: ACPI: EC: event blocked
apr 07 11:53:26 Idefix kernel: ACPI: EC: EC stopped
apr 07 11:53:26 Idefix kernel: ACPI: PM: Saving platform NVS memory
apr 07 11:53:26 Idefix kernel: Disabling non-boot CPUs ...
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 1 is now offline
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 2 is now offline
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 3 is now offline
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 4 is now offline
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 5 is now offline
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 6 is now offline
apr 07 11:53:26 Idefix kernel: IRQ146: set affinity failed(-22).
apr 07 11:53:26 Idefix kernel: smpboot: CPU 7 is now offline
apr 07 11:53:26 Idefix kernel: PM: hibernation: Creating image:
apr 07 11:53:26 Idefix kernel: PM: hibernation: Need to copy 539161 pages
apr 07 11:53:26 Idefix kernel: PM: hibernation: Normal pages needed: 539161 + 1024, available pages: 1464535
apr 07 11:53:26 Idefix kernel: PM: hibernation: Image created (539161 pages copied)
apr 07 11:53:26 Idefix kernel: ACPI: PM: Restoring platform NVS memory
apr 07 11:53:26 Idefix kernel: ACPI: EC: EC started
apr 07 11:53:26 Idefix kernel: Enabling non-boot CPUs ...
apr 07 11:53:26 Idefix kernel: x86: Booting SMP configuration:
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 1 APIC 0x2
apr 07 11:53:26 Idefix kernel: CPU1 is up
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 2 APIC 0x4
apr 07 11:53:26 Idefix kernel: CPU2 is up
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 3 APIC 0x6
apr 07 11:53:26 Idefix kernel: CPU3 is up
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 4 APIC 0x1
apr 07 11:53:26 Idefix kernel: CPU4 is up
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 5 APIC 0x3
apr 07 11:53:26 Idefix kernel: CPU5 is up
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 6 APIC 0x5
apr 07 11:53:26 Idefix kernel: CPU6 is up
apr 07 11:53:26 Idefix kernel: smpboot: Booting Node 0 Processor 7 APIC 0x7
apr 07 11:53:26 Idefix kernel: CPU7 is up
apr 07 11:53:26 Idefix kernel: ACPI: PM: Waking up from system sleep state S4
apr 07 11:53:26 Idefix kernel: ACPI: EC: interrupt unblocked
apr 07 11:53:26 Idefix kernel: ACPI: EC: event unblocked
apr 07 11:53:26 Idefix kernel: pcieport 10000:e0:1d.0: can't derive routing for PCI INT A
apr 07 11:53:26 Idefix kernel: nvme 10000:e1:00.0: PCI INT A: no GSI
apr 07 11:53:26 Idefix kernel: nvme nvme0: 8/0/0 default/read/poll queues
apr 07 11:53:26 Idefix kernel: mei_hdcp 0000:00:16.0-b638ab7e-94e2-4ea2-a552-d1c54b627f04: bound 0000:00:02.0 (ops i915_hdcp_component_ops [i915])
apr 07 11:53:26 Idefix kernel: PM: Cannot find swap device, try swapon -a
apr 07 11:53:26 Idefix kernel: PM: Cannot get swap writer
apr 07 11:53:26 Idefix kernel: PM: hibernation: Basic memory bitmaps freed
apr 07 11:53:26 Idefix kernel: OOM killer enabled.
apr 07 11:53:26 Idefix kernel: Restarting tasks ... done.
apr 07 11:53:26 Idefix gnome-shell[1076]: An active wireless connection, in infrastructure mode, involves no access point?
apr 07 11:53:26 Idefix systemd-sleep[1902]: Failed to put system to sleep. System resumed again: No such device
apr 07 11:53:26 Idefix systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
apr 07 11:53:26 Idefix systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
apr 07 11:53:26 Idefix audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='unit=systemd-hibernate comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? termi>
apr 07 11:53:26 Idefix systemd[1]: Failed to start Hibernate.
apr 07 11:53:26 Idefix systemd[1]: Dependency failed for System Hibernation.
apr 07 11:53:26 Idefix systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
apr 07 11:53:26 Idefix systemd-logind[427]: Operation 'sleep' finished.
apr 07 11:53:26 Idefix systemd[1]: Stopped target Sleep.
apr 07 11:53:26 Idefix kernel: PM: hibernation: hibernation exit
apr 07 11:53:26 Idefix kernel: audit: type=1130 audit(1649325206.393:136): pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='unit=systemd-hibernate comm="systemd" exe="/usr/lib/systemd/syst>
apr 07 11:53:26 Idefix ModemManager[459]: <info>  [sleep-monitor] system is resuming
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.3994] manager: sleep: wake requested (sleeping: yes  enabled: yes)
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.3995] device (wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4000] device (p2p-dev-wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4001] manager: NetworkManager state is now DISCONNECTED
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4226] device (wlo1): supplicant interface state: internal-starting -> disconnected
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4226] device (p2p-dev-wlo1): state change: unavailable -> unmanaged (reason 'removed', sys-iface-state: 'removed')
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4229] Wi-Fi P2P device controlled by interface wlo1 created
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4231] manager: (p2p-dev-wlo1): new 802.11 Wi-Fi P2P device (/org/freedesktop/NetworkManager/Devices/7)
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4232] device (p2p-dev-wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4235] device (wlo1): state change: unavailable -> disconnected (reason 'supplicant-available', sys-iface-state: 'managed')
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4237] device (p2p-dev-wlo1): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
apr 07 11:53:26 Idefix gnome-shell[1076]: Removing a network device that was not added
apr 07 11:53:26 Idefix wpa_supplicant[638]: wlo1: Reject scan trigger since one is already pending
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4254] device (wlo1): supplicant interface state: disconnected -> scanning
apr 07 11:53:26 Idefix NetworkManager[454]: <info>  [1649325206.4254] device (p2p-dev-wlo1): supplicant management interface state: disconnected -> scanning
apr 07 11:53:28 Idefix touchegg.desktop[1374]: Error connecting to Touchégg daemon: Could not connect: Connection refused
apr 07 11:53:28 Idefix touchegg.desktop[1374]: Reconnecting in 5 seconds...

I have no clue how to solve this.
I whish the developers would add “Swapfile with hibernation” (in a subvolume, no need to snapshot the file) in Calamares for BTRFS, that would make it so much easier :pensive:

@megavolt Does your instruction How to Enable and configure hibernation with BTRFS]([HowTo] Enable and configure hibernation with BTRFS) also work with LUKS-encryption?
What exactly has to be considered extra in case?

Not sure, but according to the ArchWiki, the only thing what changes is that the resume parameter at grub must point to unlocked/mapped root partition (which contains the swapfile).

:arrow_down:

resume=/dev/mapper/root_device

I am actually not very interested in full encryption and therefore can only point to wiki articles.

PS: I reworked the steps a bit recently. If you stuck somewhere, see a mistake or have a suggestion, please note it here or edit the content. thanks :wink:

Hey thanks for this, I was also going to spend some time fixing the old script that didn’t work.

I applied your steps to a clean install and found a few minor issues, like setting permissions to /swapfile, instead of /swap/swapfile. Mounting to /swap before creating /swap
Also, for some reason temporarily mounting using /dev/... didn’t work. I am used to doing everything via uuid anyway so that is how I solved it.
This way, only 1 variable is used since you use uuid already in fstab.

But the main issue I found (also in the old script):

echo -e "GRUB_CMDLINE_LINUX_DEFAULT+=\" resume=UUID=$swp_uuid resume_offset=$swp_offset \"" | sudo tee -a /etc/default/grub
Gives me:

GRUB_CMDLINE_LINUX_DEFAULT+=" resume=UUID=7d25c3b8-0c7b-4fd3-8de6-eb911909e71b resume_offset=5288750 "

This does not seem correct:

  • the “+”
  • the space before resume
  • the space after the offset number.

I removed the + and extra spaces, performed the rest of the steps and will reboot now :crossed_fingers:

Unfortunately, still doesn’t work for me.
I have re-checked all steps, I have my @swap subvolume, it is mounted (checked with mount) to /swap, it contains swapfile, I can see it is active via free command. Yet the error I get is:

Cannot find swap device, try swapon -a
Wtf? I don’t get it.
Full journalctl:

jun 02 10:12:01 Idefix dbus-daemon[431]: [system] Activating via systemd: service name='org.freedesktop.home1' unit='dbus-org.freedesktop.home1.service' requested by ':1.164' (uid=0 pid=3089 comm="sudo sy>
jun 02 10:12:01 Idefix dbus-daemon[431]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.home1.service': Unit dbus-org.freedesktop.home1.service not found.
jun 02 10:12:01 Idefix sudo[3089]: pam_systemd_home(sudo:account): systemd-homed is not available: Unit dbus-org.freedesktop.home1.service not found.
jun 02 10:12:01 Idefix audit[3089]: USER_ACCT pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:accounting grantors=pam_unix,pam_permit,pam_time acct="asterix" exe="/usr/bin/sudo" hostname=? addr=? terminal=/>
jun 02 10:12:01 Idefix sudo[3089]:  asterix : TTY=pts/0 ; PWD=/home/asterix ; USER=root ; COMMAND=/usr/bin/systemctl hibernate
jun 02 10:12:01 Idefix audit[3089]: CRED_REFR pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:setcred grantors=pam_env,pam_fprintd acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=s>
jun 02 10:12:01 Idefix kernel: audit: type=1101 audit(1654157521.143:140): pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:accounting grantors=pam_unix,pam_permit,pam_time acct="asterix" exe="/usr/bin/sudo">
jun 02 10:12:01 Idefix kernel: audit: type=1110 audit(1654157521.143:141): pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:setcred grantors=pam_env,pam_fprintd acct="root" exe="/usr/bin/sudo" hostname=? add>
jun 02 10:12:01 Idefix sudo[3089]: pam_unix(sudo:session): session opened for user root(uid=0) by (uid=1000)
jun 02 10:12:01 Idefix audit[3089]: USER_START pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:session_open grantors=pam_systemd_home,pam_limits,pam_unix,pam_permit acct="root" exe="/usr/bin/sudo" hostname=>
jun 02 10:12:01 Idefix kernel: audit: type=1105 audit(1654157521.146:142): pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:session_open grantors=pam_systemd_home,pam_limits,pam_unix,pam_permit acct="root" e>
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.1540] manager: sleep: sleep requested (sleeping: no  enabled: yes)
jun 02 10:12:01 Idefix audit[3089]: USER_END pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:session_close grantors=pam_systemd_home,pam_limits,pam_unix,pam_permit acct="root" exe="/usr/bin/sudo" hostname=?>
jun 02 10:12:01 Idefix audit[3089]: CRED_DISP pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:setcred grantors=pam_env,pam_fprintd acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/0 res=s>
jun 02 10:12:01 Idefix ModemManager[462]: <info>  [sleep-monitor] system is about to suspend
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.1541] device (p2p-dev-wlo1): state change: disconnected -> unmanaged (reason 'sleeping', sys-iface-state: 'managed')
jun 02 10:12:01 Idefix sudo[3089]: pam_unix(sudo:session): session closed for user root
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.1545] manager: NetworkManager state is now ASLEEP
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.1546] device (wlo1): state change: activated -> deactivating (reason 'sleeping', sys-iface-state: 'managed')
jun 02 10:12:01 Idefix kernel: audit: type=1106 audit(1654157521.153:143): pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:session_close grantors=pam_systemd_home,pam_limits,pam_unix,pam_permit acct="root" >
jun 02 10:12:01 Idefix kernel: audit: type=1104 audit(1654157521.153:144): pid=3089 uid=1000 auid=1000 ses=4 msg='op=PAM:setcred grantors=pam_env,pam_fprintd acct="root" exe="/usr/bin/sudo" hostname=? add>
jun 02 10:12:01 Idefix dbus-daemon[431]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.3' (uid=0 pid=452 >
jun 02 10:12:01 Idefix systemd[1]: Starting Network Manager Script Dispatcher Service...
jun 02 10:12:01 Idefix dbus-daemon[431]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
jun 02 10:12:01 Idefix systemd[1]: Started Network Manager Script Dispatcher Service.
jun 02 10:12:01 Idefix audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=NetworkManager-dispatcher comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res>
jun 02 10:12:01 Idefix kernel: audit: type=1130 audit(1654157521.163:145): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=NetworkManager-dispatcher comm="systemd" exe="/usr/lib/systemd/systemd" host>
jun 02 10:12:01 Idefix kernel: wlo1: deauthenticating from 78:8a:20:5e:3e:75 by local choice (Reason: 3=DEAUTH_LEAVING)
jun 02 10:12:01 Idefix wpa_supplicant[627]: wlo1: CTRL-EVENT-DISCONNECTED bssid=78:8a:20:5e:3e:75 reason=3 locally_generated=1
jun 02 10:12:01 Idefix wpa_supplicant[627]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3084] device (wlo1): state change: deactivating -> disconnected (reason 'sleeping', sys-iface-state: 'managed')
jun 02 10:12:01 Idefix wpa_supplicant[627]: wlo1: CTRL-EVENT-SIGNAL-CHANGE above=0 signal=-9999 noise=9999 txrate=0
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3273] dhcp4 (wlo1): canceled DHCP transaction
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3273] dhcp4 (wlo1): activation: beginning transaction (timeout in 45 seconds)
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3274] dhcp4 (wlo1): state changed no lease
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3305] device (wlo1): set-hw-addr: set MAC address to 6A:1A:2C:DA:09:05 (scanning)
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3760] device (wlo1): supplicant interface state: completed -> disconnected
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3768] device (wlo1): state change: disconnected -> unmanaged (reason 'sleeping', sys-iface-state: 'managed')
jun 02 10:12:01 Idefix NetworkManager[452]: <info>  [1654157521.3796] device (wlo1): set-hw-addr: reset MAC address to 2C:DB:07:80:24:33 (unmanage)
jun 02 10:12:01 Idefix touchegg.desktop[1328]: Error connecting to Touchégg daemon: Could not connect: Connection refused
jun 02 10:12:01 Idefix touchegg.desktop[1328]: Reconnecting in 5 seconds...
jun 02 10:12:01 Idefix systemd[1]: Reached target Sleep.
jun 02 10:12:01 Idefix systemd[1]: Starting Hibernate...
jun 02 10:12:01 Idefix audit: BPF prog-id=0 op=UNLOAD
jun 02 10:12:01 Idefix kernel: audit: type=1334 audit(1654157521.393:146): prog-id=0 op=UNLOAD
jun 02 10:12:01 Idefix wpa_supplicant[627]: p2p-dev-wlo1: CTRL-EVENT-DSCP-POLICY clear_all
jun 02 10:12:01 Idefix wpa_supplicant[627]: p2p-dev-wlo1: CTRL-EVENT-DSCP-POLICY clear_all
jun 02 10:12:01 Idefix wpa_supplicant[627]: nl80211: deinit ifname=p2p-dev-wlo1 disabled_11b_rates=0
jun 02 10:12:01 Idefix systemd-sleep[3106]: Entering sleep state 'hibernate'...
jun 02 10:12:01 Idefix kernel: PM: hibernation: hibernation entry
jun 02 10:12:01 Idefix wpa_supplicant[627]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
jun 02 10:12:01 Idefix wpa_supplicant[627]: wlo1: CTRL-EVENT-DSCP-POLICY clear_all
jun 02 10:12:01 Idefix wpa_supplicant[627]: nl80211: deinit ifname=wlo1 disabled_11b_rates=0
jun 02 10:12:03 Idefix kernel: Filesystems sync: 0.017 seconds
jun 02 10:12:03 Idefix kernel: Freezing user space processes ... (elapsed 0.031 seconds) done.
jun 02 10:12:03 Idefix kernel: OOM killer disabled.
jun 02 10:12:03 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x00000000-0x00000fff]
jun 02 10:12:03 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x0009f000-0x000fffff]
jun 02 10:12:03 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x4de03000-0x4de1bfff]
jun 02 10:12:03 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x50571000-0x50571fff]
jun 02 10:12:03 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x51a11000-0x59efefff]
jun 02 10:12:03 Idefix kernel: PM: hibernation: Marking nosave pages: [mem 0x59f00000-0xffffffff]
jun 02 10:12:03 Idefix kernel: PM: hibernation: Basic memory bitmaps created
jun 02 10:12:03 Idefix kernel: PM: hibernation: Preallocating image memory
jun 02 10:12:03 Idefix kernel: PM: hibernation: Allocated 756343 pages for snapshot
jun 02 10:12:03 Idefix kernel: PM: hibernation: Allocated 3025372 kbytes in 0.31 seconds (9759.26 MB/s)
jun 02 10:12:03 Idefix kernel: Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
jun 02 10:12:03 Idefix kernel: printk: Suspending console(s) (use no_console_suspend to debug)
jun 02 10:12:03 Idefix kernel: ACPI: EC: interrupt blocked
jun 02 10:12:03 Idefix kernel: ACPI: PM: Preparing to enter system sleep state S4
jun 02 10:12:03 Idefix kernel: ACPI: EC: event blocked
jun 02 10:12:03 Idefix kernel: ACPI: EC: EC stopped
jun 02 10:12:03 Idefix kernel: ACPI: PM: Saving platform NVS memory
jun 02 10:12:03 Idefix kernel: Disabling non-boot CPUs ...
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 1 is now offline
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 2 is now offline
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 3 is now offline
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 4 is now offline
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 5 is now offline
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 6 is now offline
jun 02 10:12:03 Idefix kernel: IRQ148: set affinity failed(-22).
jun 02 10:12:03 Idefix kernel: smpboot: CPU 7 is now offline
jun 02 10:12:03 Idefix kernel: PM: hibernation: Creating image:
jun 02 10:12:03 Idefix kernel: PM: hibernation: Need to copy 743588 pages
jun 02 10:12:03 Idefix kernel: PM: hibernation: Normal pages needed: 743588 + 1024, available pages: 1260135
jun 02 10:12:03 Idefix kernel: PM: hibernation: Image created (743588 pages copied)
jun 02 10:12:03 Idefix kernel: ACPI: PM: Restoring platform NVS memory
jun 02 10:12:03 Idefix kernel: ACPI: EC: EC started
jun 02 10:12:03 Idefix kernel: Enabling non-boot CPUs ...
jun 02 10:12:03 Idefix kernel: x86: Booting SMP configuration:
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 1 APIC 0x2
jun 02 10:12:03 Idefix kernel: CPU1 is up
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 2 APIC 0x4
jun 02 10:12:03 Idefix kernel: CPU2 is up
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 3 APIC 0x6
jun 02 10:12:03 Idefix kernel: CPU3 is up
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 4 APIC 0x1
jun 02 10:12:03 Idefix kernel: CPU4 is up
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 5 APIC 0x3
jun 02 10:12:03 Idefix kernel: CPU5 is up
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 6 APIC 0x5
jun 02 10:12:03 Idefix kernel: CPU6 is up
jun 02 10:12:03 Idefix kernel: smpboot: Booting Node 0 Processor 7 APIC 0x7
jun 02 10:12:03 Idefix kernel: CPU7 is up
jun 02 10:12:03 Idefix kernel: ACPI: PM: Waking up from system sleep state S4
jun 02 10:12:03 Idefix kernel: ACPI: EC: interrupt unblocked
jun 02 10:12:03 Idefix kernel: ACPI: EC: event unblocked
jun 02 10:12:03 Idefix kernel: pcieport 10000:e0:1d.0: can't derive routing for PCI INT A
jun 02 10:12:03 Idefix kernel: nvme 10000:e1:00.0: PCI INT A: no GSI
jun 02 10:12:03 Idefix kernel: nvme nvme0: 8/0/0 default/read/poll queues
jun 02 10:12:03 Idefix kernel: mei_hdcp 0000:00:16.0-b638ab7e-94e2-4ea2-a552-d1c54b627f04: bound 0000:00:02.0 (ops i915_hdcp_component_ops [i915])
jun 02 10:12:03 Idefix kernel: PM: Cannot find swap device, try swapon -a
jun 02 10:12:03 Idefix kernel: PM: Cannot get swap writer
jun 02 10:12:03 Idefix kernel: PM: hibernation: Basic memory bitmaps freed
jun 02 10:12:03 Idefix kernel: OOM killer enabled.
jun 02 10:12:03 Idefix kernel: Restarting tasks ... done.
jun 02 10:12:03 Idefix gnome-shell[1031]: An active wireless connection, in infrastructure mode, involves no access point?
jun 02 10:12:03 Idefix systemd-sleep[3106]: Failed to put system to sleep. System resumed again: No such device
jun 02 10:12:03 Idefix kernel: PM: hibernation: hibernation exit
jun 02 10:12:03 Idefix systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
jun 02 10:12:03 Idefix systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
jun 02 10:12:03 Idefix systemd[1]: Failed to start Hibernate.
jun 02 10:12:03 Idefix audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=systemd-hibernate comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=failed'
jun 02 10:12:03 Idefix systemd[1]: Dependency failed for System Hibernation.
jun 02 10:12:03 Idefix systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
jun 02 10:12:03 Idefix systemd[1]: Stopped target Sleep.
jun 02 10:12:03 Idefix systemd-logind[434]: Operation 'sleep' finished.
jun 02 10:12:03 Idefix ModemManager[462]: <info>  [sleep-monitor] system is resuming
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4121] manager: sleep: wake requested (sleeping: yes  enabled: yes)
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4121] device (wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4126] device (p2p-dev-wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4128] manager: NetworkManager state is now DISCONNECTED
jun 02 10:12:03 Idefix kernel: audit: type=1130 audit(1654157523.410:147): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=systemd-hibernate comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? a>
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4383] device (wlo1): supplicant interface state: internal-starting -> disconnected
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4383] device (p2p-dev-wlo1): state change: unavailable -> unmanaged (reason 'removed', sys-iface-state: 'removed')
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4386] Wi-Fi P2P device controlled by interface wlo1 created
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4387] manager: (p2p-dev-wlo1): new 802.11 Wi-Fi P2P device (/org/freedesktop/NetworkManager/Devices/6)
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4388] device (p2p-dev-wlo1): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4391] device (wlo1): state change: unavailable -> disconnected (reason 'supplicant-available', sys-iface-state: 'managed')
jun 02 10:12:03 Idefix NetworkManager[452]: <info>  [1654157523.4393] device (p2p-dev-wlo1): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
jun 02 10:12:03 Idefix gnome-shell[1031]: Removing a network device that was not added

EDIT:
OK I found more issues, fixed now:

  1. sudo sed -i "s/ filesystems / filesystems resume /g" /etc/mkinitcpio.conf does not work because in the file, filesystems is the last attribute, there is no space after it, just ". This is on a clean install of Manjaro Gnome (installed yesterday with latest image from homepage).
  2. (see response from freggel.doe below, not an issue) the file /etc/default/grub already has a line with GRUB_CMDLINE_LINUX_DEFAULT=, after following the steps, an additional one is added to the bottom, I manually added those attributes to the top one and removed the bottom one:
    Looks like this now:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor udev.log_priority=3 resume=UUID=7d25c3b8-0c7b-4fd3-8de6-eb911909e71b resume_offset=5288750"

Then I performed the last action, to update initcpio + grub and reboot.
Still, same error! Does not work.

I then checked this command:

export swp_uuid=$(findmnt -no UUID -T /swap/swapfile) && echo $swp_uuid

It returns the same UUID as findmnt / -o UUID -n, which is the UUID of my root drive/btrfs root subvolume /dev/nvme0n1p2, the same UUID that is in /etc/fstab to mount ech subvolume… it is not a unique UUID for /swap or /swap/file.

This might be the issue?

I looked up the btrfs UUID of the @swap subvolume, replaced it in /etc/default/grub, again updates initcpio + grub and rebooted, still cannot hibernate, exact same error :frowning:

But it is, see

In the context where an assignment statement is assigning a value to a shell variable or array index (see Arrays), the ‘+=’ operator can be used to append to or add to the variable’s previous value.

Using witespace “around” strings to append is commonplace to not mess up any previous content.

1 Like

@freggel.doe thanks! I restored that command in the wiki. But I already fixed that file manually on my, still hibernation doesn’t work. Might have found the culprit, see my latest message above you. Not sure how to fix.

Hello @zilexa

I will check/test the script again with the latest xfce minimal iso (that is the one which I use for testing in a vm).

I will update this post, when finished this weekend.

Thanks @megavolt I do believe every command in the guide now works correctly.

Why I get this error is beyond me.

I have had this error on older systems since almost half a year now. No matter how many times I configure this, always end up with the same error.
Now that I tested your new version on a clean new install I’m convinced the issue is not isolated to my systems.

Hello @zilexa,

I guess I have found the issue and it was my mistake. I forgot that I didn’t use filefrag on my setup :man_facepalming:

Normally it is a “setup and forget” configuration for me and well you know, I have forgotten it. :roll_eyes:

Thanks @zomberman for mentioning it. Sadly you did not edit the wiki post. I almost over read it.

1 Like

Thanks!
With the new & updated wiki, my script is now working again, copy pasted the wiki and also enabled a few related stuff, tested & verified:

manjaro-gnome-post-install/btrfs-hibernation.sh at main · zilexa/manjaro-gnome-post-install · GitHub

The script will:

  1. Automatically perform the actions in this wiki, creating the root subvolume for swap, swap file and configuring hibernation.
  2. Additionally, enable "suspend-then-hibernate", the most modern way of standby! suspend-then-hibernate will be the default suspend method for suspend, always hibernating 2 hours after suspend.
  3. Power-off key will skip suspend, instead hibernate the system immediately.
  4. (If a laptop) lid close will “suspend-then-hibernate”.

What is suspend-then-hibernate?
The system will go quickly into standby and wake up quickly if woken by the user within 2 hours. Otherwise, it will automatically wake up and hibernate (write to swap & shutdown completely), saving battery power and preventing you from losing data when battery dies.
When you wake the system after 2 hours, wake up can take slightly longer as it will wake up from hibernation.