Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Automate OS switching on a dual-boot Linux system

Switch between Linux and Windows on the same machine without manual intervention

Marc Carter, WebSphere MQ/JMS performance specialist, IBM United Kingdom
Marc Carter is a Performance Specialist with the WebSphere MQ JMS performance team in IBM Hursley. Marc works with development in evaluating new releases of WebSphere MQ and with customers to provide consultancy on design, configuration, and tuning issues relating to this product. He has also spent many years working on internal test automation systems.
Phil Willoughby (phil.willoughby@uk.ibm.com), XMS Developer, IBM, Software Group
Phil Willoughby is part of the IBM Message Service Clients development team working on the XMS API for C & C++. He specializes in writing portable high-performance C code.

Summary:  Switch from one operating system to another -- without manual intervention -- by following these step-by-step instructions for enabling a dual-boot machine. Duplicate this setup for running both Linux® and Windows® on your own machine with the scripts provided with this article.

Date:  08 Mar 2006
Level:  Introductory
Also available in:   Russian  Japanese

Activity:  16408 views
Comments:  

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.
# <file system> <mount point> <type> <options> <dump> <pass>
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:

# <file system> <mount point> <type> <options> <dump> <pass>
/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
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 <grub-config-file> <platform-title>

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.



Download

DescriptionNameSizeDownload method
Sample scripts for this articlel-osswitch-bootcontrol.zip3KB HTTP

Information about download methods


Resources

Learn

Get products and technologies

  • GNU Parted is a package for creating, destroying, resizing, checking, and copying partitions and the filesystems on them.

  • With IBM trial software, available for download directly from developerWorks, build your next development project on Linux.

Discuss

About the authors

Marc Carter is a Performance Specialist with the WebSphere MQ JMS performance team in IBM Hursley. Marc works with development in evaluating new releases of WebSphere MQ and with customers to provide consultancy on design, configuration, and tuning issues relating to this product. He has also spent many years working on internal test automation systems.

Phil Willoughby is part of the IBM Message Service Clients development team working on the XMS API for C & C++. He specializes in writing portable high-performance C code.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux
ArticleID=105280
ArticleTitle=Automate OS switching on a dual-boot Linux system
publish-date=03082006
author1-email=mcarter@uk.ibm.com
author1-email-cc=
author2-email=phil.willoughby@uk.ibm.com
author2-email-cc=