• subscribe
January 01, 1999 12:00 AM

Inside the Boot Process, Part 2

Windows IT Pro
InstantDoc ID #4711
Learn how NT initializes

In November, I began this two-part series on the Windows NT boot process. I described the way NT's Setup program prepares a hard disk for a boot by placing NT code in the disk's Master Boot Record (MBR) and boot sectors. When the system boots, the NT code loads the NTLDR boot file and executes the file's code. NTLDR is responsible for the pre-NT Kernel portion of the boot; part of NTLDR's responsibility is to prepare a data structure with information about the system and to construct the HKEY_LOCAL_MACHINE\HARDWARE and HKEY_LOCAL_MACHINE\SYSTEM Registry keys. NTLDR later gives this information to the Kernel, together with images for hal.dll and the boot-start device drivers.

This month, I resume my description of the boot process at the point at which NTLDR has finished its role in the boot by calling the NT Kernel's entry point. I'll walk you through the rest of the boot process, including the initialization steps each Executive subsystem takes. I'll describe how and when device drivers from each of the start categories--­Boot, System, and Auto--­initialize. I'll conclude by describing how the Kernel finishes a boot by loading user-mode code that presents the logon screen display and launches the Win32 subsystem. The sidebar "Windows 2000 and the Boot," page 60, explains how the NT boot process will change in Windows 2000 (Win2K--­formerly NT 5.0).

Initializing the Kernel and Executive Subsystems
The NT Kernel goes through two phases in its boot process: phase 0 and phase 1. Phase 0 initializes just enough of the Kernel and Executive subsystems so that basic services required for the completion of initialization become operational in phase 1. NT keeps interrupts disabled during phase 0 and enables them before phase 1. Most Executive subsystems implement their initialization code by having one function take a parameter that identifies which phase is executing.

The function responsible for orchestrating phase 0 is called ExpInitializeExecutive. This function starts by calling the hardware abstraction layer (HAL) function HallnitSystem. HallnitSystem gives proprietary versions of the HAL that various OEMs develop a chance to gain system control before NT performs significant initialization. One HallnitSystem responsibility is to prepare the system interrupt controller for interrupts and to configure the clock tick interrupt. When HallnitSystem returns control, ExpInitializeExecutive proceeds by honoring the /BURNMEMORY BOOT.INI switch (if the switch is present in the selection the user made in the boot.ini file for which installation to boot) and discarding the amount of memory the switch specifies. Next, ExpInitializeExecutive calls initialization routines for the Memory Manager, Object Manager, Security Reference Monitor, and Process Manager. The Memory Manager gets the ball rolling by constructing page tables and internal data structures that are necessary to provide basic memory services. The Memory Manager builds and reserves an area for the system file cache and creates memory areas for the paged and nonpaged pools. The other Executive subsystems, the Kernel, and the device drivers use these two memory pools for allocating their data structures.

After the Memory Manager finishes phase 0, ExpInitializeExecutive prints the text Microsoft (R) Windows NT (TM) Version 4.0 (Build 1381) to the initial blue screen you see during a boot. Build 1381 is the build number for NT 4.0 without service packs. For NT 4.0 with service packs applied, text similar to Service Pack 3 follows the build number on the initial blue screen. The system obtains the service pack number from HKEY_LOCAL_MACHINE\SYSTEMCurrentControlSet\Control\Windows\CSDVersion, where the number is encoded as a hexadecimal value that can identify interim service packs (e.g., Service Pack 1a).

During phase 0 of Object Manager initialization, NT defines the objects that are necessary to construct the Object Manager namespace so that other subsystems can insert objects into it. NT also creates a handle table so that resource tracking can begin. The Security Reference Monitor initializes the token type object and then uses the object to create and prepare the first token for assignment to the initial process. The last Executive subsystem to initialize in phase 0 is the Process Manager. The Process Manager performs most of its initialization in phase 0, defining the process and thread object types and setting up lists to track active processes and threads. The Process Manager also creates a process object for the initial process and names it Idle. As its last step, the Process Manager creates the System process and launches a thread for this process that will direct phase 1 initialization in the Kernel's Phase1Initialization function.

