Why would you want to do this automatically when doing it manually is straightforward enough? The simple answer is that an automated process makes it a lot easier to use multiple operating systems. If you test software on multiple operating system platforms, for example, this ability is especially useful.
These instructions assume that you have the operating systems already installed and multiple booting using GRUB already configured. GRUB, the GRand Unified Bootloader, loads and transfers control to OS kernel software when a machine starts up. For help deploying GRUB, see the Resources section later in this article.
The instructions in this article work with:
- Microsoft® Windows XP Professional
- Microsoft Windows Server 2003
- Debian Linux 3.1 (Sarge)
- Red Hat Enterprise Server (RHES) 3
- GRUB 0.97; success if not guaranteed with other bootloaders
Step 1. Set up disk partitions
Before starting to configure your system, make sure that you have an up-to-date system backup and a rescue CD handy. If something goes wrong with these steps, your machine will fail to boot. Do not proceed with these instructions if you find that risk unacceptable.
Create the Bootcontrol partition
Create a small partition on one of the hard drives. This partition must have a filesystem that can be both mounted and written to by all the operating systems you want to switch between. We chose FAT32. Even though the entire Bootcontrol system requires less than 1MB of disk space, FAT32 has a default minimum limit of 256MB, so some space is wasted.
If you do not have sufficient unallocated disk space, you can create space by shrinking or deleting some existing volumes. Do this in Linux using the GNU parted
command. If the ordering of existing partitions changes as a result of parted
operations, you may need to update the /etc/fstab file. Check the parted
documentation for more information.
When we used parted
to create the necessary partitions on our test machine, we got the results shown in Listing 1:
Listing 1. Creating the necessary partitions
repton:~# cat /etc/fstab # /etc/fstab: static file system information. # proc /proc proc defaults 0 0 /dev/hda2 / ext3 defaults 0 1 /dev/hda6 /home ext3 defaults 0 2 /dev/hda7 /opt ext3 defaults 0 2 /dev/hda5 none swap sw 0 0 /dev/hdc /media/cdrom0 iso9660 ro,user,noauto 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0 repton:~# umount /home repton:~# parted Using /dev/hda (parted) print Disk geometry for /dev/hda: 0.000-57231.562 megabytes Disk label type: msdos Minor Start End Type Filesystem Flags 1 0.031 18412.734 primary ntfs boot 2 18418.271 25085.874 primary ext3 3 25085.874 57231.562 extended 5 25085.905 26458.615 logical linux-swap 6 26458.646 49999.174 logical ext3 7 49999.206 57231.562 logical ext3 (parted) resize 6 26458 49739 (parted) mkpartfs logical fat32 49739 49999 (parted) print Disk geometry for /dev/hda: 0.000-57231.562 megabytes Disk label type: msdos Minor Start End Type Filesystem Flags 1 0.031 18412.734 primary ntfs boot 2 18418.271 25085.874 primary ext3 3 25085.874 57231.562 extended 5 25085.905 26458.615 logical linux-swap 6 26458.646 49740.314 logical ext3 8 49740.346 49999.174 logical fat32 7 49999.206 57231.562 logical ext3 (parted) q repton:~# mount /home
|
Mount the Linux partition
Once you have created the space for the control partition, mount it so that you can see it from Linux. In our case, we added the following to /etc/fstab:
#
/dev/hda8 /boot/control vfat umask=022,dmask=022,fmask=022 0 2
Then create the mountpoint and mount the filesystem with:
mkdir /boot/control
mount /boot/control
You also need to update the information that GRUB maintains on the partition structure. On our test systems, we used grub-install /dev/hda
.
Mount the Windows partition
Verify that the previous partition editing step did not break the Windows boot by rebooting (manually) to Windows. Then assign a drive letter to the Bootcontrol volume you just created. On modern versions of Windows, use the Computer Management MMC snap-in (right-click My Computer and select Manage. On older releases, select Start > Administrative Tools.
Figure 1 shows how we assigned the letter W: to our Bootcontrol partition.
Figure 1. Assigning a Windows drive letter to the Bootcontrol partition
Step 2. Redirect the GRUB boot menu
Place the GRUB config file /boot/grub/menu.lst into the Bootcontrol partition where both Windows and Linux can write to it. This lets you change the default boot setting from a script run under either operating system. By default, GRUB does not look in that location for a config file, so you must add a small hack to the file in the original location.
Print a hardcopy of the original file. If GRUB fails to load, you can manually type in the commands required to boot your system. See the GRUB info pages for more information.
On our example system, we first copied the file: cp /boot/grub/menu.lst /boot/control/menu.lst
, then we added the following stanza (see Listing 2) to the original /boot/grub/menu.lst, placing it in front of the existing boot choices.
Listing 2. Giving access to boot file from either operating system
title BOOTCONTROL REDIRECT : PLEASE WAIT root (hd0,7) configfile /menu.lst boot
|
Ensure that the parameter of the root
command is correct for your system. As a rough guide, drives are numbered from 0 (rather than a-z), and partitions also start at 0 (rather than 1). Therefore, for our example, /dev/hda8 becomes (hd0,7). We removed the savedefault
command from all the other stanzas and updated the following settings to ensure the Bootcontrol selection is chosen after 10 seconds. Find more information in the GRUB documentation.
default 0
timeout 10
Now that you've redirected the GRUB configuration, check that the system reboots and that the menu is still displayed correctly.
The most common error at this point in incorrectly identified partitions. Verify that the partition number ("Minor") in parted
matches /etc/fstab and that GRUB uses that number minus one in /boot/grub/menu.lst.
Step 3. Configure Bootcontrol
Download the zip file from the Downloads section below, and unpack it into the Bootcontrol partition. The zip file contains a Perl script to handle switching operating systems in a general fashion, as well as some sample scripts for switching between Windows and Linux. These scripts expect the current working directory to be set to the Bootcontrol partition.
Usage script
This is the usage script:
bootcontrol.pl
The grub-config-file
parameter is the path to the config file to be edited. Generally you should modify menu.lst, but you may want to test that the changes are as you expect by using a copy of your menu.lst file with a new name.
The platform-title
parameter is used as a substring (technically a regular expression) to match against the title field in /boot/control/menu.lst. It is case insensitive, and bootcontrol.pl
selects the first matching instance. If a number is specified for platform-title
, it is treated as the menu option to boot (not a platform to match against). The first entry in the menu file is zero.
Helper scripts
Accompanying bootcontrol.pl
are two small scripts, provided as templates, that streamline the process between Windows and Linux. In either operating system, type to_linux.pl
or to_windows.pl
. These scripts do not reboot unless required, but they always update the GRUB default setting.
Step 4. Maintain the system
Changes or updates to any of the installed operating systems may affect the settings used by Bootcontrol, so check the rebooting capability after any update that affects either GRUB or the Linux kernel. These changes can alter /boot/grub/menu.lst without changing /boot/control/menu.lst.