设为首页 收藏本站
查看: 511|回复: 0

[经验分享] CentOS 6系统中/boot恢复被删除的/boot分区 简单介绍

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-6-9 08:16:02 | 显示全部楼层 |阅读模式
在CentOS 6系统中,因为不小心或操作失误导致boot分区被删除,

遇到这种情况是否能够恢复被删除的boot分区呢?

  1.首先利用centos6镜像进入linux rescue救援模式。

2015042317121672.jpg

  2.启动sshd服务,查看eth0获取的ip地址,然后用ssh secure shell 连接。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
SSH Secure Shell 3.2.9 (Build 283)
  Copyright (c) 2000-2003 SSH Communications Security Corp -
http://www.ssh.com/
  This copy of SSH Secure Shell is a non-commercial version.
  This version does not include PKI and PKCS #11 functionality.
  [root@localhost ~]# cd /boot //进入/boot分区
  [root@localhost boot]# ls //查看boot分区的内容
  config-2.6.32-71.el6.i686 symvers-2.6.32-71.el6.i686.gz
  grub System.map-2.6.32-71.el6.i686
  initramfs-2.6.32-71.el6.i686.img vmlinuz-2.6.32-71.el6.i686
  [root@localhost boot]# cd 。。//返回上层目录
  [root@localhost /]# rm -rf /boot/*//删除/boot分区所有内容
  [root@localhost /]# ls /boot//查看/boot分区内容为空
  [root@localhost /]# mount /dev/sr0 /mnt//挂载cdrom设备到/mnt目录下
  mount: block device /dev/sr0 is write-protected, mounting read-only
  [root@localhost /]# rpm -ivh /mnt/Packages/kernel-2.6.32-71.el6.i686.rpm
--root=/ --



force //安装光盘的kernel软件包


1
2
3
4
5
6
7
8
9
10
 Preparing.。。 ########################################### [100%]
  1:kernel ########################################### [100%]
  [root@localhost /]# ls /boot //查看/boot分区内容
  config-2.6.32-71.el6.i686 System.map-2.6.32-71.el6.i686
  initramfs-2.6.32-71.el6.i686.img vmlinuz-2.6.32-71.el6.i686
  symvers-2.6.32-71.el6.i686.gz
  [root@localhost /]# mkdir /boot/grub//在/boot目录新建一个grub目录
  [root@localhost /]# touch /boot/grub/grub.conf//新建一个grub.conf配置文件
  [root@localhost /]# cp -rf /usr/share/grub/i386-pc/* /boot/grub/
//



把/usr/share/grub/i386-pc的所有内容拷贝到/boot/grub中。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost /]# ls /boot//查看/boot分区内容
  config-2.6.32-71.el6.i686 symvers-2.6.32-71.el6.i686.gz
  grub System.map-2.6.32-71.el6.i686
  initramfs-2.6.32-71.el6.i686.img vmlinuz-2.6.32-71.el6.i686
  [root@localhost /]# ls /boot/grub/ //查看/boot/grub目录内容
  e2fs_stage1_5 iso9660_stage1_5 stage1 vstafs_stage1_5
  fat_stage1_5 jfs_stage1_5 stage2 xfs_stage1_5
  ffs_stage1_5 minix_stage1_5 stage2_eltorito
  grub.conf reiserfs_stage1_5 ufs2_stage1_5
  [root@localhost /]# fdisk -l //查看分区
  Disk /dev/sda: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0x000b1db4
  Device Boot Start End Blocks Id System
  /dev/sda1 * 1 13 102400 83 Linux//这个为/boot启动分区
  Partition 1 does not end on cylinder boundary.
  /dev/sda2 13 144 1048576 82 Linux swap / Solaris




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Partition 2 does not end on cylinder boundary.
  /dev/sda3 144 2611 19819520 83 Linux //这个为/根分区
  [root@localhost /]# mount//查看所有挂载分区
  /dev/sda3 on / type ext4 (rw)//根分区
  /dev/sda1 on /boot type ext4 (rw)//boot分区为sda1
  devpts on /dev/pts type devpts (rw)
  tmpfs on /dev/shm type tmpfs (rw)
  proc on /proc type proc (rw)
  sysfs on /sys type sysfs (rw)
  /dev/sr0 on /mnt type iso9660 (ro)
  [root@localhost /]# grub//启动grub
  Probing devices to guess BIOS drives. This may take a long time.
  GNU GRUB version 0.97 (640K lower / 3072K upper memory)
  [ Minimal BASH-like line editing is supported. For the first word, TAB
  lists possible command completions. Anywhere else TAB lists the
possible
  completions of a device/filename.]
  grub》 root (hd0,0) //首先find /grub/stage1查看/boot分区为(hd0,0)
  root (hd0,0)//设置/boot分区为/dev/sda1
  Filesystem type is ext2fs, partition type 0x83
  grub》 setup (hd0)//重新安装grub
  setup (hd0)




1
2
3
4
5
6
7
8
9
10
 Checking if “/boot/grub/stage1” exists.。。 no
  Checking if “/grub/stage1” exists.。。 yes
  Checking if “/grub/stage2” exists.。。 yes
  Checking if “/grub/e2fs_stage1_5” exists.。。 yes
  Running “embed /grub/e2fs_stage1_5 (hd0)”。。。 26 sectors are embedded.
  succeeded
  Running “install /grub/stage1 (hd0) (hd0)1+26 p (hd0,0)/grub/stage2
/grub/grub.conf”。。。 succeeded
  Done.
  grub》 quit//退出



  3.重新reboot启动系统进入grub界面测试

2015042317121673.jpg

  4.查找find /grub/stage1然后找到/boot分区为(hd0,0),指定kernel,initrd, boot启动系统成功。

2015042317121674.jpg

  5.系统启动成功,然后进入系统重新写/boot/grub/grub.conf文件。

2015042317121675.jpg

  6.[root@localhost /]# vi /boot/grub/grub.conf配置文件如下:

  最后填写grub.conf文件内容
  default=0 //默认菜单为第一个
  timeout=6//等待时间为6秒
  title mylinux //启动标题为mylinux
  root (hd0,0) //boot所在分区为/dev/sda1
  kernel /vmlinuz-2.6.32-71.el6.i686 ro root=/dev/sda3 rhgb quiet//kernel所在位置以只读模式挂载/dev/sda3根分区rhgb quiet为安静模式不显示内核信息。
  initrd /initramfs-2.6.32-71.el6.i686.img//加载initrd镜像。

  7.最后进入linux rescue重建一个grub

2015042317121676.jpg

  8.最后启动界面如下

2015042317121677.jpg

  上面就是CentOS 6恢复被删除boot分区的方法介绍了,步骤有些长,如果觉得麻烦的话可以重装系统,同样能恢复boot分区。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-75265-1-1.html 上篇帖子: mount 挂接命令及技巧光盘镜像文件、移动硬盘及U盘 简单说明 下篇帖子: Centos6.5 6.6 (均可) 重置密码或强行破解root密码 简单操作
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表