Welcome to MSDN Blogs Sign in | Join | Help

How Windows Starts Up (part 1 of 4)

Hi folks, my name is David and I’m an Escalation Engineer for Microsoft.  Since Bryan wrote about How Windows Shuts Down, I thought it would be a good idea to cover How Windows Starts Up.

 

This information applies specifically to Windows 2000, Windows XP, and Windows Server 2003.  I will blog separately on the boot changes in Windows Vista.

 

Additional information about this topic may be found in Chapter 5 of Microsoft Windows Internals by Russinovich and Solomon and also on TechNet:  http://technet.microsoft.com/en-us/library/bb457123.aspx

 

Methodology

The key to understanding and troubleshooting system startup issues is to accurately ascertain the point of failure.  To facilitate this determination, I have divided the boot process into the following four phases.

 

                1. Initial

                2. Boot Loader

                3. Kernel

                4. Logon

 

Over the next few weeks, I’ll be describing each of these phases in detail and providing appropriate guidance for troubleshooting relevant issues for each phase. 

 

Initial Phase

The Initial Phase of boot is divided into the Power-On Self Test (POST) and Initial Disk Access. 

 

Power-On Self Test

POST activities are fully implemented by the computer’s BIOS and vary by manufacturer.  Please refer to the technical documentation provided with your hardware for details.  However, regardless of manufacturer, certain generic actions are performed to ensure stable voltage, check RAM, enable interrupts for system usage, initialize the video adapter, scan for peripheral cards and perform a memory test if necessary.  Depending on manufacturer and configuration, a single beep usually indicates a successful POST. 

 

Troubleshooting the POST

ü  Make sure you have the latest BIOS and firmware updates for the hardware installed in the system.

ü  Replace the CMOS battery if it has failed.

ü  Investigate recently added hardware (RAM, Video cards, SCSI adapters, etc.)

ü  Remove recently added RAM modules.

ü  Remove all adapter cards, then replace individually, ensuring they are properly seated.

ü  Move adapter cards to other slots on the motherboard.

ü  If the computer still will not complete POST, contact your manufacturer.

 

Initial Disk Access

Depending on the boot device order specified in your computer’s BIOS, your computer may attempt to boot from a CD-ROM, Network card, Floppy disk, USB device or a hard disk.  For the purposes of this document, we’ll assume that we’re booting to a hard disk since that is the most common scenario.

 

Before we discuss the sequence of events that occur during this phase of startup, we need to understand a little bit about the layout of the boot disk.  The structure of the hard disk can be visualized this way:  (Obviously, these data areas are not to scale)

 

 

 

Hard disks are divided into Cylinders, Heads and Sectors.  A sector is the smallest physical storage unit on a disk and is almost always 512 bytes in size.  For more information about the physical structure of a hard disk, please refer to the following Resource Kit chapter:  http://www.microsoft.com/resources/documentation/windowsnt/4/server/reskit/en-us/resguide/diskover.mspx

 

There are two disk sectors critical to starting the computer that we’ll be discussing in detail:  

 

·         Master Boot Record (MBR)

·         Boot Sector

 

The MBR is always located at Sector 1 of Cylinder 0, Head 0 of each physical disk.   The Boot Sector resides at Sector 1 of each partition.  These sectors contain both executable code and the data required to run the code.

 

Please note that there is some ambiguity involved in sector numbering.  Cylinder/Head/Sector (CHS) notation begins numbering at C0/H0/S1.  However, Absolute Sector numbering begins numbering at zero.  Absolute Sector numbering is often used in disk editing utilities such as DskProbe.  These differences are discussed in the following knowledge base article:

Q97819  Ambiguous References to Sector One and Sector Zero

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q97819

 

Now that we have that straight, when does this information get written to disk?  The MBR is created when the disk is partitioned.  The Boot Sector is created when you format a volume.  The MBR contains a small amount of executable code called the Master Boot Code, the Disk Signature and the partition table for the disk.  At the end of the MBR is a 2-byte structure called a Signature Word or End of Sector marker, which should always be set to 0x55AA.  A Signature Word also marks the end of an Extended Boot Record (EBR) and the Boot Sector.

 

The Disk Signature, a unique number at offset 0x1B8, identifies the disk to the operating system.  Windows 2000 and higher operating systems use the disk signature as an index to store and retrieve information about the disk in the registry subkey HKLM\System\MountedDevices.

 

The Partition Table is a 64-byte data structure within the MBR used to identify the type and location of partitions on a hard disk.  Each partition table entry is 16 bytes long (four entries max).  Each entry starts at a predetermined offset from the beginning of the sector as follows:

 

                                Partition 1                           0x1BE    (446)

                                Partition 2                           0x1CE    (462)

                                Partition 3                           0x1DE    (478)

                                Partition 4                           0x1EE    (494)

 

The following is a partial example of a sample MBR showing three partition table entries in-use and one empty:

 

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00 00 00

000001D0: 81 0A 07 FE FF FF 8A F5 – 7F 00 3D 26 9C 00 00 00

000001E0: C1 FF 05 FE FF FF C7 1B – 1C 01 D6 96 92 00 00 00

000001F0: 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00

 

Let’s take a look at each of the fields of a partition table entry individually.  For each of these explanations, I’ll use the first partition table entry above and highlight the relevant section.  Keep in mind that these values are little-endian.

 

