Hack The Planet!

Spellbook > Linux

Spell #4 Configure hybrid sleep in Omarchy / Arch Linux

Synopsis

This guide shows how to configure hibernation on Omarchy or Arch Linux for e.g. a Framework laptop. This guide was tested on a Framework 13 AMD Ryzen 7040 laptop, but you should be able to adapt the instructions for any Linux distribution that has a modern kernel and uses systemd.

Here suspend-then-hibernate is chosen over hybrid-sleep. You can look up the differences between them elsewhere but this configures the behavior that I want on my laptop:

  • Go to a low power state when I close the lid
  • Wake up fast from this state before an extended idle period starts
  • Save more battery when the idle period exceeds 30 minutes by saving state to disk and shutting down (hibernate)
  • Also hibernate when battery is critically low

Assumptions

  • You are using Omarchy or Arch Linux
  • You are using btrfs

Open a root shell

sudo -i

Create a swap subvolume to store hibernation data

Calculate swap file size based on physical RAM size

SWAPSIZE=$(free | awk '/Mem/ {x=$2/1024/1024; printf "%.0fG", (x<2 ? 2*x : x<8 ? 1.5*x : x) }')

Create a btrfs subvolume for swap and disable Copy on Write

btrfs subvolume create /var/swap
chattr +C /var/swap

Create the swap file

btrfs filesystem mkswapfile --size $SWAPSIZE /var/swap/swapfile

Add the swap file to /etc/fstab and enable it

echo '/var/swap/swapfile none swap defaults 0 0' | tee -a /etc/fstab
swapon -a

Enable resuming from hibernation file

Add the resume hook

cat << 'EOF' > /etc/mkinitcpio.conf.d/resume.conf
HOOKS+=(resume)
EOF

Regenerate initramfs

limine-mkinitcpio

Configure laptop lid action

cat << 'EOF' >> /etc/systemd/logind.conf
HandleLidSwitch=suspend-then-hibernate
EOF

Configure hibernation timeout

cat << 'EOF' >> /etc/systemd/sleep.conf
HibernateDelaySec=30min
HibernateOnACPower=no
EOF

Test hibernation

systemctl hibernate