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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

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

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

一、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)

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

三、內(nèi)核引導(dǎo)階段(一)

錯(cuò)誤執(zhí)行 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. 若還沒有重啟系統(tǒng),可做如下操作恢復(fù)

[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]# ? ? ##恢復(fù)成功 2. 若已經(jīng)重啟了系統(tǒng),那么接下來的操作如下圖:


四、內(nèi)核引導(dǎo)階段(二)

錯(cuò)誤執(zhí)行 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. 若還沒有重啟系統(tǒng),可做如下操作恢復(fù)
[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í)別

[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執(zhí)行該操作后,在重啟時(shí)會(huì)遇到這樣的問題


此時(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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。