?

Log in

No account? Create an account
Mar. 14th, 2010 @ 05:02 pm Headless multi-boot with Ubuntu and Windows with Grub2
Current Mood: awakeawake
Tags:
My use case is thus:
- Sootball is running as a headless machine. There's no keyboard or monitor hooked up to it. I use Calcifer to log in remotely.
- Sootball is (again) dual-boot, running both Ubuntu and Windows XP.
- When it's running Ubuntu, I use FreeNX. That works quite nicely.
- When it's running Windows, I use rdesktop. That works quite nicely too.
- Sootball should boot into Ubuntu per default.
- But once in a while I need WinXP. In such cases, I can't interrupt Grub (the Linux bootloader) to select that entry from the boot menu, because Sootball is headless!

So, what I want, is that I can issue a command from within Ubuntu that specifies that the machine should reboot and boot into Windows. After shutting down Windows, the next time Sootball boots, it should boot into Ubuntu again.
That is harder than it sounds. I tried to configure this earlier but then found out that that particular feature doesn't work. And I had converted to Grub2 because I had to reinstall Grub after reinstalling Windows and I didn't want to be bothered by having to download an older live CD. So here is how to do it:
- Upgrade to Grub2 on your existing installation.
- Reboot from your WinXP installation CD and repair or reinstall your installation. Do the upgrade dance, install software, etcetera.
- Restore Grub2 so that your machine will multi-boot again.
- Boot into your Ubuntu installation.
- Edit /etc/default/grub to change the line setting GRUB_DEFAULT into "GRUB_DEFAULT=saved". This will Grub record the last choice you made and boot into that the next time. Not entirely what we want, but we'll fix that later.
- Edit /etc/grub.d/30_os-prober. Find the line containing chainloader +1. Put the following two lines above tha line:
set saved_entry=0
save_env saved_entry

So, if your Windows install is chosen, the saved entry will be 0 (the most recently installed Ubuntu kernel is always first) and that will be saved. This means that when you reboot from Windows, you'll end up in Ubuntu again.
- Run update-grub to re-create your grub.cfg with your changes.
- Check /boot/grub/grub.cfg to see if it looks good; and to find the name of the entry for your Windows installation. In my case, that's "Microsoft Windows XP Professional (on /dev/sda1)".
- Add a line to your ~/.bash_aliases (or create it if it doesn't exist already) with the following line:
alias bootwin='sudo grub-reboot "Microsoft Windows XP Professional (on /dev/sda1)";sudo reboot'
This will record the entry with the given name (your Windows entry) as the last chosen entry and issue a reboot -- which will put you into Windows. But before Windows is booted, the first entry is saved as the 'saved entry' -- which will put you back into Ubuntu when you boot your machine again after closing Windows.
About this Entry
ADM3A
[User Picture Icon]
From:merle_
Date:March 14th, 2010 04:21 pm (UTC)
(Permanent Link)
Cool! I had to do something like that with LILO way back when, and my best solution was to make a separate partition for /etc so either side could modify lilo.conf (and because my primary reboot need was swapping between the two, both sides did it automatically on startup).

Needless to say, kernel upgrades required two boots without manual intervention.
(Reply) (Thread)