Skip to content

hibernate

XADE edited this page Dec 10, 2023 · 1 revision

Hibernation on Btrfs and Performance Improvement

initramfs with module : resume is needed for hibernation to work

after creating a swap file [in this example /.swap/swap]

curl -OL https://raw.githubusercontent.com/osandov/osandov-linux/master/scripts/btrfs_map_physical.c

gcc -O2 -o btrfs_map_physical btrfs_map_physical.c

# replace /.swap/swap below with path to swapfile

OFFSET="$(./btrfs_map_physical /.swap/swap | awk -v SIZE="$(getconf PAGESIZE)" 'NR==2 {printf $NF/SIZE}')" 

GC=$(cat /etc/default/grub)

# now add kernel parameters needed for hibernation and performance

printf '%s' "${GC%%\"} resume=UUID=$(findmnt / -o UUID -n) resume_offset=$OFFSET zswap.enabled=1 mitigations=off psi=1\"" > /etc/default/grub
  • to update grub menu
grub-mkconfig -o /boot/grub/grub.cfg

after a reboot, to hibernate run

printf disk > /sys/power/state

even with swap smaller than RAM, successfull hibernation is possible by reducing the value of /sys/power/image_size

printf 0 > /sys/power/image_size

Features

Requirements

Notes


Walk Through :

  1. Execute the script

  1. Select Distro & Packages

Click one of the Distros below for Detailed steps

Distro non Systemd Immutable musl support compilation support
Arch
Artix
Alpine
Void
Gentoo
Funtoo
NixOS
GUIX

Questions :

How ?

Why ?

Clone this wiki locally