| |
Why am I writing this tutorial? Because I have recieved a lot of different advice on how to set up the bootloader on my system, and at the time I set up my first Linux partition I really wasn't sure what to do. Also, the pages with the best technical info generally had the vaguest and least convincing practical info, while those offering good advice didn't explain themselves. If you don't think you need this info, don't read it. The basic thrust of this tutorial is to help understand the process, and then use this understanding to allow you to use NTLDR to perform some powerful boot operations.
This tutorial should be most useful to those who use, or are considering, a mixed WinNT/Linux system.
Because what actually happens when a computer boots is one of those things that not even people who can build a system concern themselves with, when it comes time to make decisions that will affect the boot process, many people are lost. After all, there is little need to actually make configurations at this low level.
The first thing that happens is when the power is switched on is the BIOS is invoked. The BIOS invokes the Power-On Self Test. After the POST, the BIOS checks the boot devices in order. On older models, it was usually hard-coded to be your floppy, then hard drive. Nowadays, you can generally configure this yourself; my KT7-E allows the setting of three, and it supports booting from an impressive array of devices, including LS-120 disks.
Why is this important when most boots are from a hard drive? Two reasons:
- Most boots from a volatile medium such as a CD or floppy are when you are performing an OS install or serious repair work; it is important to know what you are doing at these times.
- The process of booting is very similar for all devices, though hard drives are a little more complex. Therefore we will look first at floppy drives (FDDs), then take a fuller look at booting from a hard disk (HDD).
Overview of the Boot Process When a floppy is reached as a boot device, the system looks at the boot sector. If the floppy is not bootable, you get that familiar error that comes up every time you leave a floppy in the drive (provided your FDD is before HDD). If the floppy is bootable, the process can begin.
More interestingly, the HDD has two layers in the boot process. Each volume (or partition) has a boot sector, 512 bytes of data, which covers the necessary boot process for that volume, and the disk itself has its own boot sector, the Master Boot record (MBR). The 512 bytes that make up the Master Boot Record are what are loaded when the BIOS invokes the HDD as the boot device.
What's in the Boot Sector? As you will appreciate, 512 bytes (or 256 words, if you prefer) is not a lot of space to store any computer program, and that is why the bootstrap loader (bootloader) is not widely discussed; while it plays a crucial role, it doesn't do very much. Hairy programming techniques are often used in order to boot an OS even from that much space. For the this reason, the secondary explained below is usually lumped in with the actual bootloader, even though the data is stored in the areas of the disk that are visible to the user.
The bootloader program generally executes another program that does the next step in preparing the system. On MS-DOS based systems, this includes the familiar system files like io.sys, msdos.sys, autoexec.bat and config.sys. The MS-DOS bootloader is not really of interest here, as it is not capable of booting many different OSes.
Why NTLDR? The two bootloaders that are worth serious consideration are LILO and NTLDR. Now, I must say that for all the wrong reasons this decision will be automatic for most DevHood citizens. Simply put, NTLDR is is rather territorial. Compared to NTLDR, LILO is very well-behaved, and so as a reward for this, we aren't going to give it control of our MBR. The nice guys always geta raw deal. Don't worry, it is still needed to load Linux, but only on the boot sector of the Linux volume.
Now we are getting to an area of familiarity for many readers: some of you who kept your old Win9X OSes when you upgraded to an NT-based OS will have noticed that C: gained a few new files, like NTLDR (no extension) and boot.ini. The purpose of NTLDR has already been discussed; boot.ini is a configuration file that is used by NTLDR to know what OSes are available, and how to boot them.
If you are newly installing Linux, choose to have LILO installed on your Linux partition's boot sector, but do not let Linux alter the MBR. Make a boot floppy for the time being.
Anatomy of boot.ini Below is the boot.ini file from the box I am writing this on. Please note that it is a Windows 2000 boot.ini; the files generated by Windows XP seem to be identical, but it is possible that they are not.
[Boot Loader] Timeout=5 Default=multi(0)disk(0)rdisk(0)partition(4)\WINNT [Operating Systems] multi(0)disk(0)rdisk(0)partition(4)\WINNT="Microsoft Windows 2000 Professional" /fastdetect C:\BOOTSECT.DOS ="MS-DOS (Legacy Support)" C:\debian.mbr = "Debian GNU/Linux"
We'll look at this line by line, the first line being self-evident. The Timeout setting tells how long to show the the OS menu at boot-time. Setting this to zero still results in the menu being shown, but it is impossible to actually choose an OS. The Default setting sets the default (of course), and gives NTLDR the necessary info to boot this OS, which is addressed several ways, explained below. Below the [Operating Systems] tag is a list of OSes, in the following format:
path = name /switches
Partitions containing NT installations are addressed in the form multi(x)disk(y)rdisk(z)partition(n), with n being the partition number on that disk, and z being the disk number. On IDE systems, x and y are always zero.
Partions containing DOS (or Win9x) installations are referred to by a drive letter only in most situations. NTLDR looks for a file called "BOOTSECT.DOS" which is a 512-byte backup of what was in the MBR before NTLDR was installed. I have explicitly referenced it, as I am currently experimenting with a Windows 98 partition, trying to seperate DOS32 from Windows.
Other OSes must explicitly reference the file that contains the necessary information to boot that OS. In order to obtain this data for Linux installations, see below.
Getting the Boot Sector Data It would be logical and efficent to invoke the bootsector of the target disk from NTLDR directly. Sadly, this would require an understanding of assembler and machine code, and would be specific to your system. If you want to try it, more power to you. The normal solution is to simply dump the contents of the boot sector of your Linux volume to a file and store it on the C:\ drive, and have boot.ini reference that. The best way to do this is to use Linux utility dd. In fact, I would use this util to dump the boot sectors of FAT32 volumes. The command from your Linux shell is formatted as follows:
dd if=infile of=outfile bs=blocksize (bytes) count=blocks to read
You will only need to set the infile and outfile, so an example invocation would be:
dd if=/dev/hda5 of=/usr/tmp/debian.mbr bs=512 count=1
Because the volume on the hard disk is just a file under Linux, you can treat it as one and copy the first 512 bytes as a block to a file. Now just mount your boot volume or a floppy, and copy that file to the boot volume (if you prefer not to touch your FAT32 volumes under Linux, use a floppy). If unsure how to mount your boot volume under Linux, try this:
mkdir /myCdrive
mount -t vfat /dev/hda1 /myCdrive
and to copy the file:
cp /usr/tmp/debian.mbr /myCdrive
Note that the above assumes that your boot volume is the first partition on your disk. This is almost always the case, as long as the original OS on the system was MS-DOS, a Windows 9X, or a Windows NT.
Final Config Now, add a line at the bottom to the boot.ini file specifying your new OS, such as the following:
C:\debian.mbr = "Debian GNU/Linux"
You may want to alter the filename of the bootsector image if you copied a different OS, or just a different Linux distribution (remember, dd can copy from any partition Linux recognizes), and you are free to alter the display name of your OSes. Several of my associates made unprintable comments about the OEM Windows ME their computers came with after installing Windows 2000 or Windows NT.
If you need any help or assistance, feel free to private meassage me or email at .
Disclaimers: The following should be kept in mind
- Working at the boot level with devices is risky- a mistake could leave your system unbootable.
- This information applies to modern x86 systems. Those that run i386-based OSes such as Linux and 32-bit Windows are included.
- Even if you followed my instructions to the letter, I am not liable for any lost data or damaged hardware.
- Altering your bootloader or boot.ini file may violate End-User License Agreements with your software suppliers.
- "Windows", "MS-DOS" and individual "Windows" versions are trademarks of Microsoft. Use here does not constitute a challenge to those copyrights.
|
|