You are not logged in.

#1 2019-05-09 07:09:07

pradtf
Member
Registered: 2009-06-10
Posts: 134

[SOLVED] hibernate not keeping original state

my understanding is that
systemctl hibernate
saves the current state to swap so it can be recovered on powerup.

using the wiki:
https://wiki.archlinux.org/index.php/Po … ibernation
and Archlinux enabling hibernation:
http://blog.programmableproduction.com/ … Hibernate/

i did the following:

1. setup swap file
find size of image to be stored in swap /sys/power/image_size
fallocate -l 3.3G /home/swapfile (swapfile is in /dev/sda2)
chmod 600 /home/swapfile
mkswap /home/swapfile
swapon /home/swapfile
make entry into /etc/fstab

2. find file offset for swapfile
filefrag -v /home/swapfile | awk '{ if($1=="0:"){print $4} }'
which gives 6538233..

3. modify grub
alter in /etc/default/grub adding on resume and resume_offset:
GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=/dev/sda2 resume_offset=6538233.."
grub-mkconfig -o /boot/grub/grub.cfg

4. update mkinitcpio
add resume hook to /etc/mkinitcpio.conf
HOOKS=(base udev resume autodetect modconf block filesystems keyboard fsck)
then generate base image:
mkinitcpio -p linux

then i reboot as instructed in the wiki before first hibernation.
then i hibernate with systemctl hibernate.

the system shutdown properly, but when i power on again i don't get my original state back eg
no gnome-terminal
no emacs
no chromium (though when i restore chromium the pages all come back - but that's thx to chromium)

i tried from
Hibernate not functioning rekahsoft
https://bbs.archlinux.org/viewtopic.php?id=175822

echo disk > /sys/power/state
but got
echo: write error: no such device

so the state is not being saved to swapfile it seems.

i am on a desktop with archlinux installed less than a week ago and i have done pacman -Syu just before making this post.

would appreciate some insights. thx!

Last edited by pradtf (2019-05-19 17:07:05)


in friendship,
prad

Offline

#2 2019-05-19 07:52:38

cowile
Member
Registered: 2019-05-01
Posts: 15

Re: [SOLVED] hibernate not keeping original state

Please clarify: Do you get any part of the running system back? For example, are you still logged in after reboot?

Second, basic checks, does journalctl or dmesg say anything about resuming? Post the output of

lsblk

.


The Linux motto is "Laugh in the face of danger." Oops, wrong one. "Do it yourself." Yes, that's it. -- Linus Torvalds

Offline

#3 2019-05-19 17:02:28

pradtf
Member
Registered: 2009-06-10
Posts: 134

Re: [SOLVED] hibernate not keeping original state

hey thx for the ideas cowile!

when i followed up on checking dmesg i found that resume was indeed showing up but:

A. it was the incorrect offset because i had altered the swapfile but foolishly forgot to get a new offset.

after remedying this i found

B. i hadn't properly coded /etc/default/grub (and the system wouldn't boot)

fixed all these things and hibernate worked perfectly!!



here are the all the correct steps i took to get hibernate to work (for reference):

1. setup swap file
find size of image to be stored in swap /sys/power/image_size

fallocate -l 3.3G /home/swapfile (swapfile is in /dev/sda2)
chmod 600 /home/swapfile
mkswap /home/swapfile
swapon /home/swapfile

make entry into /etc/fstab: /home/swapfile none swap defaults 0 0

2. find file offset for swapfile

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

it'll give something like nnnnnnn..

3. alter /boot/grub/grub.cfg
take the value of #2 and put it and the partition holding the swapfile as
GRUB_CMDLINE_LINUX_DEFAULT="quiet resume=/dev/sda2 resume_offset=nnnnnnn.."
into /etc/default/grub
then regenerate the /boot/grub/grub.cfg with

grub-mkconfig -o /boot/grub/grub.cfg

4. update mkinitcpio
add resume hook to /etc/mkinitcpio.conf
HOOKS=(base udev resume autodetect modconf block filesystems keyboard fsck)
then generate base image:

mkinitcpio -p linux

5. reboot (don't try to hibernate without rebooting this once!)

6. go into hibernate using:

systemctl hibernate

note: if you change the swapfile, the offset will likely change as well, so you need to do the steps over again.

thx again cowile for the guidance!

Last edited by pradtf (2019-05-23 17:23:34)


in friendship,
prad

Offline

#4 2022-04-15 03:25:34

solomonbstoner
Member
From: Singapore
Registered: 2018-07-16
Posts: 2

Re: [SOLVED] hibernate not keeping original state

How did you check your `dmesg`? When I forgot to set the `resume` hook in `mkinitcpio.conf` (even though I set the `grub` and `swap` correctly), `systemctl hibernate` would work, but attempting to resume became a restart. `dmesg` in my case looks like a complete restart rather than a resume. How did resume appear in your `dmesg`?

Offline

#5 2022-04-15 17:09:43

pradtf
Member
Registered: 2009-06-10
Posts: 134

Re: [SOLVED] hibernate not keeping original state

@solomonbstoner

dmesg | grep resume
is what i presume

ii can't recall for sure because i don't use a swap file anymore having switched to a swap partition a couple of years ago (so i can't test it on my computer). all that's showing up for me is "ACPI: PM: Low-level resume complete"


in friendship,
prad

Offline

Board footer

Powered by FluxBB