When control returns to it, ExpInitializeExecutive has become a thread in the Idle process and immediately becomes the system's idle thread. ExpInitializeExecutive sets its priority to 0 (the lowest possible) and begins executing a loop that will run only if no other thread in the system can run.

Phase 1 starts when Phase1Initialization calls the HAL to prepare the system to accept interrupts from devices and to enable interrupts. Phase1Initialization notes the time and stores it as the time the system booted. Up to this point, only one CPU has been active. In a symmetric multiprocessing (SMP) system, the boot process has left other CPUs off. Now, with the aid of the HAL, Phase1Initialization turns on the remaining CPUs. NT prints text similar to 2 System Processors [128 MB Memory] Multiprocessor Kernel to the blue screen after all CPUs have initialized.

Phase1Initialization continues by calling every Executive subsystem in the order Table 1 shows, so that they can execute phase 1 initialization. The order in which Phase1Initialization calls the subsystems is important because of system interdependencies. For example, the Executive must define type objects like mutexes, semaphores, events, and timers because other subsystems use these objects.



ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Jan 11, 2005

    This article is extremely useful and I'd like to give my utmost gratitude to the writer who writes such a wonderful and informative article. I'm not that expert to understand certain difficult parts of this article, but here's a simple question: Since SMSS loads the win32 subsystem only after the BootExecute programs, this means the programs loaded through BootExecute are not able to use the win32 functions, right? In order to create programs that run before the win32 subsystem loads, such programs must avoid the usage of win32 functions, and thus programs of VB6 are not executable in that phase, right? If it's true, then how should I create my programs? I am thinking of MS-DOS programs. Please correct me as I'm not an expert in this area.

  • ts taylor
    8 years ago
    Apr 28, 2004

    i would like to thank you for this article. although this is the most informative piece i have been able to find on the steps the computer takes to boot, i also need to know what happens once a user clicks on their picture on the welcome screen & logon begins...ending with the desktop/taskbars loaded. i have been trying to figure out what is going on with my "boot/logon" processes in my XP home OS to pinpoint whatever is not loading preventing my desktop, taskbars, & start menu along with many other things on my system from functioning like user accounts, system info, help, device manager, etc. if there is a subsequent article to this explaining logon steps, i would appreciate it if you would contact me by email and let me. thank you again for this wonderful article. tst

  • Nguyen Manh Thang
    9 years ago
    Nov 06, 2003

    Please send me some information about boot process when loading,initialization ,installation driver in WIN NT

  • Shailendra Shenoy
    13 years ago
    Aug 06, 1999

    In Mark Russinovich’s NT Internals: “Inside the Boot Process, Part 2” (January 1999), the author states that the Service Control Manager (SCM) deems a Windows NT boot successful after the SCM successfully initializes Auto Start services and drivers. He goes on to say that after NT creates the LastKnownGood control set, the Winlogon process presents the logon dialog box, which ends the boot process.
    However, the Microsoft Windows NT Server 4.0 Resource Kit says that an NT boot is complete only after a user successfully logs on to the system. NT copies the Clone control set (in HKEY_LOCAL_
    MACHINE\\SYSTEM) to the LastKnownGood control set. This step is important because if an NT boot fails and the user has not yet logged on, NT can successfully invoke the Last Known Good configuration the next time the system starts. But if the system crashes just after the user logs on, the Last Known Good menu might not help.
    In the author’s description of the NT shutdown process, he does not discuss stopping the SCM services (the part of the process that takes up most of the time during shutdown). Do the Memory Manager and Configuration Manager flush data to disk before or after the services shut down?

    --Shailendra Shenoy



    I was unclear in the article about when NT copies the Clone control set. The resource kit documentation is correct: NT copies the key only after all services have successfully started and a successful logon takes place. To answer your question, services shut down before the final cleanup by kernel-mode components.

    --Mark Russinovich

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...