Thursday, June 19, 2008

Dual Booting with Wake On Lan

I don't usually talk about technical stuff here, but I'm going to take a little break from gushing about my kids to explain part of how I solved my problem of too many pictures. To quickly summarize, I found that my digital picture library was too large to continue storing on my laptop, and even if I upgraded the hard drive in my laptop to a 320 GB or possibly a 500 GB drive, I would just be delaying the inevitable as my library is growing very rapidly. The crux of the problem is that only one hard drive will fit in my macbook pro (I have the 15" model which doesn't support this crazy option, even if I wanted to).

To solve this problem, I am now storing all of my original photos on a desktop computer running Windows. This computer has multiple hard drives and provides plenty of space for my pictures. I use Lightroom on my laptop, which is smart enough to only store reasonably small previews of all my photos, drastically reducing the amount of space required on my laptop.

This setup works fine when both machines are up and running, but I usually keep my desktop turned off to conserve energy. I often find myself in a situation where I am in another room and don't feel like walking down the hall to turn on the desktop, just so I can import photos from my camera. Wouldn't it be nice if I could remotely boot my desktop and import my photos without getting off the couch?

It turns out I can. I poked around in my BIOS settings and enabled a feature called Wake-on-Lan. Then I installed a Wake-on-Lan Dashboard widget on my laptop. Now I can boot my desktop from another room at any time with 2 simple clicks.

This worked well for a while until I decided to install Ubuntu on that same desktop and dual boot between that and Windows. Now things are a little trickier, because sometimes I will want to remotely boot into Windows, but other times I might want to remotely boot into Linux. Unfortunately, Wake-on-Lan doesn't have the capability to choose an OS when the computer turns on.

The solution I came up with (read: found on the Internet) was to use Wake-on-Lan to boot the computer and let Grub boot into whichever OS is set to default, then use a shell script to change the default OS to one of my choosing, then reboot the machine. It's a few more steps than I'd like, but it sure beats getting off the couch!

Here's everything you need to get it working yourself.

Requirements:

  1. Grub bootloader. This solution could be adapted to work with other bootloaders, but right now it only works with Grub.

  2. Ext2 IFS. Allows your Windows partition to access your Linux file system.

To get started, create two copies of /boot/grub/menu.lst in Linux. Name one menu.lst.win, and the other menu.lst.lin. Then edit each one to boot into the corresponding OS (Windows for menu.lst.win, Linux for menu.lst.lin). You will probably only have to change one line like:
default  0
to something like:
default  4
But there are instructions for doing this out on the web if you need help.

Once you've done that, create a file named grubEdit.sh with the following.

grubEdit.sh
usage="Usage: grubEdit [win | lin]"
grubHome="/boot/grub"
menuLst="/boot/grub/menu.lst"
menuLstWin="/boot/grub/menu.lst.win"
menuLstLin="/boot/grub/menu.lst.lin"

if [ $# -ne 1 ]
then
echo $usage
exit 1
fi

if [ $1 = "win" ]
then
rm -f $menuLst
cp $menuLstWin $menuLst
else
if [ $1 = "lin" ]
then
rm -f $menuLst
cp $menuLstLin $menuLst
else
echo $usage
fi
fi



Now boot back into Windows and create a file named grubEdit.bat, and copy in the following.
Disclaimer: I think this is the first time I've used goto's in a real script. I don't write many shell scripts, but I think this is how it has to be done.

grubEdit.bat
@echo off
set grubHome=L:\boot\grub
set menuLst=%grubHome%\menu.lst
set menuLstWin=%grubHome%\menu.lst.win
set menuLstLin=%grubHome%\menu.lst.lin

if "%1" == "win" goto win
if "%1" == "lin" goto lin
goto error

:win
del %menuLst%
copy %menuLstWin% %menuLst%
goto end

:lin
del %menuLst%
copy %menuLstLin% %menuLst%
goto end

:error
echo Usage: grubEdit [win ^| lin]
goto end

:end


Now from either OS, just run:
grubEdit win
to boot into Windows, and
grubEdit lin
to boot into Linux.

It's that easy!

(Note that you'll need to prepend sudo to either command on Linux, and I've left out instructions for editing your PATH to make sure the shell can find your new scripts.)

No comments:

Post a Comment