Tech In-Depth: System Booting

The Operating System Takes Charge
After the hardware part of the boot sequence has finished, what is loaded next is the operating system. If you have only one operating system, it is easy, because the computer knows immediately how to proceed. If you have more than one operating systems — i.e. Windows and Linux, or two or more Windows or Linux varieties, all this is written in the boot configuration and it takes one more step to load the Windows (or respectively) Linux boot loader and then to choose which of the available varieties of Windows (or Linux) to load.


Basically, the process of loading the operating system involves loading the kernel in memory, loading device drivers, starting services and finally presenting the user with a login screen or a login prompt, if it is not a GUI.  A kernel is a software layer that exists between your hardware and operating system to coordinate the two. It is useful to know what services are loaded at startup because this way you can remove some services (not the core ones, of course) and make your computer boot faster. The process of loading the operating system differs under Linux and Windows and that is why the boot sequence for both operating systems is described separately in the next two sections.


Windows
There are several stages in the Windows boot sequence. NTLDR is the boot loader for Windows for Windows 2000, XP, 2003 (under Vista its functionality is divided between winload.exe and the Windows Boot Manager). NTLDR is located in the root directory of the Windows system partition. NTLDR requires the boot.ini file, where configuration options about the boot process are written. NTLDR goes through the following four phases before the user is presented with the login screen:



  1. Initial Boot Loader Phase. The tasks that NTLDR performs at this stage are memory initialization to enable full memory addressing, as well as initialization of the file system on the primary boot drive. On the primary boot drive NTLDR looks for boot.ini.


  2. Selecting which operating system to load. The boot.ini file contains boot settings, such as a list of available operating systems and instructions, timeout before loading the default operating systems and so on. If you have only one Windows variety installed, it will be booted automatically but if you have two or more Windows varieties coexisting on your computer, you will be presented with a screen where you can select which of them you want to load.

    If you are running Windows 2000, XP, or 2003, you can press F8 to interrupt the boot sequence and display a list of several options for special cases like Safe Mode or Last Known Good Configuration. Safe Mode loads only the most essential drivers and services, while Last Known Good Configuration loads the latest working configuration. Both options are very useful after an unsuccessful driver or application installation, or a malware infection which prevent you from properly logging into Windows.


  3. Hardware initialization. The next step in the boot sequence for Windows 2000, XP and 2003 is detection of the installed device drivers and initialization of the respective pieces of hardware. If you have more than one hardware profiles, you will be presented with a screen to choose which one you want to load. If you have only one hardware profile, it will be booted automatically.


  4. Configuration loading. After the hardware has been initialized and the appropriate hardware configuration is loaded, some additional drivers, namely of boot devices, are loaded as well. Then the next step is loading the kernel. After that, core subsystems, like the Object Manager, the I/O Manager, and the Process Manager are started as well. Then all services that are labeled for auto start are started and if everything goes smoothly, the user is presented with a login screen and this boot sequence is saved as the Last Known Good Configuration. If there are problems at this stage, you may see your Windows halted or rebooted, especially if it is a device driver failure.


The above presentation of the boot sequence in Windows was brief, and it covered the main points only. If you need more information, for instance a list of which services are started and in what order, you can find it on the Microsoft website. Now that we have briefly examined the boot sequence for Windows, let’s see how it works for Linux. }


Linux
The boot sequence under Linux is very different from the boot sequence under Windows. Under Linux there are two boot loaders — GRUB (GNU GRand Unified Bootloader) and LILO (LInux LOader). LILO is the older boot loader, but it is still used by some distributions (distros), while GRUB is newer, and more and more distros use it. There are some slight differences in the boot procedure between the two boot loaders and also among distros, but the major steps, which are described next, are the same for all Linux distros.


Basically, the procedure involves starting the OS loader, which locates the kernel image on disk. Then the boot loader loads the kernel into memory and starts it. After that, the kernel initializes the devices and their drivers, mounts the file system and starts the init program. The init program, in turn, starts the rest of the processes, including the process that allows the user to login. In many distros on screen messages inform you what is going on at any moment of the boot sequence. In more details, here is what happens:



  1. OS Loader. As already mentioned, the MBR is responsible to tell the BIOS which operating system to load. But the tiny size of the MBR (512 bytes) does not allow the OS loader itself to reside there. Instead, the primary loader is in the MBR, but its function is only to provide information about the location of the secondary loader, which is located on the specified disk partition. Thus, LILO and GRUB can be installed on the primary (DOS) loader, which will be pointing to them and everything works just fine — when you select them from the boot screen, they start, locate the kernel and load it. Very often it is possible to configure the boot loader to load an alternative kernel or to pass additional parameters to it.


  2. Kernel startup. After the OS loader has loaded the kernel in memory, the kernel initializes the devices (i.e. loads their drivers) and you will see the messages about that on screen. Then the kernel starts the swapper and mounts the root file system. It is possible to pass parameters that override the default file system and mount another one. Right after the root file system has been mounted, the kernel starts the init process and then it starts the system services.


  3. init and inittab. The init process is the first process that the kernel starts and because of this it always has a PID (Process ID) of 1. After the init process is started, it reads /etc/inittab for further instructions what to load. inittab defines what should be run in different runlevels. Runlevel is a key concept in the Linux boot process because each of the 7 runlevels (from 0 to 6) define a different set of services that need to be started.    Each runlevel has a separate directory (under the /etc/rc.d/ directory) with many boot scripts that are to be executed, when the particular runlevel is selected.


  4. Boot scripts. The location of the boot scripts directory and their structure differs between the distros, so you’d better consult the documentation of your distro if you can’t find the scripts directory right away.  Runlevels and boot scripts provide incredible flexibility in customizing the Linux boot process. Boot scripts define at least the start and stop options for a particular service, though very often it is possible to pass the service additional commands and parameters and to define the sequence in which services will be started. The last service that is started is the login process, which presents the user with a login screen (or prompt, if you are using a non-graphical environment).


Describing the Linux boot sequence fully, involves more details outside the scope of this article, so if you need more information about the process in general or about the process for a particular distro, see the Linux Documentation Project or the documentation of your distro. There you can read how to configure GRUB and LILO, what options are available for passing, what is the meaning of each of the runlevels and how to configure them, what kinds of modifications are possible for the boot scripts, etc.


In short, this is how the boot process works from the minute you press the power button until the Operating System loads up and is ready for your input.

Opt In Image
Free Weekly PCMech Newsletter
Almost 500 Issues So Far, Received By Thousands Every Week.

The PCMech.com weekly newsletter has been running strong for over 8 years. Sign up to get tech news, updates and exclusive content - right in your inbox. Also get (several) free gifts.

Pages: 1 2 3

Leave a Reply

PCMech Insider Cover Images - Subscribe To Get Your Copies!
Learn More
Tech Information you can use, sent to your inbox each and every week. Check out PCMech's digital e-zine...