Byte Offset

Field Length

Sample Value

Field Description

0x1BE

8 Bits

0x80

Boot Indicator

                00=Do Not Use for Booting

                80=Active partition (Use for Booting)

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00     

 

0x1BF

8 Bits

0x01

Starting Head

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

0x1C0

0x1C1

2 Byte

Word

0x01

Starting Sector

Only the first 6 bits are used.  The upper 2 bits of this byte are used by the Starting Cylinder field.

0x00

Starting Cylinder

Uses 1 byte + 2 bits from the Starting Sector field to make up the cylinder value.  The Starting Cylinder is a 10-bit number with a maximum value of 1023.

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

 

 

0x1C2

8 Bits

0x07

System ID

Defines the volume type.  0x07=NTFS

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

Other Possible System ID Values:  

Partition Type

ID Value

0x01

FAT12 primary partition or logical drive (fewer than 32,680 sectors in the volume)

0x04

FAT16 partition or logical drive (32,680–65,535 sectors or 16 MB–33 MB)

0x05

Extended partition

0x06

BIGDOS FAT16 partition or logical drive (33 MB–4 GB)

0x07

Installable File System (NTFS partition or logical drive)

0x0B

FAT32 partition or logical drive

0x0C

FAT32 partition or logical drive using BIOS INT 13h extensions

0x0E

BIGDOS FAT16 partition or logical drive using BIOS INT 13h extensions

0x0F

Extended partition using BIOS INT 13h extensions

0x12

EISA partition

0x42

Dynamic disk volume

0x86

Legacy FT FAT16 disk *

0x87

Legacy FT NTFS disk *

0x8B

Legacy FT volume formatted with FAT32 *

0x8C

Legacy FT volume using BIOS INT 13h extensions formatted with FAT32 *

 

Partition types denoted with an asterisk (*) indicate that they are also used to designate non-FT configurations such as striped and spanned volumes.

 

0x1C3

8 Bits

0xFE

Ending Head      (0xFE=254 decimal)

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

0x1C4

0x1C5

2 Byte

Word

0xBF

Ending Sector

As with the Starting Sector, it only uses the first 6 bits of the byte.  The upper 2 bits are used by the Ending Cylinder field.

0x09

Ending Cylinder

Uses 1 byte in addition to the upper 2 bits from the Ending Sector field to make up the cylinder value.  The Ending Cylinder is a 10-bit number with a maximum value of 1023.

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

0x1C6

32 Bits

0x3F000000

Relative Sectors

The offset from the beginning of the disk to the beginning of the volume, counting by sectors.

0x0000003F = 63

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

 

0x1CA

32 Bits

0X4BF57F00

Total Sectors

The total number of sectors in the volume.

0x007FF54B = 8,385,867 Sectors = 4GB

000001B0:                                             80 01

000001C0: 01 00 07 FE BF 09 3F 00 - 00 00 4B F5 7F 00

 

Are you with me so far?  Good!  Now, Cylinder/Sector encoding can be a bit tricky, so let’s take a closer look. 

 

Cylinder - Sector Encoding

16

15

14

13

12

11

10

9

8

7

6

5

4

3

2

1

Cylinder bits 1-8

Cyl bits

9 & 10

Sector value

Bits 1-6

 

As you can see, the Sector value occupies the lower 6 bits of the word and the Cylinder occupies the upper 10 bits of the word.  In our example, the starting values for Cylinder and Sector are 01 00.  Values in the MBR use reverse-byte ordering, which is also referred to as ‘little-endian’ notation.  Therefore, we swap the bytes and find that our starting values are Cyl 0, Sec 1.

 

Our ending values are more interesting:  BF 09.  First, we swap the bytes and obtain a hex value of 0x09BF.  This value in binary notation is 100110111111.  The following table illustrates how we derive the correct partition table values from these bytes:

 

Example:  BF 09

8

7

6

5

4

3

2

1

10

9

6

5

4

3

2

1

0

0

0

0

1

0

0

1

1

0

1

1

1

1

1

1

10 Cylinder value bits 1-8

Cyl bits

9 & 10

Sector value

bits 1-6

 

The 6 low bits are all set to 1, therefore our Sector value is 111111 or 63.   You can see above how the bits are arranged for the Cylinder value.  The value above is 1000001001 (521).  Since both Cylinder and Head values begin numbering at zero, we have a total of 522 Cylinders and 255 Heads represented here.  This gives us an ending CHS value of:  522 x 255 x 63 = 8,385,930 sectors. 

 

Subtracting the starting CHS address (Cylinder 0, Head 1, Sector 1) (63) gives us the total size of this partition:  8,385,867 sectors or 4GB.  We can verify this number by comparing it to the Total Sectors represented in the partition table:  4B F5 7F 00.  Applying reverse-byte ordering gives us 00 7F F5 4B which equals 8,385,867 sectors.

 

So, now that we have an understanding of what is contained within the structures on the disk, let’s look at the sequence of events that occur.  Remember, this is just after POST has successfully completed.

 

1.       The motherboard ROM BIOS attempts to access the first boot device specified in the BIOS.  (This is typically user configurable and can be edited using the BIOS configuration utility.)

 

2.       The ROM BIOS reads Cylinder 0, Head 0, and Sector 1 of the first boot device.

 

3.       The ROM BIOS loads that sector into memory and tests it.