Linux Boot and kernel management

Source: Internet
Author: User

One: The composition of Linux system system

Linux consists of kernel and rootfs, so what is kernel and what is ROOTFS?
Kernel: Operating system kernel, operating system kernel is the core part of most operating systems. Kernel for process management, memory management, network management, drivers, file systems, security features
ROOTFS: Programs and glibc. Rootfs exists because of the need to provide the most primitive mount point to the system under the VFS mechanism. VFS is a Linux file system implementation must follow a mechanism, ROOTFS is a specific implementation of the file system, Linux all the file system implementation must conform to the VFS (VFS interface), this is the real relationship between the two.
Libraries: function sets, functions, calling interfaces (header file is responsible for description)
Program: Binary Execution file

Second: System startup process

The startup of the operating system is divided into two stages: Boot and boot startup. The boot phase begins when the power switch is turned on, ending with the kernel initialization complete and the SYSTEMD process running successfully. The start-up phase takes over the remaining work until the operating system enters an operational state

Booting boot stage

1:post:power-on-self-test, power-on self-test, is a major part of the BIOS function. Responsible for the CPU, motherboard, memory, hard disk subsystem, display subsystem, serial parallel interface, keyboard, CD-ROM drive and other hardware conditions detection.
2: Read MBR
1.Stage 1:bios will look for a boot record on the attached disk, which is usually located in the MBR (Master boot record), it loads the first boot record it finds into memory, and starts executing this code. The boot code (that is, the Phase 1 code) must be very small because it must be placed in the first 512-byte sector of the hard disk along with the partition table. This phase of the main work is to find and load the second paragraph bootloader program (STAGE2), but the system does not start, the MBR can not find the file system, and can not find the location of stage2, therefore, there is a stage1_5
Stage 1.5 In this phase, the system loads an image file initrd that is stored outside the partition. A temporary root file system that is mounted during system boot to support a two-stage boot process. The Initrd file contains a variety of executable programs and drivers that can be used to mount the actual root filesystem and then unload the INITRD RAM disk and free up memory.

Stage 2/initramfs-$ (UNAME-R). IMG, need to mount the/dev/sda2 premise is Ext4.ko. The GRUB program looks for kernel information based on the/boot/grub/grub.conf file and then starts loading the kernel program, and when the kernel program is detected and loaded into memory, grub transfers control to the kernel program. Simply put: Load kernel mount root filesystem

Exercise: Delete the/boot/grub/grub.conf file in the CENTOS6 and restart it. Let the system start temporarily, then rewrite the grub.conf file so that it will start automatically after the next boot.

After deleting the file, the machine still works, but when we restart it? found that the machine does not start properly.

Next we enter the system as follows, and then explain the role of the file in detail.

Next, let's take a look at this file. See what it is specifically about.

    #boot=/dev/sda    default=0        #设定默认启动的title的编号,从0开始    timeout=5       #等待用户选择的超时时间    splashimage=(hd0,0)/boot/grub/splash.xpm.gz    #GRUB的背景图片    hiddenmenu     #隐藏菜单    title CentOS (2.6.18-194.el5PAE)      #内核标题        root (hd0,0)         #内核文件所在的设备        kernel /vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/     #内核文件路径以及传递给内核的参数        initrd /initrd-2.6.18-194.el5PAE.img                            #ramdisk文件路径
2: Start startup phase (service)

The init process is the parent process for all Linux processes, and its process number is 1. The init command is one of the most indispensable programs in the Linux operating system, and the Init process is run by the Linux kernel and is the first process in the system.
Next we are learning a file:/etc/inittab

Id:runlevels:action:process

The ID is used to define the unique entry number in the Inittab file, with a length of 1-4 characters
Runlevels the level listed to run is empty then represents all levels
Action to perform
Procedure to be executed by the process

Id:3:initdefault:

ID is used to define the ID itself
3 is the running level listed
Initdefault
This action is to set the default RunLevel, if the previous runlevels does not specify the RunLevel, then the terminal will be asked at startup, this line does not need to process this paragraph

Si::sysinit:/etc/rc.d/rc.sysinit

ID is si just used to identify
Runlevels is empty, which represents all RunLevel
Sysinit refers to the subsequent process (i.e./etc/rc.d/rc.sysinit) that executes at system startup
/etc/rc.d/rc.sysinit This is a system initialization script that initializes a lot of processes inside this script.
The role of/etc/rc.d/rc.sysinit:
(1) Set host name
(2) Setting welcome information
(3) Activate Udev and SELinux
(4) Mount the file system defined in the/etc/fstab file
(5) Detecting the root file system and re-mounting the root filesystem in read and write mode
(6) Setting the system clock
(7) Activate swap device
(8) Set kernel parameters according to/etc/sysctl.conf file
(9) Activating LVM and software RAID devices
(10) Loading drivers for additional devices
(11) Cleaning operation

Service startup Management
Chkconfig AutoFS on
Chkconfig AutoFS off
Chkconfig AutoFS on--level 35
Service AutoFS Start
Service AutoFS Stop
Service AutoFS Status
Service AutoFS Reload
Or
/etc/init.d/autofs Start|stop|status|reload

These commands allow you to modify the switching state of the service in different modes. The picture shows the switching status of the service in different modes.
The services that were previously spoken were frequently used services, but what about the services that were not commonly used? It would be a waste of resources to keep them open, and in this case there would be a strategy to sleep without the usual services and wake them up when they were needed, and then have a service to wake them up: xinetd service. By the XINETD unified to wake up those sleeping services. Now let's talk about the XINETD service
XINETD itself is a SYSV service, activated and disabled in the way: chkconfig daemon on/off equivalent to modify/etc/xinetd.d/daemon disable = No/yes
Make the changes effective to restart/etc/init.d/xinetd restart

Next we'll do a few experiments.
1. Delete/boot/grub/all files except grub.conf, reboot, and discover to start

2. Damage to grub, found to be unable to boot, repair as follows.

    dd if=/dev/zero of=/dev/sda bs=1 count=446

 进入rescue     chroot /mnt/sysimage    grub-install /dev/sda kernel /vmlinuz.... ro root=/dev/sda2 selinux=0 vim /etc/selinux/config    SELINUX=disabled


3. Then delete all/boot/grub/except grub.conf and find that it cannot be started.


This is because the original operating system has stage2 files, and later Grub-install will be the original to cover, so we just need to find stage2 back on the good.

4. Destroy the SDA1 and find the system is directly damaged.

dd if=/dev/zero of=/dev/sda bs=1 count=10240 seek=512
    rescue    chroot /mnt/sysimage    grub-install /dev/sda #恢复/boot/grub/stage 文件    grub        root(hd0,0)        setup (hd0)



Linux Boot and kernel management

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.