Cover V11, I11

Article
Figure 1
Figure 2

nov2002.tar

Multi-Booting: Part II

Brian Gollsneider

In the October 2001 issue, Sys Admin published my article "Multi-Booting Windows 98, Linux, and Solaris", which covered some of the ways to make a system capable of booting several different operating systems. The point of the previous article was that some versions of operating systems (such as Red Hat 6.2 and Solaris 8 (6/00)) do not get along very well and form the worst case in multi-booting. In this article, I will update how multi-booting works with the new OS versions and show some new tricks. I will describe how a Windows 2000 system can be made to multi-boot Windows 2000, Windows 98, Solaris 8 (2/02), and Red Hat 7.3. I will also discuss Windows 2000 boot disks, grub (the newest Linux boot loader), how to save and restore the master boot record, and how to share data between these operating systems.

Multi-Booting Basics

Before trying any of the ideas presented in this article, I recommend making a complete backup of your system. I will describe ways to make some very serious changes to the system, and things can go wrong. Also, be sure to check your backup before going further.

Multi-booting involves installing and configuring multiple operating systems on one computer system so that any one system can be chosen and run at boot time. Today's hard drives provide enough elbow room to fit several operating systems onto one or more physical hard drives. Common choices for multi-booting are one or more Windows systems, a version of Solaris for x86, OS/2, and Linux. Loading the correct operating system is the job of the boot loader (e.g., lilo or the NT boot manager). Note that you only have one of the operating systems available at any particular time with multi-booting. If you need to have multiple systems available at the same time, multi-booting will not help you, and you should consider multiple computers or products like VMware or Win4lin to create logical machines.

Working with the Master Boot Record

The master boot record (MBR) provides the computer with a place to boot. It can be stored at the beginning of the hard drive itself or at the beginning of a partition. The OS installation process will make a change to the MBR so that it can be booted. Control of this MBR installation varies by OS. Linux provides a great deal of control over where and which boot loader is used, whereas Windows provides none. Windows will always write over the previous MBR and establish itself. The question then becomes "how can I capture a current MBR and restore it as necessary?" One answer is provided by Linux and the dd command. This can be used even if Linux is not installed on your computer.

To begin, boot from your Linux distribution CD-ROM. When you get the initial prompt of "boot:", type linux rescue. You'll get a couple of prompts about keyboard and other admin information. Then you will get a prompt to search for previous Linux installations. Even if you have Linux installed on your computer, you can skip the search. You will finally get a boot prompt as root. Assuming you have an IDE hard drive and a blank floppy in the computer, you can type:

dd if=/dev/hda of=/dev/fd0 bs=512 count=1
to copy the current MBR to the floppy. Store the floppy in a safe place.

To restore, do the opposite:

dd if=/dev/fd0 of=/dev/hda bs=512 count=1
These commands take a block size of 512 bytes for a count of 1 from the input field to the output field. Again, you can use this trick even if you do not have Linux installed on the computer. It is handy to do before each new OS is installed. Then it becomes relatively easy to revert back a step if necessary.

Data Sharing

Under multi-booting, it is very desirable and even necessary to be able to share data between the different systems. Part of the reason multi-booting is so handy is that a specific application might be available only on one particular OS. You can reboot into that OS, process the data, save it, and reboot. The question becomes how and where to save the data. The floppy and CD-ROM come to mind, but they have limitations. A floppy holds a fairly limited amount of data, and while a CD-ROM holds a large amount, you must be able to write to it in each OS. A third option is to save over the network, which has a potentially large storage area but might not exist. The option I will outline is to save and read data to the computer's own hard drive from each OS. This method is fast and also potentially has a large storage area that will always be available.

Sharing data between Windows 98 and Windows 2000 is easy as long as any Windows 2000 applications save the data to the Windows 98 FAT32 partition, whatever the drive letter might be. Windows 98, Windows 2000, and Linux can also exchange data easily via FAT32 partitions. Under Linux, the partition can be mounted as:

mount -t vfat /dev/hda1 /mnt/c_drive
where -t vfat says to support long file names, /dev/hda1 is the first partition on the first IDE hard drive, and the partition is mounted at /mnt/c_drive, which must exist. The /dev structure has hda as the first hard drive, hdb as the second, hdc as the third, and so on. The first primary partition is 1, the second is 2, up to a maximum of 4. One of the primary partitions, typically the fourth, can be established as an extended partition and then logical partitions can be established within that.

Logical partition numbering starts at 5 for the first logical, 6 for the second, and continues. Once the partition is mounted, the data can be accessed through normal UNIX cp, mv, and other commands. Exchanging data with Solaris follows similar lines. The command is:

