Linux Startup Process details

Source: Internet
Author: User
Tags ide hard drive
Article Title: linux Startup Process details. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

I have read many documents over the past few days, so I have a detailed understanding of the linux Startup Process.

There are a lot of articles on the Internet about this, but I don't think there is a complete explanation of the linux Startup details. Below are some of the things my younger brother has summarized during his learning process. this is the complete linux Startup Process,

Kernel is not involved, but I think it is more detailed.

(Because I am relatively lazy, this section was copied from the Internet)

After the machine is powered on, the BIOS starts to detect system parameters, such as memory size, date and time, disk devices, and the sequence in which these disk devices are used for boot, the BIOS is configured to first check the soft drive or optical drive (or both), and then try to boot from the hard disk. If no bootable media is found on these removable devices, the BIOS usually redirects to the first sector of the first hard disk to find instructions for loading the operating system. The program that loads the operating system is the boot loader.

In linux, the boot loader is usually lilo or grub. Starting from Red Hat Linux 7.2, GRUB (GRand uniied Bootloader) replaces LILO as the default start loader. How is grub loaded at startup?

Grub has several important files, stage1 and stage2, which sometimes need stage1.5. these files are generally loaded under the/boot/grub folder. grub usually includes the following steps:

1. the basic bootstrap loader (stage1) is very small. It is 512 bytes on the Internet. However, in my system, du-B/boot/grub/stage1 is shown as 1024 bytes, I don't know whether the grub version is different or why I understand it incorrectly. stage1 is usually located in the main boot sector. For hard disks, It is MBR. The main function of stage1 is to load the second boot program (stage2 ). this is mainly because there is not enough space in the primary Boot Sector for other things. I use grub 0.93, and the size of stage2 is 107520 bit.

2. Load the second bootstrap loader (stage2), which actually leads to more advanced features that allow users to load into a particular operating system. In GRUB, this step allows the user to display a menu or enter a command. Because stage2 is very large, it is generally located in the file system (usually the root partition of boot ).

The above mentioned stage1.5 file. What is its role? You can check out fat_stage_1.5 e2fs_stage_1.5 xfs_stage_1.5 in the/boot/grub directory. It is easy to guess that stage1.5 is related to the file system. sometimes stage1 cannot identify the file system partition where stage2 is located. In this case, stage1.5 is required to connect stage1 and stage2. therefore, different file systems may have different stage1.5. but for grub 0.93, it seems that stage1.5 is not very important, because I tried it. Without stage1.5, I installed stage1 in the boot sector of the floppy disk, and then put stage2 in a floppy disk formatted as ext2 or fat. during startup, The stage2 boot is normal and does not require e2fs_stage_1.5 or fat_stage_1.5.

The following is my experiment:

# Mkfs. ext2/dev/fd0

# Mount-t ext2/dev/fd0/mnt/floppy

# Cd/mnt/floppy

# Mkdir boot

# Cd boot

# Mkdir grub (the mkdir-p boot/grub command can be used in the preceding three steps)

# Cd grub

# Cp/boot/grub/{stage1, stage2, grub. conf }./

# Cd; umount/mnt/floppy

The above steps are used to format the floppy disk into the ext2 format, and then stage1, stage2, grub. conf

Copy the required files to the specified directory of the floppy disk. Install grub on the floppy disk.

# Grub (entering the grub environment)

Grub> install (fd0)/boot/grub/stage1 (fd0) (fd0)/boot/grub/stage2

P (fd0)/boot/grub. conf

The preceding command can also be replaced by the following two statements:

Grub> root (fd0) # partition of the root directory of grub

Grub> setup (fd0) # This step is equivalent to the above install command

Here I will explain

Install (fd0)/boot/grub/stage1 (fd0) (fd0)/boot/grub/stage2 p

(Fd0)/boot/grub. conf command.

Install

Tell GRUB to (fd0)/boot/grub/stage1

The Boot Sector (fd0) to which the disk is installed ).

(Fd0)/boot/grub/stage2

Tell grub stage2 where the file is located.

The p parameter is followed by (fd0)/boot/grub. conf to tell the location of the grub configuration file.

Okay, let the BIOS start from the soft drive. Try it. You can still access the system without the e2fs_stage_1.5 file.

In fact, this is a small boot disk. (After learning about the running principle of grub, it's much easier to understand ^_^)

3. Now we have entered the grub boot menu. Next, grub needs to load the operating system on a specific partition, such as the Linux kernel. Once GRUB receives the correct command from its command line or configuration file to start the operating system, it will find the necessary boot file and hand over control of the machine to the operating system.

Due to the limited space and avoiding the lengthy length, I will not talk much about grub commands. There is a lot of information on the Internet. A typical and complete command for guiding linux is as follows:

Title 51 base

Root (hd0, 0)

Kernel/bzImage ro root =/dev/ram0

Initrd/initrd. img

Pay attention to the following issues:

(1) The naming of grub disks and partitions is different from that of linux. The first disk starts from 0 and the first partition starts from 0. for example, the 5th partition of the first hard disk is/dev/hda5 in linux, and the partition in grub is (hd0, 4 ). another example is that/dev/fd0 is (fd0, 0) in grub ). (if there is an error in the last sentence, please remind me)

(2) Whether it is IDE Hard Drive hda, hdb or SCSI hard drive sda, sdb is named in hd mode in grub.

For example, the/dev/sda2 In the VM is (hd0, 1) in grub, and the/dev/hdb7 is named (hd1, 6) in grub.

(3) We need to figure out the relationship between the above two root servers. root (hd0, 0) is the grub command, which is used to specify the partition of the boot server as the root directory of grub. root =/dev/ram0 is the kernel parameter. It tells the operating system the device where the real file system is located after the kernel is loaded. note the differences between the grub root directory and the file system root directory.

Return to the preceding commands.

The kernel command is used to specify the location of the kernel. "/" indicates (hd0, 0), that is, the grub root directory.

The initrd command is used to specify the location of the imgfile used to initialize ram.

Grub loads the kernel bzImage and expands it to the specified location (it should be 0x100000). It also loads initrd. img to the memory (I don't know where it is ).

Ps:

The grub task ends now. grub transfers control of the machine to the Operating System (linux ).

After the operating system receives control, start start_kernel. Then the kernel expands initrd. img to the/dev/ram0 temporary root file system and runs the linuxrc file.

P. It is necessary to talk about the role of initrd, especially the core file linuxrc in it.

[1] [2] Next page

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.