Linux之系统排错

系统引导过程

通电–>bios初始化–>grub磁盘引导阶段–>grub文件引导阶段–>指定boot所在分区–>启动内核,只读/挂载设备–>启动init程序进入初始化阶段–>启动systemd初始化进程–>取/etc/systemd中的文件–>启动程序–>启动登陆环境

磁盘引导错误:MBR丢失

这里写图片描述
重启后会显示如下界面:
这里写图片描述
解决方法:
在真机virt-manager打开如下界面:将测试机server关闭
这里写图片描述
设置光驱启动
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
选择系统修复
这里写图片描述
选择挽救模式
这里写图片描述
进入挽救环境
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
关闭系统,修改成硬盘启动
这里写图片描述
开启系统后,就会进入登录界面,即可修复成功
这里写图片描述
登录进入,界面会多一个镜像
这里写图片描述

grub引导文件丢失

1.文件丢失后没有重启系统
[root@localhost Desktop]# cd /boot/
[root@localhost boot]# ls
config-3.10.0-123.el7.x86_64
grub
grub2
initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img
initramfs-3.10.0-123.el7.x86_64.img
initrd-plymouth.img
symvers-3.10.0-123.el7.x86_64.gz
System.map-3.10.0-123.el7.x86_64
vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817
vmlinuz-3.10.0-123.el7.x86_64
[root@localhost boot]# cd grub2
[root@localhost grub2]# ls
device.map  fonts  grub.cfg  grubenv  i386-pc  locale  themes
[root@localhost grub2]# rm -fr grub.cfg  删除grub引导文件
[root@localhost grub2]# grub2-mkconfig > /boot/grub2/grub.cfg  恢复文件
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817
Found initrd image: /boot/initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img
done
[root@localhost grub2]# ls  查看文件是否被恢复
device.map  fonts  grub.cfg  grubenv  i386-pc  locale  themes
2.文件丢失后重启了系统
[root@localhost Desktop]# rm -fr /boot/grup2/grup.cfg  删除文件
[root@localhost Desktop]# reboot

重启之后直接进入了如下界面:
这里写图片描述
进入系统后

[root@localhost ~]# grub2-mkconfig > /boot/grub2/grub.cfg  恢复文件
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817
Found initrd image: /boot/initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img
done

完成上述操作即可正常启动系统

内核文件丢失

1.文件丢失后没有重启系统

删除内核文件

[root@localhost Desktop]# cd /boot/
[root@localhost boot]# ls  查看内核文件
config-3.10.0-123.el7.x86_64
grub
grub2
initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img
initramfs-3.10.0-123.el7.x86_64.img
initrd-plymouth.img
symvers-3.10.0-123.el7.x86_64.gz
System.map-3.10.0-123.el7.x86_64
vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817
vmlinuz-3.10.0-123.el7.x86_64
[root@localhost boot]# rm -fr vmlinuz-3.10.0-123.el7.x86_64  删除内核文件
[root@localhost boot]# ls
config-3.10.0-123.el7.x86_64
grub
grub2
initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img
initramfs-3.10.0-123.el7.x86_64.img
initrd-plymouth.img
symvers-3.10.0-123.el7.x86_64.gz
System.map-3.10.0-123.el7.x86_64
vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817
[root@localhost boot]# yum whatprovides /boot/vmlinuz-3.10.0-123.el7.x86_64   查看内核文件在那个安装包里面
Loaded plugins: langpacks
kernel-3.10.0-123.el7.x86_64 : The Linux kernel
Repo        : rhel_dvd
Matched from:
Filename    : /boot/vmlinuz-3.10.0-123.el7.x86_64
kernel-3.10.0-123.el7.x86_64 : The Linux kernel
Repo        : installed
Matched from:
Filename    : /boot/vmlinuz-3.10.0-123.el7.x86_64

将安装包从镜像复制在桌面
这里写图片描述
恢复内核文件

[root@localhost boot]# cd 
[root@localhost ~]# cd Desktop
[root@localhost Desktop]# rpm2cpio kernel-3.10.0-123.el7.x86_64.rpm | cpio -id  解压含有内核文件的软件包
219282 blocks
[root@localhost Desktop]# cp boot/vmlinuz-3.10.0-123.el7.x86_64 /boot/  将解压出来的内核文件复制在boot目录里面,即可恢复系统内核文件,没有镜像时可以在其他主机拷贝内核文件
[root@localhost Desktop]# ls /boot/  可以查看到内核文件
config-3.10.0-123.el7.x86_64
grub
grub2
initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.img
initramfs-3.10.0-123.el7.x86_64.img
initrd-plymouth.img
symvers-3.10.0-123.el7.x86_64.gz
System.map-3.10.0-123.el7.x86_64
vmlinuz-0-rescue-946cb0e817ea4adb916183df8c4fc817
vmlinuz-3.10.0-123.el7.x86_64
2.文件丢失后重启了系统
[root@localhost boot]# rm -fr vmlinuz-3.10.0-123.el7.x86_64
[root@localhost boot]# reboot

重启后显示如下界面,提示没有内核文件
这里写图片描述
关闭系统,设置光驱启动(具体步骤见上文中的磁盘引导错误),然后打开系统进入到挽救环境
这里写图片描述
关闭系统,修改成硬盘启动,即可正常启动系统

系统初始化文件丢失

1.文件丢失后没有重启系统

这里写图片描述
其中uname -r 是查看内核版本号
这里写图片描述

2.文件丢失后重启了系统

这里写图片描述
重启后显示如下界面,提示没有初始化文件
这里写图片描述
关闭系统,设置光驱启动(具体步骤见上文中的磁盘引导错误),然后打开系统进入到挽救环境
这里写图片描述
关闭系统,修改成硬盘启动,即可正常启动系统

启动级别发生错误

linux系统有0-6个启动级别
0表示关机,系统默认运行级别不能设置为0,否则不能正常启动
1表示单用户工作状态,root权限,用于系统维护,禁止远程登陆
2表示多用户状态
3表示完全多用户状态,登录后进入控制台命令行模式
4表示系统未使用,保留
5代表有图形模式启动
6表示正常关闭并重启,默认运行不能设为6,否则不能正常启动

改变系统级别

[root@localhost ~]# systemctl set-default shutdown.target  设置系统开启时直接关闭
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/shutdown.target' '/etc/systemd/system/default.target'
[root@localhost ~]# reboot

在系统启动阶段按上下健停止系统系统引导
选择启动引导标题,按“e”进行编辑
找到内核启动行
这里写图片描述
ctrl+x启动设定过后的系统引导条目
进入系统
修改开机默认运行级别

[root@localhost Desktop]# systemctl set-default graphical.target 
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target'

修改之后即可改正系统启动级别,并可以正常开启关闭系统

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值