John Hawthorn

Hibernate with reboot on Linux

For the occasional reboot to Windows, I found I was wasting a lot of time saving my work, closing my programs, rebooting, and then later reopening everything again. I’ve started using suspend to disk AKA hibernate, which allowed me to switch to Windows, while saving my running programs and setup under Linux.

I then searched to remove the task of powering on the computer after it has suspended and then picking Windows from the Grub boot menu, which I often forgot to do.

Setting the selected operating system under grub is relatively straightforward using the grub-set-default command.

#/boot/grub/menu.lst

# change the default boot option to saved
default   saved

# (0) Linux
title  Linux
# ...
# add savedefault 0 to the end of each boot option, which sets the default back to Linux
savedefault 0

# (1) Windows
title  Linux
# ...
savedefault 0

The next step was automatically rebooting which was accomplished using the sparsely documented shutdown method = reboot option of s2disk

My final windows reboot script is

#!/bin/sh sudo grub-set-default 2 # here '2' is whichever option is Windows sudo s2disk -P 'shutdown method = reboot'

Which takes me from Linux to Windows, and back to my saved workspace on reboot.