日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux——系统排错之引导恢复shell

發布時間:2025/3/19 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux——系统排错之引导恢复shell 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、grub 磁盤引導階段

MBR

mbr 的作用是為了記錄 /boot 目錄所在分區位置,磁盤的 0 磁道 1 扇區的前 446 字節

[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

重啟后的操作如下圖:

上圖過后,還有一個選擇,也是選擇OK,就會進入下圖界面



二、grub 文件引導階段

當你用命令 rm -fr 誤刪除了/boot/grub2/grub.cfg文件時,介紹兩種恢復方法。

1. 當發現誤刪除該文件后,如果你還沒有重啟系統的話,那么恭喜你,這很好恢復,如下操作:

[root@localhost Desktop]# rm -fr /boot/grub2/grub.cfg [root@localhost Desktop]# grub2-mkconfig > /boot/grub2/grub.cfg ? ?##因為文件grub2-mkconfig里的內容與刪掉的文件內容一樣 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]# ? ?##恢復文件成功 2.?當發現誤刪除該文件后,如果你已經重啟系統的話,那就好好的跟著下圖的操作做吧
操作截圖:


注意:進入系統后,一定要執行下面的命令!!!不然下次還需要重新引導

[root@localhost Desktop]# 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 Desktop]#

三、內核引導階段(一)

錯誤執行 rm -fr vmlinuz-3.10.0-123.el7.x86_64 該條命令后

[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

1. 若還沒有重啟系統,可做如下操作恢復

[root@localhost boot]# yum whatprovides /boot/vmlinuz-3.10.0-123.el7.x86_64 Loaded plugins: langpacks rhel_dvd/filelists_db | 3.0 MB 00:00:00 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_64kernel-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 ~]# cd /run/media/root/RHEL-7.0\ Server.x86_64/ [root@localhost RHEL-7.0 Server.x86_64]# ls addons images Packages RPM-GPG-KEY-redhat-release EFI isolinux release-notes TRANS.TBL EULA LiveOS repodata GPL media.repo RPM-GPG-KEY-redhat-beta [root@localhost RHEL-7.0 Server.x86_64]# cd Packages/ [root@localhost Packages]# pwd /run/media/root/RHEL-7.0 Server.x86_64/Packages [root@localhost Packages]# cp kernel-3.10.0-123.el7.x86_64.rpm /root/Desktop/ [root@localhost boot]# cd /root/Desktop/ [root@localhost Desktop]# ls kernel-3.10.0-123.el7.x86_64.rpm [root@localhost Desktop]# file kernel-3.10.0-123.el7.x86_64.rpm kernel-3.10.0-123.el7.x86_64.rpm: RPM v3.0 bin i386/x86_64 kernel-3.10.0-123.el7 [root@localhost Desktop]# rpm2cpio kernel-3.10.0-123.el7.x86_64.rpm | cpio -id 219282 blocks [root@localhost Desktop]# ls boot etc kernel-3.10.0-123.el7.x86_64.rpm lib [root@localhost Desktop]# cp boot/vmlinuz-3.10.0-123.el7.x86_64 /boot/ [root@localhost Desktop]# ? ? ##恢復成功 2. 若已經重啟了系統,那么接下來的操作如下圖:


四、內核引導階段(二)

錯誤執行 rm -fr /boot/initramfs-3.10.0-123.el7.x86_64.img 該條命令后

[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 /boot/initramfs-3.10.0-123.el7.x86_64.img [root@localhost boot]# ls config-3.10.0-123.el7.x86_64 grub grub2 initramfs-0-rescue-946cb0e817ea4adb916183df8c4fc817.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_641. 若還沒有重啟系統,可做如下操作恢復
[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]# ? ? ? ? ? ? ?##恢復成功 2. 若已經重啟了系統,那么接下來的操作如下圖:



五、啟動級別被改變后所引起的系統問題

啟動級別設置

systemctl set-default + 啟動級別

[root@localhost Desktop]# systemctl set-default multi-user.target ? rm '/etc/systemd/system/default.target' ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target' [root@localhost Desktop]# 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 Desktop]# reboot執行該操作后,在重啟時會遇到這樣的問題


此時的操作如下圖所示:


注意:進入系統后,一定要執行下面的命令!!!不然下次還需要重新設置

[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]#

系統啟動級別介紹

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運行級別0:系統停機狀態,系統默認運行級別不能設為0,否則不能正常啟動
運行級別1:單用戶工作狀態,root權限,用于系統維護,禁止遠程登陸
運行級別2:多用戶狀態(沒有NFS)
運行級別3:完全的多用戶狀態(有NFS),登陸后進入控制臺命令行模式
運行級別4:系統未使用,保留
運行級別5:X11控制臺,登陸后進入圖形GUI模式
運行級別6:系統正常關閉并重啟,默認運行級別不能設為6,否則不能正常啟動

總結

以上是生活随笔為你收集整理的linux——系统排错之引导恢复shell的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。