2016 Microcomputer and Applications Issue 3 Author: Yuan Qianqian
Abstract: This article provides a detailed study of the computer boot process and system loading, combining the collaborative invocation mechanism between hardware and software. It presents a relatively complete discussion of the entire process from pressing the power button to loading the operating system, culminating in the appearance of the boot interface. This is very helpful for beginners to gain a comprehensive understanding of the boot process.
0 Introduction
For most people not related to computer science, their understanding of computers is limited to mastering basic operations, and they do not have a deep understanding of the internal operating principles. Exploring the boot process can help them gain a deeper understanding of computers. From powering on to the appearance of the operating interface, the computer undergoes a series of complex processes. First, the computer must detect and configure all critical hardware devices in a specific order, then load the operating system from the storage device according to the boot sector, and further complete system initialization. Understanding the computer boot process helps users enhance their daily maintenance of computers, improve boot speed by upgrading hardware performance, and provides those interested in exploring computer science with a preliminary understanding of the operating mechanisms of computers.
1 Power-On Self-Test
The initialization boot process of the computer is called bootstrapping or “Boot”. The term originates from a paradox: to start the computer, it must first run a program, but without running, the computer cannot start. How to start the computer was once a mystery. After a long period, engineers found various ways to overcome this paradox. By writing the boot program into memory, they linked the self-test of the computer with the loading of the operating system, allowing the computer to start and run normally.
1.1 CPU Preparation
When the power button is pressed, the power supply begins to provide power to the motherboard and other devices. Initially, due to unstable voltage, the control chipset on the motherboard sends and maintains a positive pulse signal, known as the RESET signal, with a width greater than 2 ms to the CPU. After about 100 to 500 ms, the power supply stabilizes and generates a logical signal. When the chipset detects this signal, it removes the RESET signal. The Central Processing Unit (CPU) begins reading instructions from address FFFF-0000H, and the Basic Input and Output System (BIOS) uses the jump instruction stored here to find its actual boot code thread, starting a series of detection and configuration tasks.
1.2 Basic Functions of BIOS
The BIOS plays a crucial role in the computer system as the low-level code that interacts directly with hardware. It stores the most important basic input/output programs, power-on self-test programs, and system auto-start programs. It is powered by a special battery on the computer motherboard, reading and writing specific information about system settings from the Complementary Metal Oxide Semiconductor (CMOS), providing basic functions for controlling hardware devices. The BIOS includes system BIOS (mainboard BIOS), graphics card BIOS, and BIOS for other devices (such as integrated drive controllers, small computer system interface cards, or network cards). BIOS is usually stored in Read Only Memory (ROM), which can permanently retain data and program information, even if the machine loses power.
1.3 BIOS Detection Process
The boot code of the system BIOS first performs a hardware self-test (Power-On Self-Test, POST), mainly checking whether some key devices in the system exist and function properly, such as memory and graphics cards. Since the graphics card has not yet been initialized, if hardware issues are found during the self-test, the system will emit beeping sounds, with the duration and number of beeps indicating different types of errors. If no errors occur, the POST process will quickly end, and other codes will be called for more thorough hardware testing.
Next, the system BIOS will look for the graphics card’s BIOS (at address C0000H), and after finding it, it will call its initialization code to initialize the graphics card. For most graphics cards, some initialization information will be displayed on the screen, such as manufacturer and model information, but it will almost flash by. The system BIOS will then look for the BIOS programs of other devices and call their initialization codes to initialize the relevant devices. Finally, the system BIOS will display its own startup screen, listing the type, serial number, and version number of the system BIOS.
Next, the system BIOS will detect and display the type and operating rate of the CPU, then test all Random Access Memory (RAM), displaying the progress of the memory test on the screen. After the memory test passes, the system BIOS will begin to detect some standard hardware devices installed in the system, including hard drives, CD-ROMs, etc. Next, it will detect and configure the Plug and Play devices installed in the system, displaying the detected device names and model information, and allocating available resources for these devices.
After all hardware devices have been tested, the screen will display various resources and related working parameters used by standard hardware devices. Then, the system BIOS will update the Extended System Configuration Data (ESCD), which the system BIOS uses to exchange hardware configuration information with the operating system. This data is stored in the CMOS, and the ESCD data is usually only updated when the system hardware configuration changes.
2 Master Boot Record
Once the hardware self-test is complete, the system BIOS’s operation interface will display the user-specified boot device order. The listed external storage devices can be floppy disks, hard drives, or CDs. The devices listed first have priority control, and the BIOS reads the Master Boot Record (MBR) from the devices in the boot order, loading it into memory address 7C0000H, and looking for the next information to read from the MBR.
2.1 Structure of the Master Boot Record
The Master Boot Record is located on the first sector of the zero cylinder and zero head of the hard drive, totaling 512 B. If the last two bytes of this 512 B are 55AAH, it indicates that this device is bootable; if not, it indicates that the device cannot boot and must transfer control to the next device in the boot order table. The byte code meanings of the standard MBR are shown in Table 1.
2.2 Partition Table
After finding the Master Boot Record, the system begins to read the valid partition table. The length of the partition table is 64 B, subdivided into four primary partitions, each occupying 16 B. There are many benefits to partitioning a hard drive, allowing different operating systems to be installed in different partitions, achieving multi-system coexistence. The Master Boot Record determines whether a primary partition is active by checking the first byte of the partition table, with only one active partition among the four primary partitions. The structure of the partition table is shown in Table 2.
As shown in Table 2, the number of sectors occupied by the primary partition totals 4 B, so the maximum number of sectors for a primary partition is 232. If each sector is 512 B, then the maximum for each partition is 2 TB (1 TB = 240 B). The logical address of the sector also occupies 32 bits, so the maximum usable space of the hard drive is 2 TB. Therefore, if you want to expand hard drive space, there are two methods: one is to increase the number of bytes per sector, and the other is to increase the total number of sectors. Currently, hard drive storage capacity has reached the 3 TB stage, and related technologies continue to develop, with storage capacity expected to increase further.。
3 Hard Drive Boot
3.1 Booting the Hard Drive Through the Primary Partition
The computer reads the first sector of the activated partition’s Volume Boot Record (VBR), also known as the volume boot sector or partition boot record, by finding the corresponding VBR through the logical address of the primary partition. If the storage device has not been partitioned, such as a floppy disk, the VBR is located in the first sector of that device. The VBR contains a lot of information, such as the number of bytes per sector, the number of sectors per cluster, the size of the reserved area, the number of files in the File Allocation Table (FAT), the size of each FAT in sectors, and the location of the cluster storing root information. Through the VBR, the system BIOS can find the specific location of the operating system in this partition, and then the computer will begin to look for address information to load the operating system. The entire logical structure of the hard drive can be seen in Figure 1.
3.2 Booting the Hard Drive Through the Extended Partition
Among the four primary partition tables, only one can be defined as an extended partition (EP), which can contain multiple logical partitions. The computer first reads the first sector of the extended partition, which is the “Extended Boot Record” (EBR), which contains a 64 B partition table. The extended partition can contain an unlimited number of logical partitions. However, computers rarely choose this method to boot the operating system. If the operating system is installed in the extended partition, it generally chooses to boot the operating system via the boot manager.
3.3 Booting the Hard Drive Through the Boot Manager
In this case, the computer does not transfer control to a particular partition when reading the MBR, but runs a pre-installed boot manager, allowing the user to choose which operating system to boot. In Linux systems, the boot manager (Grand Unified Bootloader, Grub) uses the first 446 B of the MBR as its starting execution program, allowing the selection of different kernels on the operating system partition and passing boot parameters to these kernels.
3.4 File System
In the operating system, the subsystem related to files and directories is called the file system, which is used to organize and manage files. It organizes storage space into physical locations and provides a mechanism to index the data stored within. It also establishes a hierarchical index relationship, converting the physical partitions of the disk into logical partitions, and allocating data to the positions within the logical partitions. The commonly used file systems in Microsoft systems include FAT16, FAT32, and NTFS (New Technology File System).
FAT16, the 16-bit File Allocation Table, is the most widely used file system, where disk file allocation is based on “clusters”. Regardless of the proportion of the file to the total capacity, each cluster corresponds to one file, and it can only support partitions up to 2 GB, leading to low disk space utilization. With the improvement of computer hardware performance, Microsoft introduced the enhanced file system FAT32, which can support a maximum disk size of 2 TB and uses smaller clusters to store information more efficiently. The FAT32 file system can relocate the root directory and use backup copies of the FAT, and its boot record is included in a structure containing key data, reducing the risk of system crashes. NTFS emerged with Microsoft’s NT operating system, offering strong security and stability, making it less prone to file fragmentation. NTFS can support file sizes up to 64 GB, far exceeding the 4 GB limit under FAT32, and it can support long file names.
4 Loading the Operating System
Once the operating system is determined, its kernel is first loaded into memory for system initialization and loading device drivers. In Linux systems, the operating system kernel located in the /boot directory is loaded first. The kernel, being the core part of the operating system, mainly functions to control and manage event scheduling and synchronization, inter-process messaging, memory management, and process management. Once the disk file system is mounted and the kernel loads successfully, it first runs the program in /sbin/init, which generates the init process based on the configuration file. This is the first process after Linux starts, setting the process identification number (PID) in the process control block to 1, with all other processes created afterward being its child processes. The init thread then begins to load various system modules, such as window programs and network programs, and finally executes the /bin/login program, presenting the login interface. After successfully logging in, the system boot process is completed smoothly, and the user can proceed with normal daily usage.
5 Conclusion
The computer boot process involves knowledge of the underlying hardware and system software. Understanding the entire process can enhance one’s understanding and maintenance of computer systems. If problems occur during the computer startup process, users can analyze the issues based on the different stages and find solutions to successfully run the computer.