How To Multi-Boot Operating Systems
|
|
When IBM was putting together their Personal Computer (PC), they wanted an operating system (OS) to go with it. Gary Kildall, who wrote the popular CP/M (Control Program for Microprocessors) for early Intel Microprocessors, could not be interested to provide a new one for the IBM PC, which was based on the latest Intel processor. So, IBM gave the contract for the new OS to what was then a little-known company called Microsoft. Microsoft bought QDOS (Quick and Dirty Operating System) written by one Tim Patterson based on a manual of CP/M. The first IBM PC was released with QDOS rechristened as DOS (Disk Operating System) from Microsoft. As IBM PC compatibles began to be manufactured by companies like Compaq, Microsoft was no longer dependent on IBM. Soon, it overtook IBM as the leading provider of software for PCs. When a user started an IBM PC or PC-compatible running on MS-DOS, it went to straight to the command prompt. (If you want to see how this looked like, then type cmd or command in the Run dialog box of the Start menu of a Windows PC.) The command prompt was the OS of those PCs! To perform ordinary operations like copying a file or deleting one, the user had to type complicated commands (without any syntax errors, of course) on the command prompt. Users also had to remember a number of keyboard shortcuts. The keyboard shortcuts were actually keyboard commands, as they were quite indispensible and not really alternatives. Over time, Microsoft released new versions of DOS but the biggest improvement came when they released Windows. This was a poor imitation of the Apple Macintosh's Graphical User Interface (GUI) but it still managed to become very popular. It had a mouse, which enabled a point-and-click interface come to life, and was more easy to use when compared to DOS. Windows versions from 1 to 3.1 were not real OSs. They worked as just another program that ran on DOS. Each one of them was in effect an "operating environment." So, in 1995, Microsoft released Windows 95, an OS that was fully GUI-based. Microsoft then went on to release newer Windows OSs, such as Windows 98, Windows Me, Windows 2000 and Windows XP.
As Microsoft was dominating the OS market, a sly newcomer called Linux (or GNU/Linux to be correct) came to sudden prominence. Finnish programmer Linus Torvalds, in conjunction with the GNU community, took the UNIX kernel and ported it to the Intel PC platform. Until then, most UNIX implementations such as BSD Unix, SCO Unix, HP Ux, IBM Aix and Solaris OS, were limited to supercomputers and mainframes. There were notable attempts such as BeOS to break into the Intel PC market but it was Linux that really managed to survive and flourish. Today, there are numerous flavours of Linux called distributions or distros, such as Red Hat Linux, Mandriva Linux (formerly Mandrake Linux), Novell Linux (formerly Suse Linux) and Debian Linux. Although these distros are available as commercial shrink-wrapped software, they can also be freely downloaded and installed on PCs. Their source code is also available for free. And now, many people want to install Linux and tinker with it. Few of them are yet ready to give up their existing Windows OSs. Realising this, the distros come with smart bootloader programs which help multiple OSs to coexist on a single PC. Despite everything, installing Linux remains intimidating for the uninitiated. Terms such as partitions,‡ bootloaders and MBR spook newbies to the point that many of them abandon any interest in trying out Linux. Some are put off by horror stories of people who found themselves unable to boot into Windows after installing or removing Linux.
In this writeup, you will learn to safely dual-boot or multi-boot operating systems. Specifically, you will learn about booting Linux from the Windows boot menu. If you have any unanswered queries, you can take it to my discussion forum. You might also find additional info in the writeups PC Hardware Explained, 101 Tips & Tricks To PC Performance and Windows XP Tips & Tricks helpful.
Go Down
|
| Disc Drives & Partitions |
|
Most Windows users have more or less the following idea about disk drives.
- A: and B: are floppy discs.
- C: is in the hard disc.
- D: is the CD drive or the DVD drive.
Sometimes, when there is an extra hard disk drive, then that drive becomes D: and the CD/DVD drive E:. What they do not always know is that the C: and D: are actually only a single disk drive and are technically known as partitions. This is why people blink when a Linux installation asks them to choose a "partition" to install the OS.
A hard disc can have a maximum of only four partitions. In the early days of the IBM PCs, this number was thought to be more than sufficient. However, over time, the need for more partitions arose. So, the concept of primary partitions, extended partitions, and logical partitions was introduced. The old-style partitions were then known as primary partitions and one of these primary partitions could be what is known as the extended partition. The extended partition had a very important improvement over ordinary primary partitions. It could house any number of smaller partitions known as logical partitions inside it. Thus, the four-number primary partition limit was kept while the need for more partitions was met. Most people, when they get a new hard disk, create just one primary partition and one extended partition. Whenever a new partition is needed, a new logical partition is created inside the extended partition.
Somewhat unrelated to the number scheme above but relevant to booting OSs are active partitions and boot partitions. An active partition is a designated partition that has the files for loading the default OS or the bootloader (the program file that displays the boot menu and loads the required OS). Only one partition on a disk can be an active partition. A boot partition is the partition where the OS is installed. Windows 95/98/Me is adamant about having the first partition on the hard disk as the boot partition. Windows 2000 and Windows XP operating systems (OSs) can be installed on just any partition on the hard disc. The installation procedure actually allows the user to choose the partition on the disk. Similarly, Linux distributions can be installed on any partition.
When you install an OS on a partition, it will first format the partition. Formatting essentially creates a file system on the partition that the OS can use. Different OSs use different file systems. DOS/Windows 3.1 used the FAT-16 (File Allocation Table 16 bit) system. Windows 95/98/Me used FAT-32. Windows NT/2000/XP use the NTFS (New Technology File System). Linux distros use the ext2 and ext3 file systems. Apart from OS installation programs, there are third-party utilities like Ranish Partition Manager and Partition Magic, which will create, format, resize, and delete partitions on your hard disc.
|
| Booting a Single OS on a PC |
|
Now that you know all about partitions, you can move on to the topic of boot loaders. Bootloader programs come into action right after the BIOS (the motherboard code) performs the POST.† Bootloader programs are necessary to load an OS into execution or to display a boot menu where the user can make a choice from the available operating systems installed on the PC. Loading an OS involves two important sectors* of the disk - master boot record (MBR) and the boot sector of the OS. The MBR contains a partition table and some executable code called master boot code (MBC). The partition table contains geometry information about the disk so that all the partitions on it can be identified. The MBC is written by OS installation procedures or a bootloader programs so that they will load the OS or the bootloader program respectively. The MBR is always on the first sector of a disk. The partition table on the MBR is written the first time a partition is created on a hard disk and is independent of the OS(s) installed on the computer. The boot sector is on the first sector of every partition on a disk. On an active partition, the boot sector contains code that will load the default OS or the bootloader program. On other partitions, the boot sector may or may not have executable code. On boot partitions, however, the boot sector has executable code necessary to load the operating system. When you partition a disc, the partitioning utility or the OS installation procedure will allow you designate one of the partitions as an active partition. Without an active partition, you will not be able to boot into an OS from the hard disc.
The sequence of loading an OS is as follows:
- When the PC starts, the BIOS locates the MBR on the disc, loads the MBC on the MBR, and transfers control to it.
- The MBC reads the partition table and identifies the active partition on the disk.
- The MBC loads the executable code in the boot sector of the active partition and transfers control to it.
- The executable code from the boot sector,
- which if it belongs to default OS, loads the default OS.
- which if it belongs to a bootloader program, loads the bootloader program.
- The bootloader program displays the boot menu and allows the user to select an OS.
- The bootloader program loads the boot sector on the boot partition of the selected OS.
- The code in the boot sector loads the OS.
|
| Dual-Booting or Multi-Booting Windows OSs |
|
When you install Windows 2000/XP on a machine that already has Windows 95/98/Me, you have the option of upgrading (overwriting the Windows 9x/Me installation with Windows 2000/XP) or having a dual-boot or multi-boot setup. If you choose the latter, the new OS is installed on a different partition. The installation procedure installs a boot loader program in the boot sector of the active partition. It also modifies the MBC so that the latter can load the bootloader program that was installed on the Windows boot partition. The bootloader program displays a boot menu, which lists the available Windows OSs and lets the user to choose an OS from the menu.
The Windows 2000/XP installation procedure makes a copy of the original boot sector that was created by the Windows 9x/Me installation and places it in a hidden file named bootsect.dos. Next, it overwrites the boot sector with its own boot loader program NTLDR (NT Loader). So, every time you start the computer, NTLDR is loaded by the MBC. The NTLDR displays a boot menu that offers booting to Windows 9x/Me or Windows 2000/XP. If you choose the Windows 9x/Me option, then the old boot sector information from the bootsect.dos file is emulated by NTLDR and the computer boots into Windows 9x/Me.
|
| Boot.ini |
|
During the installation procedure, a file called boot.ini is created, which contains the choices displayed in the NTLDR boot menu. A typical boot.ini file on a PC that has Windows Me on the active partition (C:) and Windows XP on the second partition (D:) looks like this:
[Boot Loader]
Timeout=30
Default=C:\
[Operating Systems]
C:\="Microsoft Windows Me"
multi(0)disk(0)rdisk(0)partition(2)\WINNT="Microsoft Windows XP" /fastdetect
In the Boot Loader section, the Timeout parameter represents the number of seconds the boot menu will be displayed. If no option is chosen, the operating system specified by the Default parameter is loaded. In the Operating Systems section, NT-based OS installations are identified by Advanced RISC Computing (ARC)-style pathnames.
| Advanced RISC Computing (ARC) Pathname Parameters |
| NUMBER |
STARTS FROM |
REFERS TO |
DESCRIPTION |
| multi |
0 |
Number of the disk controller identified by INT 13 (a CPU instruction used by BIOS) |
Because most BIOSes can identify only one adapter with INT 13, this number is always 0. |
| disk |
0 |
SCSI ID of the disk |
This is valid only on SCSI controllers. For IDE discs, this number is always 0. |
| rdisk |
0 |
Number of the disk on the controller |
On IDE controllers, the maximum number of disks possible is 4. So, this number ranges from 0 to 3. |
| partition |
1 |
Number of the boot partition on the disk |
The boot partition is where the OS is stored. This is different from the active partition. In the above example, the active partition is C: but the boot partition for the Windows XP installation is the second partition or D:. |
|
| Linux Installation |
|
You have learned how Windows OSs coexist. The real headache comes when you try to install a non-Windows OS like Linux. NTLDR recognises only Windows partitions (FAT, FAT-32 and NTFS) and is blind to Linux partitions. In other words, NTLDR cannot load Linux. Thankfully, Linux distros come with bootloader programs, such as GRUB (Grand Unified Bootloader) or LILO (Linux Loader), which recognise both Linux and Windows partitions. This means that they can load both Linux and Windows. When you install Linux, the installation procedure replaces the MBC (on the MBR) created for Windows NTLDR with an MBC that is set to load LILO or GRUB. (This means that in future, the user will see LILO or GRUB instead of Windows or Windows NTLDR everytime the PC is started.) When the Linux installation procedure installs LILO, it automatically creates an option for Windows in its boot menu. This allows the user choose to load Windows at the LILO/GRUB boot menu. When the user chooses the Windows option, LILO loads NTLDR and exits. NTLDR then displays its boot menu and allows the user to load a Windows OS.
Now, you should learn about the Linux installation procedure in more detail. The Linux installation procedure uses some special terms to identify hard disc partitions. The MBR is called /dev/hda. Your first partition is treated as /dev/hda1; the second one will be /dev/hda2, and it goes on like that. On a second hard disk on your PC, the partitions will be known as /dev/hdb1, /dev/hdb2,... On a third hard disk, we will have /dev/hdc1, /dev/hdc2... Every Linux installation requires two or three new partitions, which are identified as:
- / - The root partition (/) is where the Linux OS files are stored. The installation procedure will allow you to create and format this partition. If you already have a free Linux partition, then you can set that as the root partition. Most people keep the size of the root partition at 4-6 GB. On my machine, the first partition /hdc1 holds Windows and so I designated the second partition /hdc2 as the root partition. (If you are wondering why my hard disk is labelled hdc instead of /hda, rest assured that it is because my motherboard supports 8 IDE devices and my hard disk is third on the list.)
- /boot - Creating an individual boot partition (/boot) separate from the root partition is optional. When you create a separate boot partition, the boot sector on this partition contains code that can load the bootloader program (LILO or GRUB). When the MBC loads the code in the boot sector on the boot partition, the LILO/GRUB boot menu is displayed. If you don't choose to create a separate boot partition, then the boot sector of the root partition contains the code to load the bootloader program. The installation procedure will allow you to install LILO or GRUB on the root partition (/) or a boot partition (/boot). Most people allocate 100-200 MB for /boot. On my PC, I designated /hdc11 as the boot partition because partitions /hdc3 through /hdc10 were Windows partitions.
- swap - The swap partition is where some disc space is allocated for the virtual memory management operations of the OS. (Old OSs such as DOS had only modest memory requirements. Modern GUI-based OSs have much larger memory requirements; much larger than installed RAM. Virtual memory management allows these OSs to greatly expand the size of the available RAM by using a swap disk space as a temporary cache.) Set the size of the swap partition to approximately 2 to 2-1/2 times the installed RAM. On my machine, the swap partition resides on /dev/hdc12.
Here, I've got to make a small clarification. The Linux installation procedure will ask you for a location to install the bootloader (LILO or GRUB)? No mater which option you choose, the bootloader files are going to be stored on / or /boot. (None of the locations listed by the procedure is big enough to hold all the files of the bootloader program.)
- If you choose the MBR option, the old MBC used by Windows NTLDR will be replaced by a new one for LILO. Your computer will display the LILO boot menu instead of the NTLDR boot menu after the installation. A Linux boot sector will also be written to / or /boot.
- If you choose first sector of the root partition option, then a Linux boot sector will be written on / or /boot. Your computer will continue to boot with the NTLDR boot menu because the MBC on the MBR has been left untouched.
- If you choose the floppy option, then a Linux boot sector will be written on to a floppy disc. You can use this floppy disk to boot in to Linux after setting the floppy drive as the first boot device in BIOS.
|
| Getting NTLDR to Load Linux |
|
You have learned how the default Linux installation handles multibooting. Basically, you have LILO loading NTLDR to boot into Windows. However, this involves overwriting the MBR i.e., the MBC (created for Windows NTLDR) being overwritten by an MBC (created for Linux LILO). If you are a Linux newbie, you might feel very apprehensive about this. What if you don't like Linux and want to get rid of it? LILO will be gone and there would be no way to boot into Windows! (Well, you could simply restart the PC with a DOS emergency disk and use the fdisk /mbr DOS command to restore the old Windows MBR.)
Now, if there was a way to get NTLDR into loading Linux, wouldn't you like that? Actually, a way exists. Interestingly, this idea was proposed by Microsoft. What you need to do is create a Linux boot sector file and place it in a Windows drive where NTLDR can access it. Next, you add a new entry in the boot.ini file so that NTLDR can use the bootsector file to transfer control to the Linux bootloader. (This is similar to the behind-the-scenes bootsect.dos-file technique that NTLDR uses to load Windows 95/98/Me.) This way, your Windows installations remains available all the time. Here are the steps:
- Power on/restart your PC.
- Enter BIOS setup.
(Refer your motherboard manual for the exact key to press for entering BIOS setup.
Usual suspects are Delete and F1.)
Set your floppy drive as the first boot device, followed by your CD/DVD drive as the second boot device, and exit BIOS setup.
- Put your Linux install CD/DVD in the CD drive and restart your PC. (Remove any floppy discs from your floppy drives.)
- Your PC will boot from your CD and the Linux installation will begin.
Follow the instructions on the screen but ensure that you have chosen the custom installation method so that you can manually specify all the options.
(If you let the installation run on its own, it will overwrite the MBR with the Linux bootloader. We don't want that to happen so...)
Create root (/), boot (/boot), and swap partitions as mentioned above.
If you have already created these partitions in a previous installation, then just assign them.
Ensure that you install the bootloader (GRUB or LILO) to /boot and not to the MBR.
In Mandriva 2007 installation, you do this in the Bootloader step.
(Please note that the following screenshot is newer - of Mandriva 2007 - while the rest of this article is based on Mandrake 10.1)
- Before exiting the Linux installation process, install the bootloader to a floppy also.
(This is very important.
As of now, your PC can boot into Windows only.
To boot into your new installation of Linux for the first time, you will need this floppy disc.)
After installing the booloader to the floppy, set the bootloader program back to your /boot partition.
In the Mandriva 2007 Linux installation, you can do all this in the Summary step.
- When the installation is over, your PC will be restarted. Insert the floppy disc in the floppy drive and remove the Linux CD/DVD from the CD drive.
- You will now boot into your new Linux OS.
- Login as root (su).
- Use the dd console command to create a copy of the boot sector (first 512 bytes) of the Linux boot partition (/dev/hdc11) to a file (mlnxboot.dos) on the /dev/hdc1. The /dev/hdc1 partition (our Windows C: drive) should have been mounted and made writable for this command to work. I have named the Linux bootsector file as mlnxboot.dos because I am using Mandrake Linux 10.1. (BTW, Mandrake is now known as Mandriva.) You can use any name for this file. Just make sure the filename is in the DOS 8.3 format - maximum 8 characters for the filename and 3 characters for the extension. if stands for input file. of stands for output file. bs stands for block size. count stands for number of blocks to copy.
dd if=/dev/hdc11 bs=512 count=1 of=/dev/hdc1/mlnxboot.dos
- Remove the floppy from the drive and restart the machine to boot into Windows.
- Open a command prompt window (type cmd or command in the Start menu Run dialog box), navigate to c:\cd c:\
- Use the DOS attrib command to make the boot.ini file writable.attrib -r -h -s boot.ini
- Open the boot.ini file in Notepad¤ and add this line to Operating Systems section.
C:\mlnxboot.dos="Mandrake Linux 10.1"
Now, my boot.ini file looks like this.
[Boot Loader]
Timeout=30
Default=C:\
[Operating Systems]
C:\="Microsoft Windows Me"
multi(0)disk(0)rdisk(0)partition(2)\WINNT="Microsoft Windows XP" /fastdetect
C:\mlnxboot.dos="Mandrake Linux 10.1"
- Save the changes to the boot.ini file and restore the file's original attributes with the attrib command in the command prompt window.
attrib +r +h +s boot.ini
- Restart the machine and the NTLDR will now display Mandrake Linux 10.1* in its boot menu. You can select the Mandrake option to boot into Linux.
Sometimes, you may get an error message that says the <Windows root>\system32\hal.dll file is missing or corrupt. To avoid the hal.dll error message, ensure the boot sector file is named with the 8.3 format. Also, you need to make a new bootsector file everytime you make a change to your boot loader configuration. If you ever forget to do this, you can use the boot floppy you had created during the installation.
- If all your operating systems are dualbooting or multibooting fine, then enter BIOS Setup and set your hard disk as the first boot device. Otherwise, the BIOS will make your PC check for boot floppies or boot CD drives everytime it boots up. (Wastes time.)
With this setup, dumping Linux and going back to a monogamous relationship with Microsoft involves very little heartburn. Just delete the Linux partitions and remove the C:\mlnxboot.dos="Mandrake Linux 10.1" line from the boot.ini file.
|
| Other Options |
|
If NTLDR and LILO drive you mad, you should try eXtended Operating System Loader (XOSL), a standalone Open Source boot loader program. XOSL supports almost all PC operating systems.
If you don't want to play with partitions, you can use a Knoppix Live CD or an Ubuntu Live CD to run these demo Linux OSs off the CD-ROM drive. Live CD Linuxes do not even require an installation. Just set the first boot device as your CD/DVD drive in the BIOS and restart the machine with the Live CD in the CD/DVD drive.
† - POST or Power-On Self Test is a series of tests performed by the BIOS when you switch the PC on. POST allows the PC to identify the devices on the PC and and initialize their settings.
* - A sector on a hard disc contains 512 bytes of information. A hard disk is divided into numerous sectors. To put in perspective, a 20 GB (20,000,000,000 bytes) hard disk contains 39062500 sectors.
¤ - The Notepad application is a text file editor and will typically open/save files with a .txt extension. So, when you open/save the boot.ini in Notepad, type the complete pathname enclosed with quotation marks - "C:\boot.ini" - in the File name input box.
|