This guide configures suspend-then-hibernate on CachyOS with btrfs, GRUB, and zram. The system will suspend to RAM when you close the lid, then automatically hibernate to disk after 2 hours.
System specs: 32GB RAM, btrfs filesystem, GRUB bootloader, existing zram
Create a 38GB swap file for hibernation (RAM + sqrt(RAM)):
# Create swap directory if it doesn't exist
sudo mkdir -p /swap
# Create swap file on btrfs
sudo btrfs filesystem mkswapfile --size 38G /swap/swapfile
# If the above command doesn't work (older btrfs-progs), use this method:
sudo truncate -s 0 /swap/swapfile
sudo chattr +C /swap/swapfile
sudo fallocate -l 38G /swap/swapfile
sudo chmod 600 /swap/swapfile
sudo mkswap /swap/swapfile# Enable the swap file
sudo swapon /swap/swapfile
# Add to fstab for automatic mounting at boot
echo '/swap/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab
# Verify swap is active
swapon --showYou need two values for GRUB configuration:
# Get the UUID of your root partition
sudo findmnt -no UUID -T /swap/swapfile
# Get the physical offset of the swap file
sudo btrfs inspect-internal map-swapfile -r /swap/swapfileWrite down both values - you'll need them in the next step.
# Edit GRUB configuration
sudo vim /etc/default/grubFind the line starting with GRUB_CMDLINE_LINUX_DEFAULT and add the resume parameters (replace with your actual UUID and offset):
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=your-uuid-here resume_offset=your-offset-here"
Example:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=12345678-1234-1234-1234-123456789abc resume_offset=123456"
Regenerate GRUB configuration:
sudo grub-mkconfig -o /boot/grub/grub.cfg# Edit mkinitcpio configuration
sudo vim /etc/mkinitcpio.confFind the HOOKS line and add sd-resume before filesystems. Your HOOKS line should look like:
HOOKS=(base systemd autodetect microcode kms modconf block keyboard sd-vconsole plymouth sd-resume filesystems)
Regenerate initramfs:
sudo mkinitcpio -PCreate systemd sleep configuration to set the 2-hour delay:
sudo vim /etc/systemd/sleep.confAdd these lines:
[Sleep]
HibernateDelaySec=2h# Edit logind configuration
sudo vim /etc/systemd/logind.confFind and uncomment (remove #) these lines, or add them if they don't exist:
HandleLidSwitch=suspend-then-hibernate
HandleLidSwitchExternalPower=suspend-then-hibernate# Restart logind service
sudo systemctl restart systemd-logind
# Reboot to apply all changes
sudo rebootAfter rebooting, verify everything works:
# Verify resume parameters are loaded
cat /proc/cmdline | grep resume
# Check swap is active
swapon --show
# Test hibernation manually
sudo systemctl hibernateAfter confirming hibernation works, test suspend-then-hibernate:
sudo systemctl suspend-then-hibernateFinally, test by closing your laptop lid and leaving it for 2+ hours.
journalctl -b -u systemd-suspend-then-hibernate
journalctl -b | grep -i hibernatecat /proc/cmdlineShould show resume=UUID=... and resume_offset=...
cat /proc/swapsYour zram and swap file should both be listed.
- zram compatibility: Your existing zram will continue working. The kernel uses zram for regular swapping and the swap file specifically for hibernation.
- Battery drain: During the first 2 hours, the system uses suspend-to-RAM (very low power). After 2 hours, it hibernates to disk (zero power).
- Wake behavior: Opening the lid before 2 hours wakes instantly from RAM. After 2 hours, it resumes from disk (slightly slower but still quick).
If you need to undo this setup:
# Disable swap file
sudo swapoff /swap/swapfile
# Remove from fstab
sudo vim /etc/fstab # Delete the /swap/swapfile line
# Remove swap file
sudo rm /swap/swapfile
# Restore logind settings
sudo vim /etc/systemd/logind.conf # Change back to suspend
# Remove sleep configuration
sudo rm /etc/systemd/sleep.conf
# Remove resume from GRUB
sudo vim /etc/default/grub # Remove resume parameters
sudo grub-mkconfig -o /boot/grub/grub.cfg
# Remove sd-resume hook
sudo vim /etc/mkinitcpio.conf # Remove sd-resume
sudo mkinitcpio -P
# Reboot
sudo reboot