Making Dual-Booting More Livable

Six years ago this month Linux became my primary operating system; it happened almost overnight. The startup company I had been working for imploded. I was at home, working on my resume, when my Windows PC crashed for the umpteenth time. I knew a bit of Unix (when I first started using the Internet, my only means of access was a Unix shell account) and was not at all intimidated by the idea of installing something Unix-y on my PC. I took the plunge and never looked back.

My main box has been a dual-booter for six years now. When it powers up, the first screen following the BIOS message asks me to choose between Linux and Windows. If there is no response after thirty seconds, Linux is chosen by default, and a short while later, Linux has booted and is waiting for me.

But the way the boot process works presents a problem when I want to play Myst IV: Revelation and go to bed four hours late. When it's Myst time, I tell Linux to reboot. I wait for it to shut down. The system restarts. I wait for the boot loader screen. I select Windows. Then I wait for Windows to boot. I have to do all this sitting and waiting because I have to be present at that key moment when I have to select Windows instead of Linux. But I'd really rather be fetching a tasty beverage from the fridge.

What I need is one button on my Linux desktop that starts the reboot-with-Windows process and needs no further action from me until Windows is up and running. Sound useful? Let me show you the magic spell.

Hacking Your Boot Loader

On most Linux boxes, the boot loader is a tiny bit of code called LILO (for LInux LOader). You can alter LILO's behavior for its next boot very simply, using its -R command-line option. For instance, on my Mandrake box, the following command tells the system to boot into Windows next time without any additional prompting:

lilo -R windows

That command must be issued when you're logged in as the root user.

It's only a couple more steps to write a shell script that fires off that command and also causes the machine to reboot. First, open your text editor of choice. If you don't have a favorite editor, press Alt-F2 and enter gedit if you're a Gnome user, kedit if you're a KDE user. Now, create a text file called "bootwin" and put these lines in it:

/sbin/lilo -R windows

Now, back on the command line, make bootwin executable with the following command:

chmod u+x bootwin

If you're logged in as root, issuing ./bootwin will run the script. The problem is, only the root user can tell the boot loader to do something different on the next boot, so when you are logged in with your normal user account, the bootwin script will conk out. (On my Mandrake box, the LILO command fails but the reboot command succeeds, so the machine reboots into Linux. Nuts.)

The solution is to somehow make your script run as a root user. There are many ways to do this. Here's one:
su -c ./bootwin

You'll be prompted for the root password, and then the script will execute as if the root user (or the "superuser"--hence "su") launched it. Even better, if you have the sudo command installed and configured on your box, you can simply issue:
sudo bootwin

With the proper sudo setup, you won't even be prompted for a password. Bootwin will simply run with root privileges, despite the fact that an ordinary user launched it.

Fine-Tuning Your Script

There are three potential problems with the bootwin script at this stage. First, our LILO command assumes that your Windows partition is named "windows" in LILO's configuration. That might not be the case. To find out what LILO calls your Windows partition, enter this command as root to reveal LILO's configuration file:
cat /etc/lilo.conf

You're looking for two lines that look something like this: other=/dev/hda1

In this case, LILO thinks my Windows partition is called "dos," so I need to replace "windows" with "dos" in my bootwin script. Easy enough. A second potential problem is that in your particular flavor of Linux the LILO and reboot commands may live elsewhere than at the paths in the script. As root, you can use which lilo and which reboot to find out the full path to these commands. If you find, for instance, that on your system reboot lives under /sbin instead of /usr/bin, then alter the final line of bootwin to point at /sbin/reboot instead of /usr/bin/reboot.

When Things Get Grubby

Now then, there's one more potential problem, and it's a doozy. It could be that your Linux box isn't booting with LILO. There's another popular boot loader called GRUB (for GRand Unified Bootloader). It lurks, for example, on my box that runs Fedora Core. I've long been convinced that it was impossible to craft a bootwin script on a machine with GRUB, because GRUB has no equivalent to the LILO command-line option for automating the next boot choice.

But when Myst IV arrived (is my obsession clear yet?), I decided to give it a shot again. To make a long story short, there was nothing out there on the Web (at least, nothing that Google turned up) about how to make this magic happen. So I'm going to change that right now. Here's a version of bootwin that works on my Fedora Core system, where GRUB is the boot loader:

/sbin/grub --device-map=/boot/grub/ --batch <<FOO
savedefault --default=3 --once

