Home  |  FAQ  |  About  |  Contact  |  View Source   
 
SEARCH:
 
BROWSE:
    My Hood
Edit My Info
View Events
Read Tutorials
Training Modules
View Presentations
Download Tools
Scan News
Get Jobs
Message Forums
School Forums
Member Directory
   
CONTRIBUTE:
    Sign me up!
Post an Event
Submit Tutorials
Upload Tools
Link News
Post Jobs
   
   
Home >  Tutorials >  General Coding >  Understanding the Boot Process and NTLDR
Add to MyHood
Understanding the Boot Process and NTLDR   [ printer friendly ]
Stats
  Rating: 4.15 out of 5 by 13 users
  Submitted: 03/04/02
Simon Parsons ()

 
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.

Return to Browsing Tutorials

Email this Tutorial to a Friend

Rate this Content:  
low quality  1 2 3 4 5  high quality

Reader's Comments Post a Comment
 
Good tutorial.
-- Brian Simoneau, March 05, 2002
 
Personally I like GRUB (handles more FS's) better than LILO, but that is personal preference. I also typically install windows first and then Linux and use the linux bootloader as it does all the necessary steps to add Windows to it's boot loader file.... but again that is just personal preference.
-- Greg McMurray, March 05, 2002
 
I am certainly on my way to understanding the boot process but I am probably just as confused about my own system. I am not sure at times whether the information is addressing multiple disks or partitions or something else.
-- Adam Patridge, March 05, 2002
 
Nice work.
-- Peter Huene, March 05, 2002
 
Good tutorial. I have never used GRUB, only lilo. I like lilo though. Seems to get the job done. In fact, when I installed XP, linux was already installed and XP didnt mess with anything. This really surprised me. I thought for sure I would have to re-do the mbr.
-- Reid Jonasson, March 06, 2002
 
Grub is really nice. i like it more than lilo, and this is a great tutorial.
-- Felipe Oduardo, March 06, 2002
 
As a response to all those that commented on using Linux bootloaders, I agree with you. As it says in the text, it is easier to use them....but NTLDR is a solid piece of software, and since the method to use it to boot Linux is not obvious, I thought it was worth a tutorial. It's a shame to exclude them for being more well-behaved, but as Windows NT is currently more important to me, and I suspect, others I think that being able to add Linux to a box without changing the MBR is worthwhile

Anyhow, it seems people found it interesting, and that is all I hoped for.
-- Simon Parsons, March 06, 2002
 
Great work!
-- Kuniaki Tran, March 09, 2002
 
Excellent tutorial, and especially helpful to me since i will be setting up a dual boot of Linux and XP this weekend. ^^ - Thanks!!
-- George Schwenzfeger, April 02, 2002
 
Good article... I have been using Mandrake Linux along with W2K for about 2 months, everything was great and then ..BOOM.. out of nowhere it seemed came that wonderful "NTLDR not found".
I'm searching for answers. Didn't find them in this article, but it did help me with the overall boot process. Thanks.
-- Michael Key, April 08, 2002
 
Excellent tutoiral. I've been a linux user for over 5 years, and I started computers with imb's pc-DOs in elemtary school, and I never know of the trick to get windows to boot linux like that. I've always had lilo give me the windows option, and then had to choose my MS operating system. This was very informative and useful. Thanks a bunch!!!!

William
-- William Triest, April 09, 2002
 
Any information that I get now is helpful. Thanks!
-- Thomas Rose, April 15, 2002
 
Please go ahead and contact me with questions; I'm getting enough that I am considering a sequel with information on booting other OSs, such as BeOS.
-- Simon Parsons, April 24, 2002
 
Nice tutorial Ben, I think I remember reading something similar to this in an old Maximum PC edition. Very helpful information for the Linux novice.
-- Jon Wright, June 03, 2002
 
Wow! This is just what I needed! Thanks so much...
-- David Harris, July 08, 2002
 
Thanks, I've always wanted to know to do that. I've used LILO and GRUB, but always wondered if it was possible to use NTLDR.
-- Brent Bishop, August 08, 2002
 
It is fan-tast-ic !
Are you paid for doing such a wonderful job ?
Great tutorial, so great teacher !
-- jean mupopa, January 02, 2004
 
Copyright © 2001 DevHood® All Rights Reserved