系统引导过程
通电–>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'
修改之后即可改正系统启动级别,并可以正常开启关闭系统