gissf1 / zram-hibernate

Allows dynamic swap changes to activate disk-based storage as swap for hibernation support when a system typically uses only zram swap during normal operation.
Apache License 2.0
35 stars 3 forks source link

Help with setting up `zram-hibernate` #1

Open JustSimplyKyle opened 2 years ago

JustSimplyKyle commented 2 years ago

It's probably a me problem tbh When I run doas /usr/lib/systemd/system-sleep/zram-hibernate it spit out this

[90315] creating tmpfile...
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
[90315] lock acquired.
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
getResumeInfo() Not a valid block device: KERNEL_RESUME_DEVICE=
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
ensureDiskSwap(): Initial swap status...
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
[19:24:08] Used=5426M MemFree=22G SwapUsed=0K/31G Overcommit=0K
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
egrep: warning: egrep is obsolescent; using grep -E
        zram0:  0.0% (0K/31G) [100]
egrep: warning: egrep is obsolescent; using grep -E
fgrep: warning: fgrep is obsolescent; using grep -F
egrep: warning: egrep is obsolescent; using grep -E
FATAL: no valid swaps found. cannot suspend to disk.

I thought this script is supposed to make hibernating without swap but with zram possible?

gissf1 commented 1 year ago

Sorry, I meant with debug enabled, so running the script directly with at least -vvv

Also, I was just thinking, do you notice anything in the system's logs (maybe the audit log?) about denying permissions to execute systemctl or anything like that?

JustSimplyKyle commented 1 year ago

https://asciinema.org/connect/7a750c30-19ed-46db-8cd2-84bd76aab22a

JustSimplyKyle commented 1 year ago

this includes my computer literally going hibernate, so the pause there is because of that

fuelen commented 1 year ago

@JustSimplyKyle seems like the recording is private

JustSimplyKyle commented 1 year ago

Should be fixed now

fuelen commented 1 year ago

@JustSimplyKyle I see the same message:

This recorder token belongs to a different user.

JustSimplyKyle commented 1 year ago

https://asciinema.org/a/556975 How 'bout this?

JustSimplyKyle commented 1 year ago

maybe the audit log?

How would i do this? if you mean dmesg nothing sus came up

mananhiteshkataria commented 1 year ago

https://asciinema.org/a/lgsPjcY9OPccdkHlg6Y57XD3I

I am a having some trouble as well with arch and a swap file.

Completely new to Linux 😔.

JustSimplyKyle commented 1 year ago

https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file btrfs inspect-internal map-swapfile -r path/to/swapfile This to get the "resume_offsett"

mananhiteshkataria commented 1 year ago

https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file btrfs inspect-internal map-swapfile -r path/to/swapfile This to get the "resume_offsett"

Got this value but am confused as to where to add this as I cannot find initramfs

gissf1 commented 1 year ago

Being up front, typically I don't like cluttering a thread with multiple unrelated issues, but I'll go with it this time since JustSimplyKyle already started addressing this issue here. In the future, individuals with issues that do not include the same error message or primary concern as the OP should open a new issue so each situation can be focused on and addressed directly.

@mananhiteshkataria the resume=XXX argument should be specified in your bootloader configuration. If you're using a swap file instead of a swap partition, several filesystems require the use of the resume_offset= parameter as well for proper resume so the kernel knows where to find the swap file before the filesystem driver is loaded.

If your bootloader is GRUB, the configuration process would be one (or both) of the following:

If you're using one of the several UEFI-specific boot loaders (rEFInd, systemd-boot, etc), you'll need to look into your bootloader's documentation to find out how and where to edit the kernel command line parameters, but the concept is the same.

initramfs is not related to setting up hibernation or configuring the resume= parameter, but on Arch Linux, initramfs is generated automatically when a new kernel is installed or manually by using the command mkinitcpio. Please look that up in the Arch wiki or man pages for more details.

gissf1 commented 1 year ago

maybe the audit log?

How would i do this? if you mean dmesg nothing sus came up

You mentioned dmesg, which is a great source for kernel log messages, but systemd and other system processes often do their logging in ways that are not included in the dmesg output.

Many system logs are stored under /var/log/ in some way. On older systems, there were several text files in this location that could be viewed with any text editor. On most modern systems, you can view these system log messages with the journalctl tool.

Audit logs are one of many messages reported there, and would contain reports of system security audit successes and failures (programs trying to do things that the system allowed/prevented them from doing).

My thought is that perhaps something may be indicated there to help us figure out why your systemctl hibernate is having issues.

From your video, it seems like the script is finding everything perfectly fine in debug mode. What happens differently when you run systemctl hibernate?

If needed, we could try to make a modified version of this script to record output to a log file when called by systemctl hibernate so we can see whats going wrong in that situation.

