2010/09/03

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:
GRUB_DEFAULT=0
GRUB_TIMEOUT=5

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
============================
#!/bin/bash
case $1 in
hibernate)
## 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
;;
thaw)
## 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
;;
esac
=====================================
sudo chmod +x /etc/pm/sleep.d/00doit
Enhanced by Zemanta