mount -F pcfs /dev/dsk/c0d0p0:c /mnt/c_drive
where -F pcfs specifies that it is a FAT16 or FAT32 file system, /dev/dsk/c0d0p0:c is the Windows partition accessed, and /mnt/c_drive is again the mount point for the partition.

The confusing part is the c0d0p0:c string. This stands for controller 0, disk 0, partition 0 (partition 1 to the other OSs), and then the first division within the partition. In this case, there is only one division or slice within the partition, but extended partitions can have several slices. If partition 4 is extended with 3 FAT32 slices in it, these would be accessed as c0d0p4:c, c0d0p4:d, and c0d0p4:e. Once it is mounted, you access the data just like Linux. To make things easier on the user, both Linux and Solaris can add entries to the boot up files to automatically mount the partitions. The file is /etc/fstab for Linux and /etc/vfstab for Solaris. See man fstab or man vfstab as appropriate for the exact format of the lines.

Multi-Boot Steps

The newer versions of Red Hat Linux and Solaris make multi-booting installation and configuration much easier and less prone to data-destroying mistakes. Here I outline the steps to convert a Windows 2000 machine with one hard drive completely devoted to Windows to multi-boot Windows 98, Windows 2000, Solaris 8 (2/02), and Red Hat 7.3. I describe this setup for two reasons. First, many of today's machines come this way -- one hard drive with all of the space devoted to NTFS. Second, I recently set up exactly this configuration and worked through the obstacles. NTFS poses a special challenge to Linux users. I know of no Linux utilities to split an NTFS partition. Linux distributions come with fips, which does a magnificent job on FAT16 and FAT32 file systems but nothing for NTFS. Specifically, the machine I set up was an AMD with a floppy, CD-ROM, and one 30-GB hard drive running Windows 2000. After exhaustive searching for a Linux partitioning tool, I admitted defeat and used Partition Commander to slice the hard drive into a 2-GB NTFS partition and 28-GB free space.

Partition Magic is a similar Windows product that does all kinds of hard drive slicing and dicing, resizing, and moving. Partition Commander has now been put on my short list of computer tools to carry. Working with the NTFS partition was slightly awkward, because I had to make a special boot disk and then boot off it, but I followed the Partition Commander instructions and got through it.

Before starting on the next OS, I made a copy of the MBR as described above (just in case), and I wanted to make a boot disk. I'm familiar with boot disks in Windows 98, Linux, and Solaris so I thought making a Windows 2000 boot disk would not be too hard. I easily made my four setup floppies, but I really wanted a disk from which I could boot and get to a command prompt. Even after searching the Microsoft Knowledge Base, there was not an obvious answer. After additional effort, I found that a method to quickly build a type of a boot floppy that works if there is a Windows 2000 installation on the hard drive. To do this, I copied the files ntldr, ntdetect, and boot.ini to a floppy.

The following shows a bare-bones boot.ini file for NT/2000/XP. The file is hidden and can be hard to find. If you do not find it, create a new boot.ini on the floppy using a text editor, not a word processor. The multi points the system to the next area in the boot sequence. Use multi for IDE drives and scsi for SCSI drives. Change disk(0), for first hard drive, and partition(1), for partition number 1, as necessary. There is a great deal more to learn about boot.ini, but this is adequate for my needs:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINNT
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINNT="Windows 2000"
I chose to add Windows 98SE next for the multi-boot installation. I booted from the floppy and got a warning message about not finding any suitable partitions for installation, so I ran fdisk when I got to a command prompt. This is literally the only situation that I will use the Microsoft Windows 98 fdisk to establish a primary partition for itself. There are a number of peculiarities associated with it that make it very dangerous to use when setting up multi-booting.

I added a primary partition, saying no when asked about devoting the entire disk to DOS. I established a 1-GB partition and exited. This forced a reboot to recognize the new drive letter. I formatted the new c: drive and then installed Windows without any problems. After the series of required reboots, the system would boot straight into Windows. The Windows 2000 system was still there but could only be accessed through a floppy. From the Microsoft Knowledge Base, the boot signature of Windows 95, 98, and ME are the same, so a system can only boot into one of those OSs. This is not a big restriction because 98 and ME are so similar.

Adding Solaris 8

