设为首页 收藏本站
查看: 812|回复: 0

[经验分享] CentOS / RHEL 7 : Booting process

[复制链接]
YunVN网友  发表于 2019-4-17 15:56:37 |阅读模式
It is important to understanding the Linux boot process to troubleshoot boot problems. These are the high-level steps in the boot process. You need to be aware of files involved in the boot process because errors in these files can cause boot problems.
If there is an issue during boot, you need to identify in which phase of boot process the issue lies so that you can take appropriate action to fix the issue.
Introduction of systemd
systemd is the new system and service manager in CentOS/RHEL 7. It is backward compatible with SysV init scripts used by previous versions of RedHat Linux including RHEL 6. It replaces Upstart as the default initialization system.
The following steps summarize how the boot procedure happens in RHEL/CentOS 7.

  •   The computer’s BIOS performs POST.
  •   BIOS reads the MBR for the bootloader.
  •   GRUB 2 bootloader loads the vmlinuz kernel image.
  •   GRUB 2 extracts the contents of the initramfs image.
  •   The kernel loads driver modules from initramfs.
  •   Kernel starts the system’s first process, systemd.
  •   The systemd process takes over. It:


  •   Reads configuration files from the /etc/systemd directory
  •   Reads file linked by /etc/systemd/system/default.target
  •   Brings the system to the state defined by the system target
  •   Executes /etc/rc.local
DSC0000.png
1. POST (Power on Self Test)
From the system firmware, which can be the modern Universal Extended Firmware Interface (UEFI) or the classical Basic Input Output System (BIOS), the Power-On Self-Test (POST) is executed, and the hardware that is required to start the system is initialized.
2. Selecting the bootable device (With MBR)
– Master Boot Record (MBR) is the first 512 bytes of the boot drive that is read into memory by the BIOS.
– The next 64 bytes contain the partition table for the disk. The last two bytes are the “Magic Number” which is used for error detection.
DSC0001.png
– MBR discovers the bootable device and loads the GRUB2 boot loader into memory and transfers control over to it.
3. Loading the boot loader (GRUB2)
– The default bootloader program used on RHEL 7 is GRUB 2. GRUB stands for GRand Unified Bootloader. GRUB 2 replaces the older GRUB bootloader also called as legacy GRUB.
– The GRUB 2 configuration file is located at /boot/grub2/grub.cfg (Do not edit this file directly).
DSC0002.png
– GRUB 2 menu-configuration settings are taken from /etc/default/grub when generating grub.cfg.
– Sample /etc/default/grub file :
# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/swap crashkernel=auto rd.lvm.lv=rhel/root rhgb quiet net.ifnames=0"
GRUB_DISABLE_RECOVERY="true"– If changes are made to any of these parameters, you need to run grub2-mkconfig to re-generate the /boot/grub2/grub.cfg file.
# grub2-mkconfig –o /boot/grub2/grub.cfg– GRUB2 searches the compressed kernel image file also called as vmlinuz in the /boot directory.
– GRUB2 loads the vmlinuz kernel image file into memory and extracts the contents of the initramfs image file into a temporary, memory-based file system (tmpfs).
– The initial RAM disk (initrd) is an initial root file system that is mounted before the real root file system.
initramfs
– The job of the initial RAM file system is to preload the block device modules, such as for IDE, SCSI, or RAID, so that the root file system, on which those modules normally reside, can then be accessed and mounted.
– The initramfs is bound to the kernel and the kernel mounts this initramfs as part of a two-stage boot process.
– The dracut utility creates initramfs whenever a new kernel is installed.
– Use the lsinitrd command to view the contents of the image created by dracut:
# lsinitrd | less4. Loading the kernel
– The kernel starts the systemd process with a process ID of 1 (PID 1).
DSC0003.png
– It also loads the necessary driver modules from initrd image.
– The boot loader (GRUB2) may present a boot menu to the user, or can be configured to automatically start a default operating system.
– To load Linux, the kernel is loaded together with the initramfs. The initramfs contains kernel modules for all hardware that is required to boot, as well as the initial scripts required to proceed to the next stage of booting.
– On RHEL 7, the initramfs contains a complete operational system (which may be used for troubleshooting purposes).
5. Starting systemd
– The kernel starts the systemd process with a process ID of 1 (PID 1).
root          1      0  0 02:10 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 23– systemd is the first process that starts after the system boots, and is the final process that is running when the system shuts down.
– It controls the final stages of booting and prepares the system for use. It also speeds up booting by loading services concurrently.
– systemd reads the file linked by /etc/systemd/system/default.target (for example, /usr/lib/systemd/system/multi-user.target) to determine the default system target (equivalent to run level). The system target file defines the services that systemd starts.
– systemd allows you to manage various types of units on a system, including services (name.service) and targets (name.target), devices (name.device), file system mount points (name.mount), and sockets (name.socket).
Comparision of SysV Run Levels and Target Units
Run LevelTarget UnitsDescription0runlevel0.target, poweroff.targetShut down and power off1runlevel1.target, rescue.targetSet up a rescue shell2,3,4runlevel[234].target, multi- user.targetSet up a nongraphical multi-user shell5runlevel5.target, graphical.targetSet up a graphical multi-user shell6runlevel6.target, reboot.targetShut down and reboot the systemsystemd brings the system to the state defined by the system target, performing system initialization tasks such as:
1. Setting the host name
2. Initializing the network
3. Initializing SELinux based on its configuration
4. Printing a welcome banner
5. Initializing the system hardware based on kernel boot arguments
6. Mounting the file systems, including virtual file systems such as the /proc file system
7. Cleaning up directories in /var
8. Starting swapping
View default/current target unit
Use the following command to view which target unit is used by default:
# systemctl get-default
graphical.targetThe graphical.target target unit indicates that the system is running in a graphical, multi- user state. This is similar to run level 5 in a SysV init system. You can verify this using the old command runlevel :
# runlevel
N 5The default target unit is represented by the /etc/systemd/system/default.target file. This file is a symbolic link to the current default target unit. For example :
# ls -lrt /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 36 Sep 23 20:01 /etc/systemd/system/default.target -> /lib/systemd/system/graphical.targetChange default target unit
Use the following command to change the default target unit (for example, to change the default to the multi-user.target unit):
# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.Notice that the default.target symbolic link has changed, and is now pointing to the multi-user.target unit:
# ls -lrt /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 41 Sep 24 11:58 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.targetBelow table summarizes where a specific phase is configured and what you can do to troubleshoot if things go wrong.
Boot PhaseConfigurationPOSTHardware Configuration (F2, ESC, F10 or another key)Select bootable DeviceBIOS/UEFI configuration or hardware boot menuLoading the boot loadergrub2-install and edits to /etc/defaults/grubLoading the kernelEdits to the GRUB configuration and /etc/dracut.confstarting /sbin/initCompiled into initramfsProcessing initrd.targetCompiled into initramfsSwitch to the root filesystem/etc/fstabRunning the default target/etc/systemd/system/default.target  

  转至:https://www.thegeekdiary.com/centos-rhel-7-booting-process/




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-828300-1-1.html 上篇帖子: CentOS 6.5 zabbix 3.0.4 乱码问题 下篇帖子: CentOS6下Nginx安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表