Linux GRUB2: How to resume from hibernation?

Moving to GRUB2 my Arch Linux no longer resumes from hibernation, because the actual resuming is no longer set up. In GRUB legacy I'd write:

/boot/grub/menu.lst:

kernel /vmlinuz26 root=/dev/disk/by-uuid/X ro resume=/dev/disk/by-uuid/Y ro

But with GRUB2's new way of handling the boot menu, I no longer know how, where and in which form to add this. My guess is you'd add the entire menuentry to /etc/grub.d/40_custom/ and somehow set up the resuming there? Manually hardcoding menuentries into GRUB2 seems to go against its flexible menu generation approach, but whatever reenables me to use hibernate is gladly welcomed.

Thanks!


Solution 1:

Open up /etc/default/grub with root privledges and add GRUB_CMDLINE_LINUX="resume=/dev/sdXY" Where XY is the swap partition location, which can be found by sudo fdisk -l. It looks like you are using UUID instead and that's fine. /etc/default/grub only affects the current operating system so don't worry about every linux OS using grub to start using that swap. After finishing your edits, run sudo grub-mkconfig -o /boot/grub/grub.cfg (substitute grub.cfg with whatever file grub reads at boot, e.g. it may be named /boot/grub/grub.efi) to update your grub startup information with what you changed in /etc/default/grub

(I don't think this needs to be done on Ubuntu)
Note that one may need to add a resume hook to make sure the kernel knows that it should resume if Archlinux or perhaps another OS is being used. To do this, if one is using mkinitcpio, go to /etc/mkinitcpio.conf and insert resume in the HOOKS array before filesystems but after ide, scsi, and sata. Then, you you need to rebuild the initial ramdisk(early OS state for loading modules, including resume) image by mkinitcpio -p linux

Other links that may help
https://askubuntu.com/questions/6769/hibernate-to-a-swap-file
https://wiki.archlinux.org/index.php/Pm-utils#Mkinitcpio_Resume_Hook