系统排错---让系统正常启动

1 系统启动流程

简单来说,系统启动的过程如下

(1)加载BIOS的硬件信息与进行自我测试,并依据设置取得第一个可启动的设备;
(2)读取并执行第一个启动设备内MBR(主引导分区)的boot loader(引导装载程序,即是grub,spfdisk等程序);
(3)依据boot loader的设置加载kernel(内核文件),kernel会开始检测硬件与加载驱动程序;
(4)在硬件驱动成功后,kernel会主动调用init进程,而init进程会取得run-level(运行级别)信息;
(5)init执行/etc/rc.d/rc.sysinit文件来准备软件执行的操作环境(如网络、时区等);
(6)init执行run-level的各个服务的启动(script方式);
(7)init执行/etc/rc.d/rc.local(用户自定义开机启动程序)文件;
(8)init执行终端机模拟程序mingetty来启动login进程,最后就等待用户登陆。

2 系统排错

2.1 硬盘引导阶段错误
对应上面流程的第二步中,引导装载程序(boot loader)安装在启动设备的第一个扇区(sector)内,也就是我们一直谈到的MBR(MasterBoot Record,主引导分区)。当MBR内的字节被破坏,需要进行MBR主引导分区的恢复
模拟问题,截取MBR的446个字节:dd if=/dev/zero of=/dev/vda bs=446 count=1
解决方法:

系统关机状态下,添加cdrom
把iso镜像装进cdrom 选择光盘启动
先选择选择troubleshooting中的挽救模式rescue 
选择1-->continue-->  回车打开shell 
chroot /mnt/sysimage/,更改挂载目录为根目录
grub2-install 启动分区所在硬盘
grub2-install /dev/vda
exit退出两次
然后选择从硬盘启动

截取MBR的446个字节
在这里插入图片描述
系统无法启动

在这里插入图片描述
添加光盘,导入镜像,选择从光盘启动
在这里插入图片描述
在这里插入图片描述
选择troubleshooting中的挽救模式rescue
在这里插入图片描述
在这里插入图片描述
选择1–>continue–> 回车打开shell ,chroot /mnt/sysimage/,grub2-install /dev/vda,exit退出两次
在这里插入图片描述
最后,选择硬盘启动,系统恢复正常
在这里插入图片描述

2.2 文件引导阶段错误
2.2.1 引导文件丢失:/boot/grub2/grub.cfg文件丢失

  对应启动流程中的第二步boot loader引导装载程序的文件丢失。
模拟问题,/boot/grub2/grub.cfg文件被删除,rm -fr /boot/grub2/grub.cfg

当系统没有重新启动时:grub2-mkconfig > /boot/grub2/grub.cfg

当系统被重新启动:
grub > set root='hd0,msdos1' 此位置是不确定的,位置指定/boot 分区
grub > linux16 /vmlinuz-3.10.0-123.el7.x86_64 ro root=/dev/vda1  (写根分区)根分区的设备名称
grub > initrd16 /initramfs-3.10.0-1213.el7.x86_64.img  系统初始化镜像
grub > boot

以上操作可以使系统正常启动,但是是临时的,所以进入系统后还是需要执行:
grub2-mkconfig > /boot/grub2/grub.cfg

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2.2.2 内核文件(vmlinuz)丢失

对应上述流程的第三步,根据boot loader引导启动内核文件,当内核文件被删除后,无法加载内核,导致不能正常启动。
模拟问题:rm -fr /boot/vmlinuz-3.10.0-514.el7.x86_64
内核文件在安装系统时使用的镜像文件ios的packages中,
所以,光盘启动时,我们可以拆解packages包,将需要的内核文件复制到原来的位置中

切换成光盘启动,进入挽救模式:
chroot /mnt/sysimage
mount /dev/cdrom /media
cd /media/Packages
cp kernel-3.10.0-514.el7.x86_64.rpm   /mnt
cd /mnt
rpm2cpio kernel-3.10.0-514.el7.x86_64  | cpio -id
cd boot
cp vmlinuz-3.10.0-514.el7.x86_64   /boot
exit
exit
然后切换成硬盘启动

在这里插入图片描述
在这里插入图片描述
切换成光盘启动,进入挽救模式
在这里插入图片描述
切换成硬盘启动,正常进入系统
在这里插入图片描述
2.3 系统初始化镜像文件丢失

