Auto Resume Linux From Hibernation in Multi-Boot System

I wanted my system to resume my hibernated Linux session right away skipping GRUB menu and without having the chance to boot into Windows in case I forget about the hibernated Linux session, because in that case, booting into Windows would had eventually caused some file system corruption and data loss in the NTFS partition I share between both OSs.
Since the options in the GRUB section in /etc/hibernate/common.conf do not work in my system (Linux Mint 9) I set up the following workaround.
Set the following variables in /etc/default/grub:

Update grub menu: sudo update-grub

Create a script that changes values in grub menu configuration before hibernation and after resuming from hibernation.
gksudo gedit /etc/pm/sleep.d/00doit
case $1 in
## Set Grub menu to resume automatically:
# Boots default right away showing no menu
sed 's/timeout=5/timeout=0/g' /boot/grub/grub.cfg > /boot/grub/grub.cfg2
# Switch default to Linux
sed 's/default="0"/default="1"/g' /boot/grub/grub.cfg2 > /boot/grub/grub.cfg3
rm /boot/grub/grub.cfg2
mv /boot/grub/grub.cfg3 /boot/grub/grub.cfg
## Restore normal Grub menu options:
# Restores presentation of grub menu
sed 's/timeout=0/timeout=5/g' /boot/grub/grub.cfg > /boot/grub/grub.cfg2
# Restores Windows as default entry
sed 's/default="1"/default="0"/g' /boot/grub/grub.cfg2 > /boot/grub/grub.cfg3
rm /boot/grub/grub.cfg2
mv /boot/grub/grub.cfg3 /boot/grub/grub.cfg
sudo chmod +x /etc/pm/sleep.d/00doit
Enhanced by Zemanta