CentOS restore the deleted boot Partition
In CentOS 6, the boot partition is deleted due to carelessness or operation errors,
In this case, can I restore the deleted boot partition?
1. Use the centos6 image to enter the linux rescue mode.
2. Start the sshd service, view the IP address obtained by eth0, and then connect to it using ssh secure shell.
SSHSecureShell3.2.9(Build283)
Copyright(c)2000-2003SSHCommunicationsSecurityCorp-
http:
//www
.
ssh
.com/
ThiscopyofSSHSecureShellisanon-commercialversion.
ThisversiondoesnotincludePKIandPKCS
#11functionality.
[root@localhost~]
# Cd/boot // enter/boot Partition
[root@localhostboot]
# Ls // view the content of the boot Partition
config-2.6.32-71.el6.i686symvers-2.6.32-71.el6.i686.gz
grubSystem.map-2.6.32-71.el6.i686
initramfs-2.6.32-71.el6.i686.imgvmlinuz-2.6.32-71.el6.i686
[root@localhostboot]
# Cd .. // Return to the upper directory
[root@localhost/]
# Rm-rf/boot/* // delete all content in the/boot Partition
[root@localhost/]
# Ls/boot // check/boot partition content is blank
[root@localhost/]
# Mount/dev/sr0/mnt // mount the cdrom device to the/mnt directory
mount
:blockdevice
/dev/sr0
iswrite-protected,mounting
read
-only
[root@localhost/]
#rpm-ivh/mnt/Packages/kernel-2.6.32-71.el6.i686.rpm
--root=/--
Force // install the disc's kernel package
Preparing.。。
###########################################[100%]
1:kernel
###########################################[100%]
[root@localhost/]
# Ls/boot // view/boot partition content
config-2.6.32-71.el6.i686System.map-2.6.32-71.el6.i686
initramfs-2.6.32-71.el6.i686.imgvmlinuz-2.6.32-71.el6.i686
symvers-2.6.32-71.el6.i686.gz
[root@localhost/]
# Mkdir/boot/grub // create a grub directory in the/boot directory
[root@localhost/]
# Touch/boot/grub. conf // create a grub. conf configuration file.
[root@localhost/]
#cp-rf/usr/share/grub/i386-pc/*/boot/grub/
//
Copy all content from/usr/share/grub/i386-pc to/boot/grub.
[root@localhost/]
# Ls/boot // view/boot partition content
config-2.6.32-71.el6.i686symvers-2.6.32-71.el6.i686.gz
grubSystem.map-2.6.32-71.el6.i686
initramfs-2.6.32-71.el6.i686.imgvmlinuz-2.6.32-71.el6.i686
[root@localhost/]
# Ls/boot/grub // view the/boot/grub directory content
e2fs_stage1_5iso9660_stage1_5stage1vstafs_stage1_5
fat_stage1_5jfs_stage1_5stage2xfs_stage1_5
ffs_stage1_5minix_stage1_5stage2_eltorito
grub.confreiserfs_stage1_5ufs2_stage1_5
[root@localhost/]
# Fdisk-l // view partitions
Disk
/dev/sda
:21.5GB,21474836480bytes
255heads,63sectors
/track
,2610cylinders
Units=cylindersof16065*512=8225280bytes
Sectorsize(logical
/physical
):512bytes/512bytes
I
/O
size(minimum
/optimal
):512bytes/512bytes
Diskidentifier:0x000b1db4
DeviceBootStartEndBlocksIdSystem
/dev/sda1
*11310240083Linux
//
This is
/boot
Start Partition
Partition1doesnotendoncylinderboundary.
/dev/sda2
13144104857682Linuxswap/Solaris
Partition2doesnotendoncylinderboundary.
/dev/sda3
14426111981952083Linux
//
This is/root Partition
[root@localhost/]
# Mount // view all mount partitions
/dev/sda3
on/
type
ext4(rw)
//
Root Partition
/dev/sda1
on
/boot
type
ext4(rw)
//boot
The partition is sda1.
devptson
/dev/pts
type
devpts(rw)
tmpfson
/dev/shm
type
tmpfs(rw)
procon
/proc
type
proc(rw)
sysfson
/sys
type
sysfs(rw)
/dev/sr0
on
/mnt
type
iso9660(ro)
[root@localhost/]
# Grub // start grub
ProbingdevicestoguessBIOSdrives.Thismaytakealong
time
.
GNUGRUBversion0.97(640Klower/3072Kuppermemory)
[MinimalBASH-likelineeditingissupported.Forthefirstword,TAB
listspossible
command
completions.Anywhere
else
TABliststhe
possible
completionsofadevice
/filename
.]
grub》root(hd0,0)
//
First
find
/grub/stage1
View
/boot
Partition is (hd0, 0)
root(hd0,0)
//
Set
/boot
Partition is
/dev/sda1
Filesystem
type
isext2fs,partition
type
0x83
grub》setup(hd0)
//
Reinstall grub
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)”。。。26sectorsareembedded.
succeeded
Running“
install
/grub/stage1
(hd0)(hd0)1+26p(hd0,0)
/grub/stage2
/grub/grub
.conf”。。。succeeded
Done.
grub》quit
//
Exit
3. Restart reboot to start the system and enter the grub interface for testing.
4. find/grub/stage1 and find the/boot partition (hd0, 0). Specify kernel, initrd, and boot to start the system successfully.
5. After the system is started successfully, enter the system to re-write the/boot/grub. conf file.
6. [root @ localhost/] # vi/boot/grub. conf configuration file is as follows:
Finally, enter the content of the grub. conf file.
Default = 0 // The default menu is the first
Timeout = 6 // The wait time is 6 seconds.
Title mylinux // boot title: mylinux
Root (hd0, 0) // The partition where boot is located is/dev/sda1
Kernel/vmlinuz-2.6.32-71.el6.i686 ro root =/dev/sda3 rhgb quiet // the location of the kernel mounted in read-only mode/dev/sda3 root partition rhgb quiet for quiet mode does not display kernel information.
Initrd/initramfs-2.6.32-71.el6.i686.img // load the initrd image.
7. Go to linux rescue and create a grub.
8. The final startup interface is as follows:
The above describes how to restore the deleted boot partition in CentOS 6. The steps are long. If you are in trouble, you can reinstall the system and restore the boot partition.