Similar caveats apply here as before: The GRUB and reboot commands may live in different directories on your machine. The script needs to run as root. And you'll need to check to see where your Windows partition is referenced in the file /etc/grub.conf. Issuing the following command as root will yield the contents of that file:

cat /etc/grub.conf

You're looking for an entry that looks like this:

title Windows 2000 SP4
rootnoverify (hd0,0)
chainloader +1

In my grub.conf, this was the fourth entry. GRUB counts entries starting with zero, so the first entry is 0, the second entry is 1, and this, my fourth entry, is 3. That's why there's a 3 on the "savedefault" line in my bootwin script. You'll need to change that digit to match the number for your own Windows partition entry.

If you've stuck with me this long, then you've got a script that will reboot your system into Windows. Now, how to make the script easy to access? Why not add a button to your system panel? In Gnome 2.6, right-click the panel and select Add to Panel, Launcher. In KDE 3.2, right-click the panel and select Add, Special Button, Non-KDE Application. Gnome users, look to the "Command" field; KDE users, find the "Execute" field. Enter the following command there, replacing "/path/to" with the full path of the directory where you've put your bootwin script:

su -c /path/to/bootwin

In both Gnome and KDE, select an icon for your button and be sure to select the "Run in terminal" check box before closing the dialog box. Voila!

If a button doesn't interest you, you can instead move the script to a directory in your command path (/usr/local/bin is one good possibility) so that you can press Alt-F2 (in either Gnome or KDE), type bootwin, and be off to the races. (Or, in my case, to the Myst IV realms of Tomahna, Serenia, Spire, and Haven.)

About to Switch to Ubuntu?

The Community release of Mandrake 10.1 has been out for about a month. Mandrake Community releases are roughly akin to an open beta: The idea is that by spreading the Community release far and wide, Mandrake can supplement its own QA efforts and shake out any obscure (or not-so-obscure) bugs turned up by a wide user base before a new version gets pressed to CD.

I hope that there's a good deal of difference between the Community release of Mandrake 10.1 and the forthcoming Official release: The Community release has given my trusty IBM Thinkpad (which ran 10.0 without issues) nothing but trouble. It's been so frustrating, I'm considering replacing it with a brand new flavor of Linux.

Ubuntu Linux is a new distribution out of Britain. It's based on Debian, pledges to always offer a cost-free version (as does Mandrake), and is the first distribution to sport the Gnome 2.8 desktop environment. Yes, folks, this may in fact be the user-friendly, Gnome-based distribution I've been hunting for so long. I've got a prerelease version of Ubuntu running on a test machine here at PC World HQ, and it's awfully slick.

The only thing that gives me pause is Ubuntu's inability to play or encode MP3 files. Fedora Core has the same problem, as I've mentioned before, and I hate having to muck around under the hood just to enable support for such a popular file format. I've been using Fedora since last spring, and I still can't get MP3 previewing to work in Nautilus, the Gnome file manager. (In Nautilus, when you hover your cursor over an MP3 file, it's supposed to start playing and continue until you move the cursor again.) That's nonsense, and I don't want to be stuck in the same boat with Ubuntu. So once again, I'm looking for solutions. Stay tuned.

Join the newsletter!


Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Matthew Newton

PC World
Show Comments

Cool Tech

Toys for Boys

Family Friendly

Stocking Stuffer

SmartLens - Clip on Phone Camera Lens Set of 3

Learn more >

Christmas Gift Guide

Click for more ›

Brand Post

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Aysha Strobbe

Microsoft Office 365/HP Spectre x360

Microsoft Office continues to make a student’s life that little bit easier by offering reliable, easy to use, time-saving functionality, while continuing to develop new features that further enhance what is already a formidable collection of applications

Michael Hargreaves

Microsoft Office 365/Dell XPS 15 2-in-1

I’d recommend a Dell XPS 15 2-in-1 and the new Windows 10 to anyone who needs to get serious work done (before you kick back on your couch with your favourite Netflix show.)

Maryellen Rose George

Brother PT-P750W

It’s useful for office tasks as well as pragmatic labelling of equipment and storage – just don’t get too excited and label everything in sight!

Cathy Giles

Brother MFC-L8900CDW

The Brother MFC-L8900CDW is an absolute stand out. I struggle to fault it.

Luke Hill


I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?