How to restore the boot partition deleted by CentOS 6

  
                

In the CentOS 6 system, the boot partition is deleted due to carelessness or operational errors. Is it possible to recover the deleted boot partition in this case? In fact, it is ok, let's take a look at it with Xiaobian.

1. First use the centos6 image to enter the linux rescue mode.

2. Start sshd service, see the ip address eth0 acquired, and then connect with ssh secure shell.

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 //Enter /boot partition

[root@localhost boot]# ls //View the contents of the boot partition

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 . . //Return to the upper directory

[root@localhost /]# rm -rf /boot/*//delete all contents of the /boot partition

[root@localhost /]# ls /boot//View the contents of the /boot partition is empty

[root@localhost /]# mount /dev/sr0 /mnt//Mount the cdrom device to the /mnt directory

mount: block device /Dev/sr0 is write-protected, mounted read-only

[root@localhost /]# rpm -ivh /mnt/Packages/kernel-2.6.32-71.el6.i686.rpm --root= /--force //Install the kernel package for the CD

Preparing. . ###############################################################################

1:kernel ####################################################################### 100%]

[root@localhost /]# ls /boot //View the contents of the /boot partition

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//Create a new grub directory in the /boot directory

[root@localhost /]# touch /boot/Grub/grub.conf//Create a new grub.conf configuration file

[root@localhost /]# cp -rf /usr/share/grub/i386-pc/* /boot/grub///put Copy all the contents of /usr/share/grub/i386-pc to /boot/grub.

[root@localhost /]# ls /boot//View the contents of the /boot partition

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///View the contents of the /boot/grub directory

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 //View partitions

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//This is the /boot boot partition

Partition 1 does not end on Cylinder boundary.

/dev/sda2 13 144 1048576 82 Linux swap /Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3 144 2611 19819520 83 Linux //This is /root partition

[root@localhost /]# mount//View all mounted partitions

/dev/sda3 on /type ext4 (rw)//root partition

/dev/sda1 on /boot type ext4 (rw)//boot partition is 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//start 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< Br>

completions of a device/filename.]

grub》 root (hd0,0) //first find /grub/stage1 view /boot partition is (hd0,0)

root (hd0,0)//Set the /boot partition to /dev/sda1

Filesystem type is ext2fs, partition type 0x83

grub" setup (hd0)//Reinstall grub< Br>

setup (hd0)

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.

probably

Running “install /grub/stage1 (hd0) (hd0)1+26 p (hd0,0)/grub/stage2 /grub/grub. Conf”. . . Successfuled

Done.

grub quit//Exit
Previous12Next Total 2 Pages

Copyright © Windows knowledge All Rights Reserved