What happened during Linux boot to user login

Source: Internet
Author: User

What happened during Linux boot to user login
I. BIOS power-on self-check when you press the power switch to start the computer, the computer will first start the BIOS (Basic Input and Output System), BIOS is generally integrated on the motherboard. BIOS work 1. detects connected hardware, such as video card, memory, and disk. The purpose of the detection is to provide the device information to the operating system. find a boot disk. Each BIOS has a boot menu, in which you can set the device to start the system, such as the optical drive, hard disk, and network, you can set multiple options in this menu to search for startup information on the device in the set order. 3. find the boot hard disk, and then the BIOS will find the Boot Sector on the disk and find the kernel boot system. 2. It is well known that the first sector of the hard disk 0th track is called MBR, that is, Master Boot Record, that is, the Master Boot Record. The size of the Record is 512 bytes, you can store the pre-start information and partition table information. After the system finds the MBR of the hard disk specified by BIOS, it will copy it to the physical memory where the 0x7c00 address is located. In fact, the content copied to the physical memory is the Boot Loader, and to your computer, it is lilo or grub. 3. Boot Loader is a small program that runs before the operating system kernel runs. Through this small program, we can initialize hardware devices and build a map of memory space to bring the system's hardware and software environment to a suitable state, in order to make all preparations for the final call to the operating system kernel. There are several Boot loaders, among which Grub, Lilo, and spfdisk are common loaders. Let's take Grub as an example. After all, there are not many people using lilo and spfdisk. The System reads grub configuration information (generally menu. lst or grub. lst) in the memory and starts different operating systems according to the configuration information. So let's take a look at grub's content. It exists in/boot/grub. GRUB has several important files, STAGE1, STAGE1.5, and STAGE2 STAGE1: it only has 512 bytes and is usually placed in MBR, it is used to load STAGE2 at system startup and give control to it. STAGE2: the Core of GRUB. All functions are implemented by it. STAGE1.5: Between STAGE1 and STAGE2, It is a bridge between them. Because STAGE2 is large, it is usually placed in a file system, but STAGE1 cannot identify the file system format, therefore, STAGE1.5 is required to guide STAGE2 located in a file system. According to the file system format, STAGE1.5 also needs the corresponding files, such as e2fsstage15 and fatstage15, which are used to identify the file system formats of ext and fat respectively. It is stored between 1-63 cylinders. the guiding sequence is as follows: STAGE1->; STAGE1.5->; STAGE2. The following is grub in my linux. content in conf: # grub. conf generated by anaconda # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a/boot partition. this means that # all kernel and initrd paths are relative to/boot/, eg. # root (hd0, 0) # kernel/vmlinuz-version ro root =/dev/sda2 # initrd/initrd-[generic-] version. img # B Oot =/dev/sda default = 0 timeout = 5 splashimage = (hd0, 0)/grub/splash.xpm.gz hiddenmenu title CentOS (2.6.32-279. el6.i686) root (hd0, 0) kernel/vmlinuz-2.6.32-279.el6.i686 ro root = UUID = b48a3c42-c2a0-42a2-a47f-1cb6b1d9f5c9 rdNOLUKS rdNOLVM LANG = enUS. UTF-8 rdNOMD SYSFONT = latarcyrheb-sun16 crashkernel = auto KEYBOARDTYPE = pc KEYTABLE = us rdNO_DM rhgb quiet initrd/initramfs-2.6.32-279.el6.i686.img the most important content has been black, Root (hd0, 0) is used to set the root address of the contents of kernel and initrd. Kernel indicates the kernel. initrd is used to access hard disk files during kernel startup. Title: an OS-induced header that allows multiple root users to specify the disk on which the required file exists (hd0, 0) indicates the first hard disk and the first partition, see/boot/grub/device. map kernel: the name of the kernel file, and some parameters during kernel loading or indicate loading initrd in read-only mode: contains some additional drivers, after the kernel is loaded and started, all hardware information of the computer is queried from the bios. Then, you take over and manage these devices to provide them to linux, some drivers of these devices are included in the kernel, called static drivers. Some of them store file systems in a module (dynamically) manner. At this time, no file system is mounted, therefore, you cannot use modules in the file system. Here, you can only drive the corresponding device of the hardware driver that exists in the kernel. to drive hardware drivers not included in the kernel, You need to load the file system. the kernel will try to mount the root file system. The root file system must contain at least/etc/bin/sbin/lib/dev These five directories are indispensable. the system will not be able to start the root file system mounting in read-only mode, because at this time linux is still in the startup phase, not stable, avoid damage to system information 5, after the init (according to the inittab file to set the running level) kernel is loaded, the first running program is/sbin/init to execute the init program/etc/rc. d/rc. sysinit # The first script executed by init/etc/rc. d/rc $ RUNLEVEL # $ RUNLEVEL is the default running mode/etc/rc. d/rc. local/sbin/mingetty # Wait for the user to log on to sysinit:/etc/rc. d/rc. sysinit mainly performs the same initialization in various running modes, including: loading keymap and starting swapping in the system font, setting the host name to set the NIS domain name check (fsck) and mount the file system to enable the quota loading sound card module to set the system clock. Inittab: in fact, the main function of the/etc/inittab file is to set the Linux running level. The setting format is ": id: 5: initdefault :", this indicates that Linux needs to run on level 5. The Linux operating level is set as follows: 0: shutdown 1: Single User Mode 2: multi-user mode without network support 3: multi-user mode with network support 4: reserved, not used 5: multi-user mode with network support and X-Window support 6: reboot the system, that is, restart rc. local: If you open This file, there is a sentence in it. after reading it, you will see the function of This command at a Glance: # This script will be executed * after * all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. rc. local is the place for users to personalize Linux after all initialization work. You can put what you want to set and start here. The init process is the first non-kernel process to be started, so its process id pid value is always 1. Init reads its configuration file/etc/inittab and determines the Runlevel to be started ). Basically, the running level specifies the behavior of the entire system. Each level (represented by an integer ranging from 0 to 6) meets a specific purpose. If the initdefault level is defined, this value is directly selected. Otherwise, you must enter a value that represents the running level. After entering a number indicating the running level, init executes a command script program according to the definition in the/etc/inittab file. The default running level depends on the selection of Logon programs in the installation phase: whether to use text-based or X-Window-based logon programs. We already know the rc command script program. When the running level changes, the/etc/inittab file defines which command script program to run. These Command Script programs start or stop various services at the specific running level. Because the number of services to be managed is large, you need to use the rc command script program. Among them, the most important one is/etc/rc. d/rc, which is responsible for calling the corresponding command script program for each running level in the correct order. As we can imagine, such a command script program can easily become difficult to control! A well-designed plan is required to prevent such incidents. For each running level, there is a corresponding sub-directory in the/etc/rc. d sub-directory. The sub-directories at the running level are named as rcX. d. X indicates the number at the running level. For example, all the Command Script programs of running level 3 are saved in the/etc/rc. d/rc3.d subdirectory. In the sub-directories of each running level, the/etc/rc is created. d/init. d sub-directory command script program symbolic links, however, these symbolic links do not use the command script program in/etc/rc. d/init. the original name in the d sub-directory. If the command script program is used to start a service, its symbolic link name starts with the letter S. If the command script program is used to close a service, the name of the symbolic link starts with K. In many cases, the execution sequence of these script programs is very important. If you do not configure the network interface first, you cannot use DNS to resolve the host name! In order to arrange their execution sequence, a two-digit character is followed by the letter S or K, and a small value is followed by a large value. For example,/etc/rc. d/rc3.d/S50inet will be executed before/etc/rc. d/rc3.d/S55named (S50inet configures network settings and 55named starts the DNS server ). Stored in/etc/rc. d/init. the Command Script programs in the d sub-directory and on the symbolic link are real practitioners who have completed the operations to start or stop various services. When/etc/rc. d/rc runs through each specific sub-directory of the running level, it calls each command script program for execution in order of numbers. It first runs the command script program with the letter K headers, and then runs the command script program with the letter S headers. The Stop parameter is passed for the command script program that starts with letters K. Similarly, the Start parameter is passed for the command script program that starts with letters S. Writing your own rc Command Script will certainly encounter a situation where the system administrator needs to modify the script for starting or shutting down the Linux system.
 

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.