JustSimplyKyle commented 1 year ago

https://asciinema.org/a/557696 After changing the bottom of the script to this

elif [[ $PRE != 0 ]]; then
    echo "streb" > /tmp/status
    pre_main

there was nothing at /tmp/status my guess is then my system is "haunted" and doesn't want to excute from pre

JustSimplyKyle commented 1 year ago
❯ doas journalctl -b -u hibernate.target 
Feb 06 13:45:45 arch systemd[1]: Dependency failed for System Hibernation.
Feb 06 13:45:45 arch systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
Feb 06 13:50:09 arch systemd[1]: Dependency failed for System Hibernation.
Feb 06 13:50:09 arch systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
Feb 06 13:50:34 arch systemd[1]: Dependency failed for System Hibernation.
Feb 06 13:50:34 arch systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
Feb 06 13:51:54 arch systemd[1]: Dependency failed for System Hibernation.
Feb 06 13:51:54 arch systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.
Feb 06 13:55:49 arch systemd[1]: Dependency failed for System Hibernation.
Feb 06 13:55:49 arch systemd[1]: hibernate.target: Job hibernate.target/start failed with result 'dependency'.

huh

JustSimplyKyle commented 1 year ago
Feb 06 13:51:54 arch systemd-sleep[28723]: Failed to find location to hibernate to: Function not implemented
Feb 06 13:51:54 arch systemd[1]: systemd-hibernate.service: Main process exited, code=exited, status=1/FAILURE
Feb 06 13:51:54 arch systemd[1]: systemd-hibernate.service: Failed with result 'exit-code'.
Feb 06 13:51:54 arch systemd[1]: Failed to start Hibernate.
Nov 03 17:47:22 arch systemd-sleep[242438]: Entering sleep state 'hibernate'...

wait what?

JustSimplyKyle commented 1 year ago

I made it working by directly telling it to use zram-hibernate in pre hibernate(and consequenctly post hibernate), but this isn't ideal.(/etc/systemd/system/hibernate-preparation.service)

[Unit]
Description=Enable swap file and disable zram before hibernate
Before=systemd-hibernate.service

[Service]
User=root
Type=oneshot
ExecStart=/bin/bash -c "/usr/lib/systemd/system-sleep/zram-hibernate pre"

[Install]
WantedBy=systemd-hibernate.service
gissf1 commented 1 year ago

Interesting partial workaround there by calling it with "pre" in a service. You should also throw in "hibernate" as a second parameter since that's the expected calling convention.

That makes perfect sense though as to why it wasn't working - if it's never getting called with "pre" it will never set up the swap to hibernate into. "post" is used for cleanup and restoration.

I'm not sure why that might be happening though... From the systemd-sleep (8) manpage, it says:

Immediately before entering system suspend and/or hibernation systemd-suspend.service (and the other mentioned units, respectively) will run all executables in /usr/lib/systemd/system-sleep/ and pass two arguments to them. The first argument will be "pre", the second either "suspend", "hibernate", "hybrid-sleep", or "suspend-then-hibernate" depending on the chosen action. [...] Immediately after leaving system suspend and/or hibernation the same executables are run, but the first argument is now "post". All executables in this directory are executed in parallel, and execution of the action is not continued until all executables have finished.

As a workaround, I wonder if we can use the ExecStop to trigger the post event. Try adding these just after the ExecStart line:

RemainAfterExit=1
ExecStop=/bin/bash -c "/usr/lib/systemd/system-sleep/zram-hibernate post hibernate"

That still doesn't explain why it's not being called as the manpage suggests it should though.

JustSimplyKyle commented 1 year ago

echo "${1}" "${2}" "$SYSTEMD_SLEEP_ACTION" > /tmp/aaar I even made a simpler script, still nothing shows up in /tmp/aaar I wonder where should I put this in?

RemainAfterExit=1 ExecStop=/bin/bash -c "/usr/lib/systemd/system-sleep/zram-hibernate post hibernate"

gissf1 commented 1 year ago

Try putting that in the [Service] section, directly below ExecStart=.

JustSimplyKyle commented 1 year ago

Yep that works! And my test script also executed... So it seems like it will only execute scripts in the directory only if the system has already got into hibernation mode

gissf1 commented 1 year ago

Excellent! Glad to hear that worked!

I'll try to look into what's going on with systemd-sleep and why it's not calling the script and I'll report back here. If you are interested in researching it, and run across anything related, please share it here as well.

If we can't find a more direct solution, are you be interested in contributing your hibernate-preparation.service file to the project?

JustSimplyKyle commented 1 year ago

Yeah, for a backup case ig. it's not ideal since suspend-then-hibernate wouldn't work, but better than not working at all