Centos7 -- glibc 升級失敗、意外刪除、故意刪除后的處理方法


第一部分:測試(如果不是想測試效果,可以直接跳到第三部分)

鑒於不久前 glibc-2.29 升級失敗導致一系列的工具無法正常使用,‘’

本着研究精神的我決定刪除 glibc及其庫文件 ,測試影響范圍到底有多廣:

# rpm -e glibc glibc-devel   

提示: gcc 依賴 glibc-devel  (因為我的gcc是升級過的,正常不需要依賴它)

           幾萬個包 依賴  glibc

# rpm -qf glibc      //預習一下glibc到底包括哪些文件,缺哪個你就知道是找它哦

# rpm -e glibc glibc-devel --nodeps  //好孩子不要輸入這個哦!

warning: %postun(glibc-2.17-260.el7_6.3.x86_64) scriptlet failed, exit status 127

於是報錯:

# rpm     // ls 、 cp、reboot、shutdown、init 等系統指令都是缺同一個文件,就不列明了

-bash:/bin/rpm: /lib64/ld-linux-86-64.so.2: bad ELF interpreter: No such file or directory

# yum

-bash:/bin/yum: /usr/bin/python: bad interpreter:No such file or directory   (yum本質上就是一個python腳本)

# ldd

-bash:/bin/ldd: /usr/bin/bash: bad interpreter:No such file or directory (ldd是shell腳本呢)

# cd   //居然是正常的!

簡單來說,基本上字符界面(終端)下的所有指令均不可使用,你無法在系統登錄狀態下做任何的拯救。

但是有趣的是,已加載的gnome桌面所有左右鍵操作均為正常,所以桌面沒退出的話還有一方法,就是當windows救吧(不過重啟肯定是起不來的)

 

 

第二部分 土方法,缺哪個補哪個(可忽略):

1. 准備一個U盤啟動盤(一個好的運維隨時都有一個U盤啟動盤)

2.按住電源鍵重啟(你的指令都用不了)

   BIOS選擇U盤啟動 (不同設備不同)

   進入拯救模式 (Troubleshooting --> Rescue a CentOS system)

3.提示:

  Rescue

  The rescue environment will not attempt to find your Linux installation and

  mount it under the directory : /mnt/sysimage . You can then make any changes

  required to your system. Choice '1' to proceed with this step.

  You can choose to mount your file systems read-only instead of read-write by

  choosing '2' .

  If for some reason this process does not work choose '3' to skip directly to a

  shell.

  1)Continue

  2) Read-only mount

  3) Skip to shell

  4) Quit(Reboot)

       Please make a selection from the above :

  選擇1   回車 

 

  chroot /mnt/sysimage   

  會出現以下三種報錯:

  chroot:failed to run command '/bin/bash': No such file or directory  //如果有留意上面測試步驟,會發現 /bin/bash 實際上缺的是  /lib64/ld-linux-86-64.so.2 這個文件

  sh-4.2# cp /lib64/ld-linux-x86-64.so.2 /mnt/sysimage/

  /bin/bash:error while loading shared libraries: libdl.so.2 : cannot open shared object file: No such file or directory

  sh-4.2# cp /lib64/libdl.so.2 /mnt/sysimage/lib64/

  /bin/bash:error while loading shared libraries: libc.so.2 : cannot open shared object file: No such file or directory

   sh-4.2# cp /lib64/libc.so.6 /mnt/sysimage/lib64/

 

  chroot /mnt/sysimage //成功,但yum與rpm還是不能用:

  rpm需要這些包:

  sh-4.2# cp /lib64/libm.so.6 /mnt/sysimage/lib64/

  sh-4.2# cp /lib64/libpthread.so.0 /mnt/sysimage/lib64/

  sh-4.2# cp /lib64/librt.so.1 /mnt/sysimage/lib64/

  yum還需要:

  sh-4.2# cp /lib64/libutil.so.1 /mnt/sysimage/lib64/

  sh-4.2# cp /lib64/libresolv.so.2 /mnt/sysimage/lib64/

  sh-4.2# cp /lib64/libcrypt.so.1 /mnt/sysimage/lib64/

  netwok服務需要:

   sh-4.2# cp /lib64/libnsl.so.1 /mnt/sysimage/lib64/  

  sh-4.2#  cp /lib64/libcrypt.so.1  /mnt/sysimage/lib64/

  

 

 

第三部分:真正的拯救方法:

1. 准備一個U盤啟動盤(一個好的運維隨時都有一個U盤啟動盤)

2.按住電源鍵重啟(你的指令都用不了)

   BIOS選擇U盤啟動 (不同設備不同)

   進入拯救模式 (Troubleshooting --> Rescue a CentOS system)

3.提示:

  Rescue

  The rescue environment will not attempt to find your Linux installation and

  mount it under the directory : /mnt/sysimage . You can then make any changes

  required to your system. Choice '1' to proceed with this step.

  You can choose to mount your file systems read-only instead of read-write by

  choosing '2' .

  If for some reason this process does not work choose '3' to skip directly to a

  shell.

  1)Continue

  2) Read-only mount

  3) Skip to shell

  4) Quit(Reboot)

       Please make a selection from the above :

  選擇1   回車 

 4. 如果你像我一樣知道自己干了什么壞事,而且鏡像包里什么包都全的話,直接裝就好了

    sh-4.2# mkdir /mnt/cdrom         //千萬不要掛載到 /mnt 下 你還掛着個系統呢!

    sh-4.2# blkid   //查看U盤是哪個

    sh-4.2# mount  /dev/sda1 /mnt/cdrom     //掛載U盤,我的U盤是/dev/sda1 

 sh-4.2# rpm -ivh /mnt/cdrom/Packages/glibc* --nodeps --root /mnt/sysimage --force     //一定要指定root,因為你目前的根目錄是U盤的

 sh-4.2# reboot   //第一次重啟時間會比較久,耐心點

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM