A boot process overview
1. POST
after boot server host, will be based on the motherboard BIOS settings for CPU, memory, video card, keyboard and other equipment preliminary testing, testing has been successfully handed over control of the system according to the preset startup sequence, most of the time will be handed over to the machine hard disk.
2. MBR boot
when the boot from the local hard drive of the system, first (Master Boot Record master boot record) according to the first sector of the hard disk is provided in the MBR, the system passes control to the operating system partition contains boot files; root or directly MBR boot record information call the boot menu.
3. GRUB menu
For Linux operating systems, GRUB (GRand Unified Bootloader, unified boot loader) is the most widely used multi-system boot program. After the transfer system control to GRUB, the boot menu will be displayed to the user selected, and depending on the option to load the Linux kernel files, then the system control to the kernel. (CentOS 7 uses GRUB2 bootloader).
4. Load the kernel
Linux kernel is a special pre-compiled binary files between various hardware resources and system programs, responsible for resource allocation and scheduling. After the kernel took control of the system, we will have complete control over the entire process of running the Linux operating system.
5. init initialization process
in order to complete further system boot process, Linux kernel first Loading System "/ sbin / init" program into memory to run, init process is responsible for the completion of a series of system initialization process, and finally waiting for the user to log on.
Two, init process
Linux operating system using digital processes are marked marked the identity of each process known as PID. During the boot Linux operating system, "/ sbin / init" kernel is loaded first program, so the init process corresponding PID number is always 1.
Three, Systemd Profile
Systemd is a Linux operating system init software, CentOS 7 system uses a new Systemd start-up mode, replacing the traditional SysVinit. When Systemd way to start the system initialization many services started in parallel, greatly improving the efficiency of the boot. CentOS 7 system "/ sbin / init" is "/ lib / systemd / systemd" link files. In other words, the first init process CentOS 7 running on the system is "/ lib / systemd / systemd" . systemd daemon is responsible for Linux systems and services, systemctl control systems and services for state Systemd management. The following is a unit of the type Systemd.
SysVinit mechanism of early Linux operating system, including the default service with seven different ways, for backwards compatibility SysVinit system, Systemd using the corresponding target (target) to simulate the SysVinit run level, as shown.
Fourth, troubleshoot system boot failure
1、修复MBR扇区故障
MBR 位于物理硬盘的第一个扇区(512 字节),该扇区又称为主引导扇区,除了包含系统引导程序的部分数据外,还包含整个硬盘的分区表记录。当主引导扇区发生故障时,将可能无法加载系统,通过该硬盘引导主机时很可能进入黑屏状态。
扇区故障实验:
(1)首先我们添加一块硬盘,然后(1)执行“fdisk /dev/sdb”命令将硬盘分区。
(2)执行“mkfs.xfs /dev/sdb1”命令对硬盘分区进行格式化。
(3)执行“mkdir /data”命令创建目录作为挂载点,再执行“mount /dev/sdb1 /data”将硬盘设备挂载到目录上。
(4)执行“dd if=/dev/sda of=/data/sda.mbr.bak bs=512 count=1”命令将主硬盘的第一扇区的内容备份到“/data”目录中。
(5)执行“dd if=/dev/zero of=/dev/sda bs=512 count=1”命令来模拟主分区故障。
(6)执行“init 6”命令重启来看一下,显示无法找到系统。
(7)我们重启设备,在加载读条的时候及时按下Esc键进入“Boot Menu”界面,并将系统镜像放入驱动中然后使用方向键选择“CD-ROM Drive”选项进入驱动引导。
(8)在向导界面使用方向键选择“Troubleshooting”进入故障修复页面,再选择“Rescue a CentOS Linux system”选项,将以“救援模式”引导 Linux 操作系统。
(9)然后选择 “1”确认并按 Enter 键继续,接下来会出现字符界面。
(10)按 Enter 键后将进入Bash Shell 环境。
(11)执行“mkdir /bak”命令创建目录,并执行“mount /dev/sdb1 /bak”命令将硬盘设备挂载到该目录上。
(12)执行“dd if=/bak/sda.mbr.bak of=/dev/sda”命令将备份的主扇区内容放入到主扇区里。
(13)最后执行“reboot”命令重启设备即可。
2、GRUB引导故障
GRUB 是大多数 Linux 操作系统默认使用的引导程序,可以通过启动菜单的方式选择进入不同的操作系统。
故障模拟实验:
(1)执行“cd /boot/”命令再执行“ls”命令可以看到“grub2”目录。
(2)执行“cd grub2”命令再执行“ls”命令可以看到“grub.cfg”配置文件(CentOS 7 采用的是 GRUB2 启动引导器)。 。
(3)执行“rm -rf grub.cfg”删除掉配置文件,然后执行“init 6”命令重启设备。
(4)重启可以发现系统让我们手写启动菜单界面。
(5)重启设备并导入镜像到驱动中,在加载读条时及时按下Esc键进入“Boot Menu”界面。使用方向键选择“CD-ROM Drive”选项进入驱动引导。
(6)在向导界面使用方向键选择“Troubleshooting”进入故障修复页面,再选择“Rescue a CentOS Linux system”选项,将以“救援模式”引导 Linux 操作系统。
(7)然后选择 “1”确认并按 Enter 键继续,接下来会出现字符界面。
(8)按 Enter 键后将进入Bash Shell 环境。
(9)执行“chroot /mnt/sysimage/”命令加载系统镜像,再执行“grub2-install /dev/sda”命令重新建立加载sda分区。
(10)执行“grub2-mkconfig -o /boot/grub2/grub.cfg”命令选择构建grub菜单配置文件。
(11)执行“exit”命令退出bash环境,再执行“reboot”命令重启即可。
五、重置root用户密码
当忘记 root 用户的密码时,将无法登录 Linux 操作系统执行管理、维护等任务,而只能通过其他用户(普通用户)登录使用一些受限制的功能。当然,如果操作系统中还有其他具有 root 权限的用户(uid 为 0),或者拥有修改 root 账号密码权限的用户,也可以使用这些用户登录操作系统,然后重新设置 root 用户的密码。
模拟实验:
1、将镜像放入驱动并重启设备。
2、在加载读条时及时按下Esc键进入“Boot Menu”界面。使用方向键选择“CD-ROM Drive”选项进入驱动引导。
3、在向导界面使用方向键选择“Troubleshooting”进入故障修复页面,再选择“Rescue a CentOS Linux system”选项,将以“救援模式”引导 Linux 操作系统。
4、然后选择 “1”确认并按 Enter 键继续,接下来会出现字符界面。
5、按 Enter 键后将进入Bash Shell 环境。
6、执行“chroot /mnt/sysimage/”命令加载系统镜像, 在执行“passwd root”命令即可重置。