if you have the ability approximately 98% of all humans (10 and older) (according to a very true source made by.... me!) and that is the ability to use your eyes to inform the gist title to yourself, you use zram and want to use hibernation
You need to put the resume
module in your initramfs
mkinitcpio:
- Edit
/etc/mkinitcpio.conf
- Find HOOKS= and place
resume
in betweenblock
andfilesystems
- 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 -f
After 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.)
why do I keep saying swap ITS A SWAPFILE
ok ANYWAY.
If you use btrfs, I found this tutorial for you. However I don't use btrfs so lets continue.
We will call this swapfile swapfile.hibernationonly
but feel free to name it your own. Anyways lets continue
$ sudo dd if=/dev/zero of=/swapfile.hibernationonly bs=1G count=[YOUR RAM SIZE]
- Replace [YOUR RAM SIZE] with your ram size.
- For some reason
dd
doesnt work and you have to manually interruptdd
as soon as it hits your ram size (usels -lh
) After that do
$ sudo fallocate --length [HALF RAM] /swapfile.hibernationonly
- Replace [HALF RAM] with half your ram
- You might not need to put half your ram. I put half my ram but go do whatever make the swap...
$ sudo chmod 600 /swapfile.hibernationonly
$ sudo mkswap /swapfile.hibernationonly
I was planning to use a fstab to activate the swapfile but systemd didn't like setting a priority and set it higher then my zram (I don't use zram-generator since it only allowed me to use 512 mb of zram, I use a script I made and a systemd unit). Setting a higher priority causes Linux to stay on that swap with the priority
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_CMDLINE
line 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