Skip to content

Hibernation Not Working with Swapfile! Here’s My Fix #144

@rezasadid753

Description

@rezasadid753

Hi Alexandre,

First off, thanks for your awesome Hibernate Status Button extension as it's exactly what I needed, It's simple and helpful! I recently tried enabling hibernate on my Ubuntu setup using your Hibernate Status Button, and while it installed fine, hibernation didn’t work when I ran it manually via systemctl hibernate. The system shut down but on boot it didn’t resume the session, it started fresh instead!

Well I noticed that when using a swap file instead of a partition the Linux kernel needs the physical disk offset of that file to properly resume from hibernation. This detail isn’t configured by default. To fix it, I extracted the first physical block offset using:

filefrag -v /swapfile | awk '/ 0:/{print $4; exit}' | sed 's/\.\.//'

Then I identified my root partition using:

findmnt /

With that info, I edited GRUB:

sudo nano /etc/default/grub

and added this to the GRUB_CMDLINE_LINUX_DEFAULT:

resume=/dev/sdX resume_offset=123456

Note: Be sure to replace /dev/sdX with the actual device where your root system is mounted (you’ll get that from findmnt /) and 123456 with the real offset value you retrieved from the filefrag command.

I also did set the same resume configuration for initramfs:

echo "RESUME=/dev/sdX resume_offset=123456" | sudo tee /etc/initramfs-tools/conf.d/resume

Then updated everything and rebooted:

sudo update-initramfs -u
sudo update-grub
sudo reboot

After this, systemctl hibernate worked properly, and my session was restored after boot. This was my way of handling the issue and it might be helpful for others running similar setups. If possible, I’d love to see some of this logic baked into the extension itself or even referenced in the documentation.

Thanks again for your work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions