Skip to content

9M2PJU/Btrfs-Compatible-Swapfile-Hibernation-Script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation


⚠️ Disclaimer


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.

🧊 Btrfs Swapfile + Hibernation Setup Script for Arch-based Systems

bash arch btrfs license

Fully automated, Btrfs-friendly swapfile creation with hibernation support — built for CachyOS and other Arch-based Linux distros.

⚡ What It Does

  • 📁 Creates a CoW-safe Btrfs swapfile
  • ⚙️ Appends proper config to /etc/fstab
  • 🧠 Calculates resume_offset using filefrag
  • 🧬 Injects kernel resume= and resume_offset= parameters into GRUB
  • 🔁 Regenerates GRUB config for UEFI boot
  • 💬 Friendly CLI output with confirmations and backups

🚀 Quick Start

1. Download

curl -LO https://raw.githubusercontent.com/yourusername/btrfs-hibernate-arch/main/setup-btrfs-swap.sh
chmod +x setup-btrfs-swap.sh

2. Run (as root)

sudo ./setup-btrfs-swap.sh

🧷 Pre-Flight Checklist

Make 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/fstab and /etc/default/grub before proceeding.


🧪 Testing

After reboot:

systemctl hibernate

If it works, your system should fully power off and resume the session after powering back on.


🛠 Troubleshooting

  • Did not resume? Check:

    • resume hook is present in /etc/mkinitcpio.conf or /etc/dracut.conf
    • You rebuilt initramfs after adding resume (mkinitcpio -P or dracut -f)
    • filefrag gave correct offset
    • Secure Boot isn't blocking resume

📚 More Info

Read the full blog post: 👉 Setting up a Btrfs-Compatible Swap File with Hibernation on CachyOS


🤝 Contribute

  • 💬 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!

About

Tested on CachyOS / Arch-based Linux

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages