DEV Community

ADEBI Châ-Fine Ayédoun
ADEBI Châ-Fine Ayédoun

Posted on

🚀 Hibernate Like a Boss on Arch/EndeavourOS with Dracut + Swapfile

💡 Because sometimes you just wanna close the lid, go make noodles, and come back like nothing happened.


1️⃣ Check your RAM & plan the swap

Hibernation stores all your RAM into the swap.
Rule: swap size ≥ RAM × 1.2 (just to be safe).

Mine:

free -h
Enter fullscreen mode Exit fullscreen mode
Mem:  7.6G total
Enter fullscreen mode Exit fullscreen mode

👉 I’ll make a 9G swapfile.


2️⃣ Create the swapfile

Let’s make it, lock it, and enable it:

sudo fallocate -l 9G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Enter fullscreen mode Exit fullscreen mode

3️⃣ Make it permanent in /etc/fstab

echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab
Enter fullscreen mode Exit fullscreen mode

No more "oops my swap disappeared after reboot".


4️⃣ Grab the UUID and offset

The kernel needs to know where your swap lives:

# UUID of the partition containing swapfile
findmnt -no UUID -T /swapfile

# Offset of the swapfile
filefrag -v /swapfile | awk '{if($1=="0:"){print $4}}' | sed 's/\.\.//'
Enter fullscreen mode Exit fullscreen mode

Write those down — we’ll need them in the GRUB step.


5️⃣ Tell GRUB about it

Edit /etc/default/grub:

sudo nano /etc/default/grub
Enter fullscreen mode Exit fullscreen mode

Find:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Enter fullscreen mode Exit fullscreen mode

Change to:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash resume=UUID=<your_uuid_here> resume_offset=<your_offset_here>"
Enter fullscreen mode Exit fullscreen mode

Update GRUB:

sudo grub-mkconfig -o /boot/grub/grub.cfg
Enter fullscreen mode Exit fullscreen mode

6️⃣ Teach Dracut to resume

Create /etc/dracut.conf.d/resume.conf:

echo 'add_dracutmodules+=" resume "' | sudo tee /etc/dracut.conf.d/resume.conf
Enter fullscreen mode Exit fullscreen mode

Rebuild initramfs:

sudo dracut --regenerate-all --force
Enter fullscreen mode Exit fullscreen mode

7️⃣ Test the magic ✨

sudo systemctl hibernate
Enter fullscreen mode Exit fullscreen mode

If your PC powers off and comes back with everything exactly where you left it,
congratulations — you’re now a hibernation wizard 🧙‍♂️.


🔥 Bonus: Suspend-then-Hibernate

Suspend to RAM first, then hibernate after a delay (battery saver’s dream):

sudo mkdir -p /etc/systemd/sleep.conf.d
sudo nano /etc/systemd/sleep.conf.d/hibernate.conf
Enter fullscreen mode Exit fullscreen mode

Put:

[Sleep]
HibernateDelaySec=30min
Enter fullscreen mode Exit fullscreen mode

Run:

sudo systemctl suspend-then-hibernate
Enter fullscreen mode Exit fullscreen mode

🏆 Done!

Now your Arch/EndeavourOS box can sleep like a cat 🐈 and wake up like it’s got super memory powers.

Top comments (0)