Discussing computer storage 6. Operating System Startup Process

Source: Internet
Author: User

Discussing computer storage 6. Operating System Startup Process
<For more information about en.wikipedia.org, see Wikipedia>

Papayas

20080903

Preface

This article is the last article of this series, mainly introduces the MS-DOS, various types of Windows and Linux
It takes so long for the operating system to understand the complete process of startup.

1. MS-DOS Startup Process

When the PC is started, read the first sector of the boot disk and execute the boot code. If the DOS Boot Sector is found,
The first three sectors of Io. sys are loaded into the memory, and PC control is handed over to Io. sys (input and output module ).
 
Io. sys takes control of the computer and performs the following operations:
 
First, load other parts of Io. sys to the memory, and initialize each default device accordingly.
Then load the MS-DOS Kernel File msdos. sys, but in MS-DOS 7.0, msdos. sys
To start the configuration file
In addition, to process the config. SYS file, config. sys is an important configuration file and can be edited.
File

Content example:

Device = C:/dos71/echo. sys w/e/L/C/O/M/E ..
Device = C:/dos71/echo. sys c/o/P/y/R/I/g/h/T ..
Device = C:/dos71/himem. sys
...
Shell = command. com/P/E: 640
...
Set Path = C:/dos71 ;..;

Note: The shell line indicates that the shell environment uses command.com, And the startup path is C:/dos71. The Environment
The size is 640 bytes./P indicates that this is the parent process and cannot be closed or exited using exit. For more details, see
Test wiki.

Load the corresponding shell according to the config. sys configuration, the MS-DOS is generally command. com
When processing command. com, the autoexec. bat batch processing script is called.

Commands in autoexec. bat can be executed in the shell environment. The main function is to set some environment changes.
Quantity. Such as the keyboard and sound card. At the same time, some low-level system tools, such as disk cache, mouse drive,
Keyboard driver. The command prompt is displayed.


2. Windows Startup Process Based on MS-DOS

The MS-DOS is responsible for Windows 3.x/ 95/98/me pre-boot. In the startup phase, process config. sys and execute autoexec. bat.
The configuration files win. ini and system. ini are read, and the corresponding Virtual Device Driver (from system. ini or
HKLM/system/CurrentControlSet/services/VxD ). After all system configuration files and device drivers are loaded
The vxdmessage Service (msgsrv32133) will start mprexe.exe to prepare user logon and network logon. When a user logs on to Windows
After that, the system will go to Windows.

MS-DOS-based Windows, you can start Windows manually by typing win at a command prompt to start dos.
In this case, the win.com file is actually called.
For details about the startup process, see the article "Win 98 system startup process full secrets.
Http://blog.csdn.net/liwei_cmg/archive/2008/09/15/2931385.aspx
 
Iii. Startup Process Based on Win NT Operating System

Windows. Boot Process
As follows:

On the x86 or x64 platform, the computer starts and loads ntldr in real mode. Ntldr is a binary file with two parts
Components: startup module and OS loader. The main task of startup module is to switch the computer to the protection mode.
OS loader mainly includes the basic functions of identifying partition file systems (such as fat and NTFS) that access the IDE hard disk.
You also need to load the ntbootdd. SYS file to obtain the corresponding SCSI driver.
The boot program then reads the boot. ini configuration file and displays the user-selected operating system menu. If boot. INI is lost, the system will
The default value is C:/windows.
At this time, ntldr of Windows 2000 and later versions will look for hiberfil. sys (Sleep file, which is the same as memory size)
Is the memory image of the last operating system sleep), read the file and load the memory.

Example of boot. ini file content:
 
[Boot loader]
Timeout = 30
Default = multi (0) disk (0) RDISK (0) Partition (1)/Windows
[Operating systems]
Multi (0) disk (0) RDISK (0) Partition (1)/Windows = "Microsoft Windows XP Professional"/noexecute = optin/fastdetect
 
Multi (a) disk (B) RDISK (c) Partition (d) is the key to adopting the arc naming rules. Used in the first part of Arc
Indicates the hardware adapter (disk controller), that is, the multi or SCSI option. Here, the Multi option is used. Multi indicates a non-
A scsi hard disk or a SCSI hard disk accessed by the SCSI bios, while SCSI indicates a SCSI hard disk prohibited by the scsi bios.
(A) indicates the serial number of the disk controller, starting from 0.
Disk (B), which is only valid for multi items. It indicates the hard disk serial number of the disk controller and is enabled from 0.
RDISK (c) indicates the serial number of the hard disk of the disk controller, starting from 0.
Partition (D), indicating the corresponding Hard Disk Partition Number, starting from 1.

Note: When only one operating system is selected, the Start menu is not displayed. Select the operating system.
In the operating system of NT, ntldr reads bootsect. Dos and delivers control of the computer. If you select NT-based
Then ntldr executes ntdetect.com to collect hardware information. At this time, ntldr is cleared and displayed
Windows Startup progress bar. If you press F8, the Advanced Startup menu, including safe mode options, is displayed.
 