Next in the install process is Solaris 8, the 2/02 version. This is the latest and possibly last x86 version of Solaris that Sun will release. Solaris 9 has been "deferred" for the Intel architecture. The order of Windows 98 and Solaris 8 can be switched. The important things to remember are the limit of three primary partitions and one extended with logical partitions and the way the Solaris boot manager works. It can only load itself from primary partitions, so Solaris can only be on partition 1, 2, or 3. Solaris 8 is the first in the series to be able to boot from a CD-ROM. I chose Solaris interactive at the start of the installation and worked through various prompts.

My video card is supported by Solaris 8, so I went through the X Windows test and the GUI came right up. The key step in the installation is "Select disks". Because this system has one IDE drive, it was listed as c0d0. I selected that and, since I did not have a partition established for Solaris, a window popped up to run fdisk. It showed partitions 1 and 2 already dedicated to Windows 2000 and 98SE, so I gave Solaris 2 GB on partition 3. The next step was the file system layout because Solaris creates slices within a partition. I let it do an auto-layout and then customized it, because it always gives the extra space to /export/home.

The following shows the way this installation ended up. During the installation, I forgot to give /var and /opt their own slices, which I typically do. I choose the End User System Support set of packages, so this gives plenty of room for those and for future growth.

(slice number, mount point, and size (MB))
0 /               195
1 swap            198
2 overlap
3
4
5
6 /usr           1300
7 /export/home    350
The rest of the installation involved just system identification and configuration and went smoothly. When I rebooted, the Solaris boot manager (see Figure 1) came up with its choice of partitions. By default, the system will time out and bring up Solaris. If I want Windows 2000, I hit 1 and enter and wait for it to come up. Similarly, I hit 2 for Windows 98. I can even get to a DOS prompt by hitting 1 at the Solaris boot manager and then quickly hitting F8 when Windows 98 starts loading. Thus, it could be argued that I have four different OSs on the system now.

Adding Red Hat

The final OS to add is Red Hat 7.3. The newest version includes some nice features. For purposes of this installation, the biggest change is the ability to specify which swap space to format. This is extremely important, because what Solaris sees as its native partition type, Linux sees as swap space. Previously, a Linux installation done after a Solaris installation would cheerfully claim the Solaris space as a lot of swap room and reformat it. Red Hat also can do a boot off the CD-ROM. Hit enter when the "boot:" prompt is displayed. It will attempt to and almost certainly bring up a GUI installation.

The only time the GUI defaulted to a console installation for me was with a one-of-a-kind on-board video card, so you should get a nice set of windows to follow. Select custom installation when prompted and then use fdisk instead of Disk Druid. Disk Druid is a useful GUI tool but does not provide the control needed in this situation. You will see a warning about being unable to align the partition properly, which is caused by different views of the world between Solaris and Linux. Click ignore and continue.

Based on previous experience with Solaris and Linux multi-booting, I created a buffer of several cylinders from the end of the Solaris partition to the beginning of the Linux partition. I have in the past been forced to reinstall when making the partitions too close. I will use fdisk to establish partition 4 as extended and then make logical partition 5 an ext3 partition for / and 6 for swap. You might want to add more partitions, especially for /home, to make future system installations and upgrades easier. Let's suppose you had a great deal of work saved in your home directory of /home/username. If /home is on the / filesystem, then doing a new Linux installation will destroy this data. If /home is on its own filesystem, then it does not have to be reformatted but the new OS can be added.

fdisk

Here is a quick walk-through of the steps involved with fdisk. Select the hda button on the window, and you will get some text and then a prompt. (Note that with fdisk, you can hit m whenever you need some help.) Hit p for print and notice which cylinder numbers are already used. Add a partition by hitting n, 4 for partition number, e for extended. Add 3 to the end of the Solaris partition for safety and use that as the beginning of your extended partition. Use the default to the end of the hard drive. Then you can add the logical drives by hitting n, and the initial cylinder number.

One trick with fdisk is to specify the partition size with the format +sizeM so a 3-GB partition becomes +3000M. A swap space about twice the size of your physical memory is typical. The fdisk will make native Linux filesystems by default, so the swap space partition type will need to be changed. Type t, the partition number, and then 82 for swap. L will give you a very long listing of the many filesystem types that Linux will support. During this step, I also added a FAT32 partition to create a dedicated area in which to exchange data between the OSes. Hit w to quit and save the changes, then click next to continue. This is the key step. You will get a window that /dev/hda3 is of swap space type but is not recognized. This is the Solaris installation, so tell it not to format. Next you will get a similar window for /dev/hda6. We want this to be the swap space, so say yes. Next, use the GUI to format /dev/hda5 and mount it as /.

grub

