This script is provided AS-IS with NO WARRANTY.
Use it entirely at your own risk. The author is not responsible for data loss, misconfiguration, or system failure.
Make sure to review and understand the code before running it on your system.
Fully automated, Btrfs-friendly swapfile creation with hibernation support — built for CachyOS and other Arch-based Linux distros.
- 📁 Creates a CoW-safe Btrfs swapfile
- ⚙️ Appends proper config to
/etc/fstab - 🧠 Calculates
resume_offsetusingfilefrag - 🧬 Injects kernel
resume=andresume_offset=parameters into GRUB - 🔁 Regenerates GRUB config for UEFI boot
- 💬 Friendly CLI output with confirmations and backups
curl -LO https://raw.githubusercontent.com/yourusername/btrfs-hibernate-arch/main/setup-btrfs-swap.sh
chmod +x setup-btrfs-swap.shsudo ./setup-btrfs-swap.shMake sure your system matches:
| Requirement | Must Be |
|---|---|
| Root Filesystem | Btrfs |
| Bootloader | GRUB (UEFI) |
| Kernel Hook | resume present in initramfs (mkinitcpio/dracut) |
| System | Arch-based (CachyOS, Arch, EndeavourOS, etc.) |
| Init System | systemd |
✅ Recommended to back up
/etc/fstaband/etc/default/grubbefore proceeding.
After reboot:
systemctl hibernateIf it works, your system should fully power off and resume the session after powering back on.
-
Did not resume? Check:
resumehook is present in/etc/mkinitcpio.confor/etc/dracut.conf- You rebuilt initramfs after adding
resume(mkinitcpio -Pordracut -f) filefraggave correct offset- Secure Boot isn't blocking resume
Read the full blog post: 👉 Setting up a Btrfs-Compatible Swap File with Hibernation on CachyOS
- 💬 Found a bug? Open an issue.
- 🔧 Want to add support for systemd-boot or non-GRUB setups? PRs welcome!
- 🧪 Tested on a weird setup? Add to the compatibility list!