Have you ever thought of how your operating system (Windows) is loaded? It’s quite interesting to know about the miniature details that are involved in the process. This article will shed some light on this topic.
The actual execution of the processor begins when you power on the system. Following are the major steps involved.
- BIOS performs some initial check and read the Zero sector of the hard disc, This Zero sector has a special name - MBR(Master Boot Record).
- MBR contains two sections:
- Boot Code (446 bytes)
- Partition Table Entries (16 bytes colored entries in the bottom)
- The purpose of boot code is to iterate over all the partition table entries and check for a bootable partition (if the first byte of the partition entry is 0x80, then it is a bootable partition. Also called as boot partition or system volume). (There can be only four entries specified in the MBR, does it mean we are limited with 4 drives ?) (this is where extended partitions come into the picture).
- Now besides locating the boot partition, it will know exactly from which sector the boot partition begins. This is done by examining the 8th-12th bytes in the partition entry (so in the above picture 3f 00 00 00 converted to little endian we get 0000003f = 63rd Sector). In general, it will be 63rd sector.
- Again the first sector (63rd) of the bootable partition is called as Boot Sector which contains enough code to read a special file named ntldr (NT loader) from the root (c:\) drive. This is the time where you may at times see “NTLDR is missing” error message. Following are the tasks performed by ntldr.
- The main purpose of ntldr is to setup the stage for the windows kernel to load.
- It enables paging and preliminary hardware detection using BIOS routines(int) and ntdetect.com
- Reads boot.ini to display boot menu.
- If the system is hibernated during the last shutdown, it will resume from hiberfil.sys.
- Most importantly, it loads boot start drivers (these are the core drivers for proper functioning of OS). Following are the examples for boot start drivers:
- Sets CPU registers, etc., and pass on the control to ntoskrnl.exe (NT OS Kernel). This ends the life of ntldr.
- Ntoskrnl is mainly responsible for setting up the following OS services (here, you will see Windows XP logo progress bar).
- Phase 0 Initialization
- Memory Management Services
- Process Management Services (First kernel mode process the system process is created)
- Object Manger Services
- Plug and Play Management Services
- Security Reference Monitor Services
- Phase 1 Initialization
- Hal initialization (Hardware Abstraction Layer)
- Multi processor support
- Scheduler support (inherently dependent on processor architecture)
- Power management
- Now the control is passed on to smss.exe (Session Manager Subsystem). It is the first user mode process that is created in the life span of windows.
- The following are the tasks performed by smss process:
- Runs check disk (disc check):
- Pending file copy and file deletes (some softwares need to overwrite the files which are in use by the OS and they will ask you for reboot) and this is the phase where those pending copy and deletes will be performed.
- Page file is created (pagefile.sys):
- Loads registry hives from \Windows\System32\Config\*.*.
- Finally, it creates two processes csrss.exe (Client Server Run-Time Subsystem), Winlogon.exe.
- Csrss.exe is responsible for user mode functionality of the system and sits as an interface for windows API)
- Winlogon.exe is responsible for starting all auto-start services (services.exe) and creating the lsass.exe (Local Security and Authentication Subsystem) this process is for authenticating the user logins
- Next winlogon will show the logon screen to the user, upon successful logon winlogon will load the explorer.exe under the current user profile. This is where you will see the desktop.
Though the actual process involves more complicated steps, I have oversimplified the overall flow in favor of novice users and tried not to lose the brevity of the content. Please feel free to comment on the post. Positive criticism is most welcome.
- Windows Internals 4th Ed By Mark E. Russinovich, David A. Solomon
Hello, This is Vineel Kumar Reddy Kovvuri, I am interested in Systems Programming, love to tinker with low level functionality of Windows and Linux. Works for NVIDIA,