You need to put the resume module in your initramfs
mkinitcpio:
- Edit
/etc/mkinitcpio.conf - Find HOOKS= and place
resumein betweenblockandfilesystems - Regenerate initramfs using
sudo mkinitcpio -P
dracut (most distros):
- Create a file named
/etc/dracut.conf.d/resume.conf - Put the content
add_dracutmodules+=" resume "in the file - Regenerate initramfs using
sudo dracut -fAfter that reboot the system
i use zram because currently I unfortunately use a HDD and have only 4 GB of ram. You definitely have better specs, but I don't :(
anyway we will need to use a swapfile as zram does not support hibernation (Swap and swapfiles are stored on disk, however zram is stored on memory. Hibernating on zram sounds exactly like sleeping, but linux has zram as its frenemy. The system will crash and reboot if you use hibernation on zram. Period.)
If you use btrfs, I found this tutorial for you.
you can call this swapfile anything but I'll call it swapfile.hibernationonly but feel free to name it your own
$ sudo dd if=/dev/zero of=/swapfile.hibernationonly bs=1G count=[YOUR RAM SIZE]
- Replace [YOUR RAM SIZE] with your ram size.
- Replace /swapfile.hibernationonly with your swapfile name
$ sudo fallocate --length [HALF RAM] /swapfile.hibernationonly
- Replace [HALF RAM] with half your ram
$ sudo chmod 600 /swapfile.hibernationonly
$ sudo mkswap /swapfile.hibernationonly
You can use a fstab but I use a script and systemd
To turn on the swapfile AFTER zram (for those who use zram-generator) use the systemd unit provided at the top of the page, download it and place it in /etc/systemd/system
Thats it ig
You need to update the command line.
the UUID is basically the same as your root partition UUID, you can use PARTUUID as well
To get the resume-offset run:
$ sudo filefrag -v /swapfile.hibernationonly | awk '{if($1=="0:"){print $4}}' | sed 's/\.\.//'\n
GRUB:
- Edit
/etc/default/grub - at the
GRUB_DEFAULT_CMDLINEline add this to the quotation marksresume=UUID/PARTUUID=[YOUR (PART)UUID HERE] resume-offset=[resume-offset you got earlier]- UUID/PARTUUID - whether you chose UUID or PARTUUID put your choiceb= there
- [YOUR (PART)UUID HERE] - your root partition UUID or PARTUUID
- [resume-offset you got earlier] - The resume-offset you got earlier in the tutorial UKI:
- Edit
/etc/kernel/cmdline - Pretty much like GRUB except you don't add the command line parameters to the GRUB_DEFAULT_CMDLINE, you add it to the file For any other bootloader refer to your braincells for changing the command line
After rebooting, run the command:
$ (sudo) systemctl hibernate
- (sudo) - Some distros require root privileges for hibernation, use sudo if it does