In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
CentOS6 startup process is what, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
When we use the Linux operating system, we just press the power button, wait, and then enter the account and password to use the Linux operating system. So what does the operating system do before pressing the power to enter the account number and password? Let's talk about what happened during this period of time.
1. Detailed explanation of Linux startup process
The following figure shows the approximate process of starting the process:
Second, POST power-on self-test
POST (PowerOnSelfTest) first checks each device. After completion, it will look for the device with the boot record, find it and read it into the operating system boot record, then hand over the control of the system to the boot record, and complete the smooth startup of the system by the boot record.
III. MBR Boot
MBR (Master Boot Record) MBR records are usually recorded in sector 1 of track 0 of the disk, with a total of 512 bytes. The first 446 bytes are BootLoder, the last 64 bytes of 16 are used to store partition information, and * 2 bytes are parity information, usually 5 bytes.
4. GRUB (GRand Unified Bootloader), loading kernel
The first 446 bytes of MBR, which is a type of BooTLoader, is used to select the kernel to boot.
1. The composition of GRUB program:
It is mainly composed of device.map,menulst,stage1,stage2 and a series of stage1_5. My understanding of these parts is as follows:
Device.map: the root partition of the kernel file is stored
Menu.lis: it's a link file for grub.conf, but I think this name is closer to its function, which is a menu list. The kernel menu that can be selected is set up in the show. Stored in stage2.
Stage: the bootloader for grub is too large, so it is booted in 2 segments. The * segment is stored in MBR, and the second segment is stored in the kernel file system. The second segment can be found after the * * segment boot is completed. However, the second paragraph is stored in the kernel file system, and the file system has not been formatted at this time. How can I access the menu.lst of the second paragraph? You need to use the middle tier stage1_5, which assists the stage1 segment to access the stage2 segment. The stage1_5 is usually located in the 63 sectors after the stage1 field. Because stage2 has uncertain file systems that can be used in memory, this is why there are multiple stage1_5.
2. The meaning of grub.conf file parameters.
Default=1 # default kernel title, 0 means * timeout=5 # default wait time splashimage= (hd0,0) / grub/splash.xpm.gz # specifies the path to the background image of the menu. For xpm format, using gzip compression, can only hide menu title CentOS (2.6.32-358.el6.x86_64) # title name for 14bits color hiddenmenu #, user can customize root (hd0,0) # specify the root location of grub # specify the location of kernel file, but also point out the location of root (after system startup), mount mode ro, this is very critical. # the init process will be started after loading. Kernel / vmlinuz-2.6.32-358.el6.x86_64 ro root=/dev/mapper/vg0-root rd_NO_LUKS rd_NO_DM LANG=en_US.UTF-8 rd_LVM_LV=vg0/swap rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg0/root KEYBOARDTYPE=pc KEYTABLE=us rhgb crashkernel=auto quiet rhgb quiet # uses initrd / initramfs-2.6.32-358.el6.x86_64.img when mounting the root file system during kernel startup
The essence of initramfs-2.6.32-358.el6.x86_64.img is?
# initramfs is a file in cpio format compressed in gzip. The kernel boots it as a temporary root file system. The stage2 of # grub loads the initrd into memory, releases the contents into the content, and the # kernel executes the init script, which gives control to the init file for processing. # init it also loads device drivers related to various storage media. When the required drivers are loaded, # creates a root device and mounts the root file system rootfs as read-only. At the end of this step, release the unused memory, convert it to the real root file system, and run the / sbin/init program at the same time. # execute process 1 of the system. After that, control of the system is handed over to the / sbin/init process.
How to make initramfs?
# you can use the dircut command Usage is as follows: # [root@server ~] # dracut / mnt/initramfs- `uname-r`.img `uname-r` [root@server ~] # du-sh / mnt/initramfs-2.6.32-358.el6.x86_64.img 16m / mnt/initramfs-2.6.32-358.el6.x86_64.img [root@server ~] # du-sh / boot/initramfs-2.6.32- is used only when the initramfs file is damaged 358.el6.x86_64.img 16m / boot/initramfs-2.6.32-358.el6.x86_64.img # detailed introduction You can use this link: https://zh.opensuse.org/index.php?title=SDB:Dracut&variant=zh-cn#.E5.90.AF.E7.94.A8_dracut_.E7.94.9F.E6.88.90.E7.9A.84_initramfs
3. The function of grub
1) provide menus and interactive interfaces
E: enter edit mode
2) Select the kernel or system to boot
Allows you to pass boot parameters to the kernel
Select the interface to hide
# it can be self-booted by passing parameters through grub like the kernel. One of the # applications is to change the root password (forget the password) and use the e option to pass single-user instructions.
3) provide protection mechanism for editing function
Enable kernel files
To choose to run the specified kernel, you have to enter the password first.
Transfer parameters
To use the e command, you must enter the password first.
[root@server root] # grub-md5-crypt Password: Retype password: $1 $Mp7Rp1 $l2wzOILNUqpUhAR7zXvQb0 # above is the generated encryption string # and then add the information to the grub.conf file in the following format: password-- md5 $1 $Mp7Rp1 $l2wzOILNUqpUhAR7zXvQb0 # of course, the encryption effect is different depending on the location of the grub.conf file. # before joining title, the entire menu will be encrypted. # if added to the title finger, the entry of the corresponding operating system will be encrypted.
4. How to install grub
1) use the grub-install command
# grub-install [--root-directory=/path/to/somewhere] DEVICE
2) grub interaction is a command
Here we make a simplified grub. Of course, you can only start a bash when you start it. The example is done under the VMware virtual machine.
* step: prepare a new disk and divide it into 2 regions
Step 2: simulate the startup boot directory, and the root directory, and mount it. As follows
[root@server] # df-H | tail-n 2 / dev/sdd1 518M 11M 481m 3% / mnt/boot / dev/sdd2 2.2G 71m 2.0G 4% / mnt/sysroot
Step 3: make grub and generate the configuration file of grub
Make grub
Copy the kernel file and initramfs file to the / mnt/boot directory and generate the grub.conf file
[root@server ~] # cp / boot/vmlinuz-2.6.32-358.el6.x86_64 / mnt/boot/vmlinuz [root@server ~] # cp / boot/initramfs-2.6.32-358.el6.x86_64.img / mnt/boot/initramfs.img [root@server ~] # ll / mnt/boot/ total 20106 drwxr-xr-x 2 root root 1024 Jul 24 20:58 grub-rw-r--r-- 1 root root 16542269 Jul 24 21 : 06 initramfs.img-rwxr-xr-x 1 root root 4043888 Jul 24 21:05 vmlinuz # generated grub.conf file [root@server ~] # cat / mnt/boot/grub/grub.conf default=0 timeout=10 title Mini Linux root (hd0,0) kernel / vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash initrd / initramfs.img
Step 4: generate the root file system
Step 5: copy the command and library to the corresponding root directory
Use the previous disk image as the boot disk of another virtual machine.
Start the init process
Init processes are * processes started by the system. Other processes have this process to control the fork, that is, init is the "ancestor" of other processes, PID=1. Of course, PID=0 processes what we call idle processes belong to the kernel.
What init does after it starts:
1. Read / etc/inittab to read the default level assumption: the default level read is 3
/ etc/init/*.conf
# Startup level: (runlevel) # 0: shutdown # 1: single user mode # 2: multi-user mode, does not support NFS function # 3: full multi-user mode, text interface # 4: reserved mode # 5: full multi-user mode, support graphic mode # 6: shutdown # / etc/inittab file format is as follows, which follows the style of CentOS5. Id:3:initdefault:
2. Execute initialization system script / etc/rc.d/rc.sysinit to initialize the script
If you have a chance to read this, the main functions of the script are as follows:
# get the network environment and host type. First, the network environment settings file "/ etc/sysconfig/network" is read to obtain the network environment such as host name and default gateway. # agree to text welcome message. # Mount other file systems defined in the / etc/fstab file. # activate swap # to detect the root file system and remount it in read / write mode # to decide whether to start SELinux and udev. Detection of interface devices and testing of plug and play (pnp) parameters. # loading of user-defined modules. Users can add custom modules to "/ etc/sysconfig/modules/*.modules", which will be loaded into the system. # load the relevant settings of the core. Press the settings of the file "/ etc/sysctl.conf" to configure the function. # set system time (clock). # set the glyph of the terminal console. # set up hard disk functions such as raid and LVM. # check the disk file system in a way. # convert disk quota quota. # reload the system disk in read mode. # start the quota function. # start the system random number device (generate random number function). # be aware of the temporary files during startup. # load startup information into the "/ var/log/dmesg" file.
3. Then execute the / etc/rc.d/rc script
When this script is run, all scripts under / etc/rc.d/rc3.d/ are read to control whether to start or shut down those services when the system starts.
# the scripts here are roughly divided into two categories, those that begin with S and those that begin with K. # S means it starts when it is started, and K means it does not start when it is turned on. # naming format of each file, for example: S01sysstat S boot 01 boot order sysstat startup script name # the definition of startup is defined in each script: for example # # chkconfig:-85 15 # default level boot order does not start order
Whether these scripts start automatically or not can be managed by the chkconfig command.
# Common options: # chkconfig-add SRV_SCRIPT can manage some scripts written by itself so that this command can be managed in a unified manner. For example: chkconfig-- add httpd # chkconfig-- del SRV_SCRIPT deletes the service, which means that the service is not managed by the chkconfig mechanism # chkconfig SRV_SCRIPT {on | off} sets whether the service boots automatically. The default management level is 2345. #-level 2345, etc., which specifies the default level and can be used with other options
4. Execute the / etc/rc.d/rc.local script, which is a script started during startup.
The / bin/login login user is executed. At this point, the system startup process is complete.
After reading the above, have you mastered how to start the CentOS6 process? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.