对应启动流程的第四步,在加载内核后启动init程序进入初始化阶段,当初始化镜像文件丢失后,需要使用命令生成镜像文件
模拟问题:rm -fr /boot/initramfs-3.10 .img

当系统没有重启时:mkinitrd /boot/initramfs-$(umane -r).img $(uname -r)

当系统重启后:切换成光盘启动,进入挽救模式 chroot /mnt/sysimage 
mkinitrd /boot/initramfs-$(uname -r).img $(uname -r)
然后exit两次  切换成硬盘启动

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

2.4 当开机启动级别被篡改

对应启动流程的第四步,启动级别被篡改后,比如篡改为开机重启级别,就会一直开机重启,所以,需要改变开机启动级别
错误形成systemctl set-default reboot.target

1.开机按上下键停止读秒
2 按“E”进入编辑模式
3 选择内核启动行
linux16 /vmlinuz-xxxxxxx ro xxxxxxxxxxxxx 改变为:
linux16 /vmlinuz-xxxxxxxx ro xxxxxxxxxx 5
然后ctrl +x 
4. 启动系统   然后在系统中重新设定 systemctl set-default graphical.target

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2.5 忘记超户密码

最后一步需要用户的登陆,当我们忘记超户的密码时,重新编辑引导条目

在系统启动阶段按上下健停止系统引导,按“E”进行编辑
找到linux16引导条目这一行,从这行最后删除到ro选项,并把ro改为rw,然后添加rd.break选项
ctrl+x启动设定过后的系统引导条目
chroot /sysroot/ ,切换到真实的系统环境
echo westos | passwd --stdin root  
建立文件/.autorelabel让系统从新扫描所有文件
exit两次使系统自动重新启动

在这里插入图片描述
在这里插入图片描述
如此,就可以使用新密码westos登陆超户了!!!
############################The End################################

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Optimize Windows system reliability and performance with Sysinternals IT pros and power users consider the free Windows Sysinternals tools indispensable for diagnosing, troubleshooting, and deeply understanding the Windows platform. In this extensively updated guide, Sysinternals creator Mark Russinovich and Windows expert Aaron Margosis help you use these powerful tools to optimize any Windows system’s reliability, efficiency, performance, and security. The authors first explain Sysinternals’ capabilities and help you get started fast. Next, they offer in-depth coverage of each major tool, from Process Explorer and Process Monitor to Sysinternals’ security and file utilities. Then, building on this knowledge, they show the tools being used to solve real-world cases involving error messages, hangs, sluggishness, malware infections, and much more. Windows Sysinternals creator Mark Russinovich and Aaron Margosis show you how to: Use Process Explorer to display detailed process and system information Use Process Monitor to capture low-level system events, and quickly filter the output to narrow down root causes List, categorize, and manage software that starts when you start or sign in to your computer, or when you run Microsoft Office or Internet Explorer Verify digital signatures of files, of running programs, and of the modules loaded in those programs Use Autoruns, Process Explorer, Sigcheck, and Process Monitor features that can identify and clean malware infestations Inspect permissions on files, keys, services, shares, and other objects Use Sysmon to monitor security-relevant events across your network Generate memory dumps when a process meets specified criteria Execute processes remotely, and close files that were opened remotely Manage Active Directory objects and trace LDAP API calls Capture detailed data about processors, memory, and clocks Troubleshoot unbootable devices, file-in-use errors, unexplained communication, and many other problems Understand Windows core concepts that aren’t well-documented elsewhere Table of Contents PART I: GETTING STARTED Chapter 1 Getting started with the Sysinternals utilities Chapter 2 Windows core concepts Chapter 3 Process Explorer Chapter 4 Autoruns PART II: USAGE GUIDE Chapter 5 Process Monitor Chapter 6 ProcDump Chapter 7 PsTools Chapter 8 Process and diagnostic utilities Chapter 9 Security utilities Chapter 10 Active Directory utilities Chapter 11 Desktop utilities Chapter 12 File utilities Chapter 13 Disk utilities Chapter 14 Network and communication utilities Chapter 15 System information utilities Chapter 16 Miscellaneous utilities PART III: TROUBLESHOOTING—“THE CASE OF THE UNEXPLAINED…” Chapter 17 Error messages Chapter 18 Crashes Chapter 19 Hangs and sluggish performance Chapter 20 Malware Chapter 21 Understanding system behavior Chapter 22 Developer troubleshooting
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值