linux——系统排错之引导恢复shell
一、grub 磁盤引導(dǎo)階段
MBR
mbr 的作用是為了記錄 /boot 目錄所在分區(qū)位置,磁盤的 0 磁道 1 扇區(qū)的前 446 字節(jié)
[root@localhost Desktop]# fdisk -l Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x00000000Device Boot Start End Blocks Id System /dev/vda1 * 2048 20970332 10484142+ 83 LinuxDisk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes[root@localhost Desktop]# dd if=/dev/zero of=/dev/vda bs=446 count=1 1+0 records in 1+0 records out 446 bytes (446 B) copied, 0.000137605 s, 3.2 MB/s [root@localhost Desktop]# reboot重啟后的操作如下圖:
上圖過后,還有一個(gè)選擇,也是選擇OK,就會(huì)進(jìn)入下圖界面
二、grub 文件引導(dǎo)階段
當(dāng)你用命令 rm -fr 誤刪除了/boot/grub2/grub.cfg文件時(shí),介紹兩種恢復(fù)方法。
1. 當(dāng)發(fā)現(xiàn)誤刪除該文件后,如果你還沒有重啟系統(tǒng)的話,那么恭喜你,這很好恢復(fù),如下操作:
[root@localhost Desktop]# rm -fr /boot/grub2/grub.cfg [root@localhost Desktop]# grub2-mkconfig > /boot/grub2/grub.cfg ? ?##因?yàn)槲募rub2-mkconfig里的內(nèi)容與刪掉的文件內(nèi)容一樣 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 Desktop]# ? ?##恢復(fù)文件成功 2.?當(dāng)發(fā)現(xiàn)誤刪除該文件后,如果你已經(jīng)重啟系統(tǒng)的話,那就好好的跟著下圖的操作做吧操作截圖:
注意:進(jìn)入系統(tǒng)后,一定要執(zhí)行下面的命令!!!不然下次還需要重新引導(dǎo)
三、內(nèi)核引導(dǎo)階段(一)
錯(cuò)誤執(zhí)行 rm -fr vmlinuz-3.10.0-123.el7.x86_64 該條命令后
1. 若還沒有重啟系統(tǒng),可做如下操作恢復(fù)
四、內(nèi)核引導(dǎo)階段(二)
錯(cuò)誤執(zhí)行 rm -fr /boot/initramfs-3.10.0-123.el7.x86_64.img 該條命令后
[root@localhost boot]# rm -fr /boot/initramfs-3.10.0-123.el7.x86_64.img [root@localhost boot]# mkinitrd /boot/initramfs-3.10.0-123.el7.x86_64.img 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 vmlinuz-3.10.0-123.el7.x86_64 [root@localhost boot]# ? ? ? ? ? ? ?##恢復(fù)成功 2. 若已經(jīng)重啟了系統(tǒng),那么接下來的操作如下圖:
五、啟動(dòng)級(jí)別被改變后所引起的系統(tǒng)問題
啟動(dòng)級(jí)別設(shè)置
systemctl set-default + 啟動(dòng)級(jí)別
此時(shí)的操作如下圖所示:
注意:進(jìn)入系統(tǒng)后,一定要執(zhí)行下面的命令!!!不然下次還需要重新設(shè)置
[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' [root@localhost Desktop]#系統(tǒng)啟動(dòng)級(jí)別介紹
runlever0.target -> poweroff.target runlever1.target -> rescue.target runlever2.target -> multi-user.target runlever3.target -> multi-user.target runlever4.target -> multi-user.target runlever5.target -> grapical.target runlever6.target -> reboot.target運(yùn)行級(jí)別0:系統(tǒng)停機(jī)狀態(tài),系統(tǒng)默認(rèn)運(yùn)行級(jí)別不能設(shè)為0,否則不能正常啟動(dòng)運(yùn)行級(jí)別1:單用戶工作狀態(tài),root權(quán)限,用于系統(tǒng)維護(hù),禁止遠(yuǎn)程登陸
運(yùn)行級(jí)別2:多用戶狀態(tài)(沒有NFS)
運(yùn)行級(jí)別3:完全的多用戶狀態(tài)(有NFS),登陸后進(jìn)入控制臺(tái)命令行模式
運(yùn)行級(jí)別4:系統(tǒng)未使用,保留
運(yùn)行級(jí)別5:X11控制臺(tái),登陸后進(jìn)入圖形GUI模式
運(yùn)行級(jí)別6:系統(tǒng)正常關(guān)閉并重啟,默認(rèn)運(yùn)行級(jí)別不能設(shè)為6,否則不能正常啟動(dòng)
總結(jié)
以上是生活随笔為你收集整理的linux——系统排错之引导恢复shell的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linun——SElinux的简单理解
- 下一篇: linux 其他常用命令