When you continue, you will get a warning about a potential booting problem. This is caused by the Solaris/Linux interaction and can be ignored. Follow the menus until you get to the boot loader screen. It will find the Windows 2000 and Windows 98SE installations but not Solaris. This option will be added later. I chose grub at the boot loader screen. From here, follow the prompts and let the installation proceed. When it is complete, you will get another warning about being unable to align the partitions properly, which can also be ignored. When you reboot, it will bring up the grub screen allowing you to choose between three OSes. Highlight the Linux line and hit a. You will get a prompt with the arguments for the boot. Add "single" at the end so that the system comes up in single-user mode.

Because I'm very paranoid, I want to make sure that we really are not using the Solaris partition as swap. To do this, you can inspect /etc/fstab with your choice of command (more/vi/cat, etc.) and ensure that the only line with swap in it refers to /dev/hda6. Edit the file if necessary.

Next, we edit /etc/grub.conf to add Solaris as a boot option. The following listing shows the modified file. Most of the non-Linux OSes will use the chainloader method. grub starts counting at 0 so your first hard drive becomes hd0. Similarly, partition 1 becomes the ,0) part of the syntax. I like to completely specify the different operating systems that have been loaded so I have modified the title lines. Adding the Solaris option is simply a matter of adding the last three lines of the listing below. grub has an advantage over lilo in that you do not have to reread the configuration file after it's edited. With lilo, you had to run /sbin/lilo as root to reread /etc/lilo.conf:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You do not have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /, eg.
#          root (hd0,2)
#          kernel /boot/vmlinuz-version ro root=/dev/hda3
#          initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,2)/boot/grub/splash.xpm.gz
title Red Hat Linux 7.3 (2.4.18-3)
root (hd0,4)
kernel /boot/vmlinuz-2.4.18-3 ro root=/dev/hda3
initrd /boot/initrd-2.4.18-3.img
title Windows 98SE
rootnoverify (hd0,1)
chainloader +1
title Windows 2000
rootnoverify (hd0,0)
chainloader +1
title Solaris 8 (2/02)
rootnoverify (hd0,2)
chainloader +1
Now, when we reboot the system, it will bring up the grub screen with four options, defaulting to Linux (see Figure 2). When we hit the arrows to choose Windows 98SE or Windows 2000, it will directly bring up those OSes. Remember that you can hit F8 while bringing up Windows 98SE if you want a true DOS prompt. Choosing the Solaris option will first bring up the Solaris boot manager, which will then bring up Solaris. This is normal, so do not be surprised by it. The following listing shows the final breakout of the hard drive. Note the impact of the Solaris partition. The final step is to save a copy of the MBR as above:

Disk /dev/hda: 255 heads, 63 sectors, 3649 cylinders
Units = cylinders of 16065 * 512 bytes
   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1       255   2048256    7  HPFS/NTFS
/dev/hda2           256       383   1028160    b  Win95 FAT32
/dev/hda3   *       384       639   2048256   82  Linux swap
Partition 3 does not end on cylinder boundary:
     phys=(638, 13, 63) should be (638, 254, 63)
/dev/hda4           642      3649  24161760    5  Extended
/dev/hda5           642      1024   3076416   83  Linux
/dev/hda6          1025      1050    208813+  82  Linux swap
/dev/hda7          3300      3649   2811375    b  Win95 FAT32
Other Operating Systems

We now have a system that can boot several different operating systems, but there are several others that I have not discussed. Windows NT is capable of being multi-booted but can only handle 8-GB hard drives, so it can't be added in this scenario because of available hardware (only a 30GB hard drive). Solaris 7 has the same restriction. OS/2 is not discussed here, because I have no experience with it. Also, Windows XP is excluded, because I do not have it. From what I have read, however, it can easily be added to the above scenario by doing the installation to a logical partition and then reestablishing the grub boot manager as already described.

Future

This is only a quick trip through the main points of a multi-booting system, and there are certainly many areas that can be explored in greater depth. For example, one topic from Eric Dyer that I did not have space to explain is filesystem backup and restoration. Another prime topic is multi-booting with two hard drives. Please keep the questions and comments coming. I'll respond with my thoughts, and they might even lead to "Multi-booting, Part III".

Acknowledgements

My thanks go to Eric Dyer (efdyer@attglobal.net). His insightful questions and comments started me thinking about this follow-up article. Also, Microsoft Knowledge Base (Articles Q102873, Q301680, Q217210, Q157992, Q153762) provided some information on NT/2000/XP booting.

Brian Gollsneider is working on a Ph.D. in Electrical Engineering from the University of Maryland. When not buried in research, he is a UNIX instructor for Learning Tree International. He can be contacted at: gollsneb@glue.umd.edu.