刪除系統檔案及其修複

來源:互聯網
上載者:User

刪除系統檔案及其修複 一 刪除boot目錄下的所有檔案[plain] #刪除/boot,然後重啟  [root@serv01 boot]# rm -rf *  [root@serv01 boot]# ls  [root@serv01 boot]# reboot  #會發現出現錯誤  Error 15     #我們關閉虛擬機器,然後使用光碟片進行驅動,注意把記憶體調整為800M;重啟電腦,在啟動的一瞬間,按ESC鍵,進入Boot Menu,選擇CD-ROM Drive  #進入引導介面,選擇Rescueinstalled system,Choose a language,選擇English,Keyboad Type選擇us,Rescue method選擇Local CD/DVD,Setup networking選擇no,Rescue選擇Contiune,Rescue選擇ok,下一個介面再次選擇ok,shell start shell,啟動shell。     #發現進入的是bash,此時cd /boot是不行的  #輸入chroot/mnt/sysimage進入/,然後進入/boot,發現bash變為sh  #配置yum源,  ls  ls /iso  mount /dev/cdrom /iso  #重裝核心  yum reinstall kernerl -y  #也可以使用rpm安裝 rpm -ivhkenerl-xxx --force --replacefiles     #安裝grub  grub-install /dev/sda  #退出sh  exit  #進入bash,然後重啟  reboot  #進入grub,依次執行以下內容(按Tab鍵)  root (hd0,0)     kernel /vmlinuz-2.6.32-131.0.15.el6.x86_64  initrd /initramfs-2.6.32-131.0.15.el6.x86_64.img  boot  #再次進入grub,依次執行以下內容  root (hd0,0)     kernel /vmlinuz-2.6.32-131.0.15.el6.x86_64  initrd/initramfs-2.6.32-131.0.15.el6.x86_64.img  boot        #修複成功,可以編輯grub.conf檔案,下次就不重新引導,grub.conf檔案如下  [root@serv01 opt]# cd /boot/grub/  [root@serv01 grub]# vim grub.conf  [root@serv01 grub]# cat grub.conf  default=0  timeout=5  title RedHat Server 6.1         root(hd0,0)         kernel/vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/sda2         initrd/initramfs-2.6.32-131.0.15.el6.x86_64.img        [root@larrywen /]# ssh 192.168.1.11  root@192.168.1.11's password:  Last login: Wed Jul 31 18:05:19 2013 from192.168.1.1     #建議把/boot分區放在第一個位置   二 rc.sysinit檔案丟失[plain] #rc.sysinit檔案丟失,進入修複模式,方法同上,只需重新安裝(拷貝)這個檔案即可  [root@serv01 grub]# ls /etc/rc.d/rc.sysinit  /etc/rc.d/rc.sysinit  #安裝出錯  [root@serv01 grub]#yum install/etc/rc.d/rc.sysinit  #重新安裝  [root@serv01 grub]#yum reinstall/etc/rc.d/rc.sysinit     [root@serv01 ~]# rpm -qf/etc/rc.d/rc.sysinit  initscripts-9.03.23-1.el6.x86_6  #其他的系統檔案丟失,類似操作   三 grub.conf檔案被刪除[plain] #可以看到/etc/grub.conf/boot/grub/grub.conf是同一個檔案  [root@serv01 ~]# ls /etc/grub.conf/boot/grub/grub.conf -l  -rw-------. 1 root root 817 Jul 30 23:47 /boot/grub/grub.conf  lrwxrwxrwx. 1 root root  22 Jul 23 00:57 /etc/grub.conf ->../boot/grub/grub.conf     #刪除grub.conf檔案後不能引導解決  #第一步,查看磁碟分割  [root@serv01 ~]# df -h  Filesystem            Size  Used Avail Use% Mounted on  /dev/sda2             9.7G  1.1G 8.1G  12% /  tmpfs                 188M     0 188M   0% /dev/shm  /dev/sda1             194M   25M 160M  14% /boot  /dev/sda5             4.0G  137M 3.7G   4% /opt  /dev/sr0              3.4G  3.4G    0 100% /iso     #進入目錄刪除grub.conf檔案  [root@serv01 ~]# cd /boot/grub/  [root@serv01 grub]# rm -rf grub.conf     [root@serv01 grub]# reboot     #依次輸入這些命令  root (hd0,0)  #這一步按住tab鍵會自動補齊的  kernel /  #然後在後面加上root=/dev/sda2,注意,您的機器不一定是/dev/sda2,您要通過df -h查看根分區是屬於哪個分區  kernel /vmlinuz-2.6.32-131.0.15.el6.x86_64ro root=/dev/sda2  #這一步按住tab鍵也會自動補齊的  initrd /  initrd/initramfs-2.6.32-131.0.15.el6.x86_64.img  #注意,如果有多個核心,需要自行選擇  #最後輸入boot重啟     #重啟後,進入boot目錄,發現沒有產生這個檔案  [root@serv01 ~]# cd /boot/grub/  [root@serv01 grub]# ls grub.conf  ls: cannot access grub.conf: No such fileor directory        #下次啟動時我們發現還需要重新引導,此時我們重新建立這個檔案,輸入以下內容即可  #這裡有個小技巧,我們在使用vim編輯檔案時,在命令模式,可以讀入命令,就可以很方便地讀取和拷貝(!表示執行命令)  r !ls/boot/initramfs-2.6.32-131.0.15.el6.x86_64.img     [root@serv01 grub]# vim grub.conf  [root@serv01 grub]# cat grub.conf  default=0  timeout=5  title RedHat Server 6.1         root(hd0,0)         kernel/vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/sda2         initrd/initramfs-2.6.32-131.0.15.el6.x86_64.img     [root@larrywen grub]# ls  device.map splash.xpm.gz     [root@serv01 grub]# find . -name"*stage*"  ./minix_stage1_5  ./stage1  ./xfs_stage1_5  ./ufs2_stage1_5  ./ffs_stage1_5  ./e2fs_stage1_5  ./stage2  ./jfs_stage1_5  ./iso9660_stage1_5  ./vstafs_stage1_5  ./fat_stage1_5  ./reiserfs_stage1_5  #把帶有stage的檔案全部刪除也不影響,重啟仍然正常  [root@serv01 grub]# find . -name"*stage*" |xargs rm -rf {}\;  [root@serv01 grub]# ll  total 8  -rw-r--r--. 1 root root   63 Jul 23 00:57 device.map  -rw-r--r--. 1 root root  170 Jul 31 00:30 grub.conf  lrwxrwxrwx. 1 root root   11 Jul 23 00:57 menu.lst -> ./grub.conf  -rw-r--r--. 1 root root 1341 May  7  2010splash.xpm.gz   四 進入boot目錄,刪除所有的檔案,在不中斷連線的情況下恢複[plain] [root@serv01 ~]# cd /boot  [root@serv01 boot]# ls  config-2.6.32-131.0.15.el6.x86_64  initramfs-2.6.32-131.0.15.el6.x86_64.img  System.map-2.6.32-131.0.15.el6.x86_64  efi                                lost+found                               vmlinuz-2.6.32-131.0.15.el6.x86_64  grub                              symvers-2.6.32-131.0.15.el6.x86_64.gz  [root@serv01 boot]# rm -rf *  [root@serv01 boot]# ll  total 0  #第一步,安裝grub  [root@serv01 boot]# grub-install /dev/sda  Probing devices to guess BIOS drives. Thismay take a long time.  Installation finished. No error reported.  This is the contents of the device map /boot/grub/device.map.  Check if this is correct or not. If any ofthe lines is incorrect,  fix it and re-run the script`grub-install'.     (fd0)      /dev/fd0  (hd0)      /dev/sda  #第二步,安裝kernel  [root@serv01 boot]# yum reinstall kernel -y  Loaded plugins: product-id, subscription-manager  Updating Red Hat repositories.  Setting up Reinstall Process  rhel-iso                                                                                                      | 4.0 kB     00:00 ...  Resolving Dependencies  --> Running transaction check  ---> Package kernel.x86_640:2.6.32-131.0.15.el6 will be installed  --> Finished Dependency Resolution     Dependencies Resolved     ======================================================================================================================================   Package                     Arch                        Version                                  Repository                     Size  ======================================================================================================================================  Reinstalling:   kernel                      x86_64                      2.6.32-131.0.15.el6                      rhel-iso                       23 M     Transaction Summary  ======================================================================================================================================  Reinstall     1 Package(s)     Total download size: 23 M  Installed size: 108 M  Downloading Packages:  Running rpm_check_debug  Running Transaction Test  Transaction Test Succeeded  Running Transaction  Installing :kernel-2.6.32-131.0.15.el6.x86_64                                                                                 1/1  duration: 263(ms)  Installed products updated.     Installed:   kernel.x86_64 0:2.6.32-131.0.15.el6                                                                                                      Complete!     [root@serv01 boot]# ls  config-2.6.32-131.0.15.el6.x86_64  initramfs-2.6.32-131.0.15.el6.x86_64.img  System.map-2.6.32-131.0.15.el6.x86_64  grub                               symvers-2.6.32-131.0.15.el6.x86_64.gz     vmlinuz-2.6.32-131.0.15.el6.x86_64     #進入grub目錄,然後建立grub.conf檔案  [root@serv01 boot]# cd grub/  [root@serv01 grub]# ll  total 268  -rw-r--r--. 1 root root     30 Jul 31 00:44 device.map  -rw-r--r--. 1 root root  13396 Jul 31 00:44 e2fs_stage1_5  -rw-r--r--. 1 root root  12620 Jul 31 00:44 fat_stage1_5  -rw-r--r--. 1 root root  11764 Jul 31 00:44 ffs_stage1_5  -rw-r--r--. 1 root root  11772 Jul 31 00:44 iso9660_stage1_5  -rw-r--r--. 1 root root  13300 Jul 31 00:44 jfs_stage1_5  -rw-r--r--. 1 root root  11956 Jul 31 00:44 minix_stage1_5  -rw-r--r--. 1 root root  14444 Jul 31 00:44 reiserfs_stage1_5  -rw-r--r--. 1 root root    512 Jul 31 00:44 stage1  -rw-r--r--. 1 root root 126040 Jul 31 00:44stage2  -rw-r--r--. 1 root root  12040 Jul 31 00:44 ufs2_stage1_5  -rw-r--r--. 1 root root  11396 Jul 31 00:44 vstafs_stage1_5  -rw-r--r--. 1 root root  13980 Jul 31 00:44 xfs_stage1_5  [root@serv01 grub]# vim grub.conf  #檔案內容如下  [root@serv01 grub]# cat grub.conf  default=0  timeout=5  title Redhat Server 6.1         root(hd0,0)         kernel/vmlinuz-2.6.32-131.0.15.el6.x86_64 ro root=/dev/sda2 quiet         initrd/initramfs-2.6.32-131.0.15.el6.x86_64.img  [root@serv01 grub]# reboot     Broadcast message from root@serv01.host.com         (/dev/pts/0)at 0:47 ...     The system is going down for reboot NOW!  [root@serv01 grub]# Connection to192.168.1.11 closed by remote host.  Connection to 192.168.1.11 closed.  #重啟後然後重新串連,成功,OK!  [root@larrywen Desktop]# ssh 192.168.1.11  root@192.168.1.11's password:  Last login: Wed Jul 31 00:43:50 2013 from192.168.1.1  [root@serv01 ~]#   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.