After collecting all the relevant hardware information, connect to start ntoskrnl.exe (NT operating system kernel file) and read and load the hardware
File abstraction layer (Hal. dll ). If a file is lost, the system prompts "Windows cocould not start because the following file ".
Was missing or cancel upt "and terminate the startup. At this time, the system control is handed over to the kernel and the Windows logo is displayed.

When the kernel is loaded, the information of the hardware device that is started is stored in HKLM/system. You can see that a series of key values constitute the control set,
For example, controlset001, controlset003, controlset004, and CurrentControlSet. Use CurrentControlSet for Windows
Read and access the current information. During Windows Startup, use HKLM/system/select to determine the corresponding key value.
Default ntldr is selected by default. If the failed value is equal to the default value, ntldr displays an error message and prompts
Whether the menu is started with the last correct configuration information (lastknowngood). If you choose lastknowngood, default
The value is also changed to the value of lastknowngood.

Kernel startup process:
Ntoskrnl.exe Kernel
Hal. dll Hardware Abstraction Layer
Kdcom. dll kernel debugging extension DLL
Bootvid. dll Windows logo and progress bar display
Configure Information Registry location
HKLM/system/CurrentControlSet/control/Session Manager/bootexecute
HKLM/system/CurrentControlSet/control/servicegrouporder starts the service in the corresponding order.
The progress bar is displayed. The progress bar of earlier versions of Windows 2000 reflects service loading. Server 2003 and XP mean
Think about it. service loading is asynchronous.

After all the device drivers are ready, ntoskrnl.exe starts session manager subsystem (smss.exe ).
Before a file is opened, smss.exe starts autochk. Autochk mounts all the drivers and checks whether they are normal,
Whether the last shutdown is complete or not. Otherwise, chkdsk will be started for scanning and repair, which is our common check disk. Session Manager Subsystem
Configuration information: HKLM/system/CurrentControlSet/control/Session Manager.
 
During startup, the process of smss.exe is as follows:
Create the environment variable HKLM/system/CurrentControlSet/control/Session Manager/Environment
Start the kernel-state Win32 subsystem (win32k. sys) and allow windows to switch to a graphical system.
Start user-state Win32 subsystem Client/Server Runtime Server Subsystem (csrss.exe)
Create a Virtual Memory Page HKLM/system/CurrentControlSet/control/Session Manager/memory management
Start winlogon.exe and add graphical identification and authentication (Gina) to support user logon.
 
Winlogon startup process:
Winlogon calls Gina. A logon prompt is displayed. Enter the user name and password.
Winlogon starts Local Security Authority Subsystem Service (lsass.exe) to verify Logon
Winlogon starts Service Control Manager (SCM), and SCM is set to automatically started
 
After Winlogon, It is the user logon phase.
 
User Logon phase:
Update lastknowngood of control sets
The Group Policy of the user's computer is applied.
Start the application at the following locations:
HKLM/software/Microsoft/Windows/CurrentVersion/runonce
HKLM/software/Microsoft/Windows/CurrentVersion/policies/Explorer/run
HKLM/software/Microsoft/Windows/CurrentVersion/run
Hkcu/software/Microsoft/Windows NT/CurrentVersion/Windows/run
Hkcu/software/Microsoft/Windows/CurrentVersion/run
Hkcu/software/Microsoft/Windows/CurrentVersion/runonce
All users profilepath/Start Menu/programs/startup/
Current user profilepath/Start Menu/programs/startup/
 
 
The Windows NT format command writes the volume Boot Record to the disk to run the ntldr program.
In Windows Vista and Windows Server 2008, ntldr is not used, and it is replaced by winload.exe and windows
Replaced by Boot manager.
 
4. Windows Vista Startup Process

Wiki start preview of Vista:
BiOS> Master Boot Record> Boot Sector> Windows boot Manager> read from BCD>
Search for hibernation file> Start winload.exe> Start ntoskrnl.exe> Start smss.exe>
Start winlogon.exe> Start services and login interface

The Startup Process of Vista is slightly different from that of the operating system of the NT kernel. The Boot Sector loads windows Boot manager.
(Bootmgr.), and then read the boot configuration data to start the operating system. Load the Boot Sector in the NT kernel
It is ntldr.

Boot configuration data is stored in a data file, which is usually stored in/boot/BCD of the system volume. Boot configuration data
You can use bcdedit.exe for editing.
 
Winload.exe is the operating system boot program, called by Windows Boot manager, and the ntldr function under NT is
.

V. Linux Startup Process

It is easy to find that the control of computer startup is changed as follows: BIOS-> boot loader-> kernel. Linux is no exception.
The previous article "Linux phone DIY. kernel of the system background startup Introduction" http://blog.csdn.net/liwei_cmg/archive/2006/11/28/1418109.aspx
I have also introduced Linux Startup, but it focuses on the actual code embedded on mobile phones. Here I just want to briefly describe the theoretical system.
To understand the detailed process of kernel startup, you need to have a comprehensive understanding of the kernel source code. At present, you lack this knowledge.
 
Startup Overview:
Host power-on to start BIOS
Boot Loader Stage 1 (MBR) Boot Loader Stage 2 (Lilo, grub ...)
Start the kernel (Linux)
Initialize Init (User)
 
Boot Loader stage:
Run the Boot Sector code in the system real-time mode. After some boot loader programs are loaded, the control is handed over to the boot program.
Linux boot programs are usually Lilo and grub. Then the Bootstrap program loads the remaining content into the memory and is ready to select the operations to be guided.
System.

<Grub>
Boot Loader Stage 1, BIOS reads and executes MBR, and then continues to boot loader Stage 2.
Boot Loader stage 2, control is already in the hands of grub, if this part of the code is on a large disk drive
Boot Loader stage 1.5 needs to be loaded, including support for over 1024 cylinders and LBA drives. Boot Loader stage 1.5
It can be stored in MBR or partition. Run Boot Loader stage 2 and display grub Operating System Selection
You can also modify the operating system environment and parameters. Grub supports access to the file system, and its configuration files are stored in
It is easy to adjust and modify the partition file system. The/boot/GRUB directory contains stage1, stage1.5, and stage2 grub.
Boot Loader and so on.

Note: Server Configuration instance (I). HP prolient ml570 server http://blog.csdn.net/liwei_cmg/archive/2007/05/20/1618174.aspx
This article introduces how grub cannot be guided.
 
Grub configuration file/etc/grub. conf, content example:
# Grub. conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# Notice: you do not have a/boot partition. This means that
# All kernel and initrd paths are relative to/, eg.
# Root (hd0, 0)
# Kernel/boot/vmlinuz-version Ro root =/dev/sda1
# Initrd/boot/initrd-version.img
# Boot =/dev/SDA
Default = 0
Timeout = 10
Splashimage = (hd0, 0)/boot/GRUB/splash.xpm.gz
Title Red Hat Linux (2.4.20-8)
Root (hd0, 0)
Kernel/boot/vmlinuz-2.4.20-8 Ro root = label =/
Initrd/boot/initrd-2.4.20-8.img

 
<Lilo>
Lilo is an old method that does not support file systems. Its Boot Code is directly stored in the MBR zone. Once the system is guided
After a failure, you can only use a floppy disk to recover the disk. Lilo reads data directly using bare devices and displays the menu
So that you can select and boot the operating system.

The lilo STARTUP configuration file is/etc/Lilo. conf. Content example:
Prompt
Timeout = 50
Default = Linux
Boot =/dev/SDA
Map =/boot/Map
Install =/boot. B
Message =/boot/message
Linear

Image =/boot/vmlinuz-2.4.20-8
Label = Linux
Initrd =/boot/initrd-2.4.20-8.img
Read-Only
Append = "root = label = /"
 
Kernel kernel stage:
 
The boot program loads the Linux kernel image into the memory. This kernel image is not an executable kernel and is compressed.
The later kernel is usually a zimage (less than 512 K) or bzimage (greater than 512 K), and zlib needs to be called for decompression.
When the kernel is loaded, some hardware settings are processed, and the kernel image is completely decompressed to the high memory area to load the RAM disk,
Then start the kernel.

<X86 series Execution Process>
The Linux phone DIY. kernel of the system background startup introduction http://blog.csdn.net/liwei_cmg/archive/2006/11/28/1418109.aspx
Although the arm series CPU is introduced in this article, the process is similar, and the call process is simply listed.

ARCH/i386/boot/head. s Start ()
ARCH/i386/boot/compress/head. s startup_32 ()
ARCH/i386/boot/compress/Misc. c decompress_kernel ()
 
ARCH/i386/kernel/head. s startup_32 ()
Init/Main. c start_kernel ()
Init/Main. c cpu_idle ()
Effect_root ()

After decompression, the startup_32 () function (also known as cleanup program or process 0) will perform memory management (at the beginning of the page table ).
Memory paging ). Check the CPU type and the optional Floating Point Unit (FPU), and call start_kernel.
Function. In fact, it can be understood as the main function of the Linux kernel.

Start_kernel () completes most initialization tasks, sets irqs, memory configuration, and starts the INIT process (the first user process ),
Finally, start the empty task cpu_idle (). In this case, the process scheduling takes over the control of the computer. by enabling the interrupt, multiple
Task processing capability.
 
Initial RAM disk ("initrd") is also mounted during the kernel startup. It has been previously loaded.
File directory. This makes it unnecessary to use physical disks or other disk drivers when loading the driver module, reducing the kernel size.
When the kernel starts, it will call cmdt_root () to detach the RAM disk and replace it with the real disk file system. RAM disk
The memory used is also recycled.
After the above work is completed, start the INIT process (usually/sbin/init ). Init is the parent process of all processes. The main task is
Create a process in the/etc/inittab configuration file. For more information about init and inittab, see the man manual.

6. Write at the end

This article takes a long time to organize, review the entire series, and learn about storage-related knowledge.
To physical devices, to logical structures, operating systems, each knowledge point has a very deep content. I believe most people only stay
Fur, and this series is no longer a fur, has been exposed to cortex.
 
 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.