CentOS restore the deleted boot Partition

Source: Internet
Author: User
Tags ssh secure shell

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/sr0iswrite-protected,mountingread-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/Osize(minimum/optimal):512bytes/512bytes  Diskidentifier:0x000b1db4  DeviceBootStartEndBlocksIdSystem  /dev/sda1*11310240083Linux//This is/bootStart Partition  Partition1doesnotendoncylinderboundary.  /dev/sda213144104857682Linuxswap/Solaris

  

Partition2doesnotendoncylinderboundary.  /dev/sda314426111981952083Linux//This is/root Partition  [root@localhost/]# Mount // view all mount partitions  /dev/sda3on/typeext4(rw)//Root Partition  /dev/sda1on/boottypeext4(rw)//bootThe partition is sda1.  devptson/dev/ptstypedevpts(rw)  tmpfson/dev/shmtypetmpfs(rw)  procon/proctypeproc(rw)  sysfson/systypesysfs(rw)  /dev/sr0on/mnttypeiso9660(ro)  [root@localhost/]# Grub // start grub  ProbingdevicestoguessBIOSdrives.Thismaytakealongtime.  GNUGRUBversion0.97(640Klower/3072Kuppermemory)  [MinimalBASH-likelineeditingissupported.Forthefirstword,TAB  listspossiblecommandcompletions.AnywhereelseTABliststhepossible  completionsofadevice/filename.]  grub》root(hd0,0)//Firstfind/grub/stage1View/bootPartition is (hd0, 0)  root(hd0,0)//Set/bootPartition is/dev/sda1  Filesystemtypeisext2fs,partitiontype0x83  grub》setup(hd0)//Reinstall grub  setup(hd0)

 

 Checkingif/boot/grub/stage1”exists.。。no  Checkingif/grub/stage1”exists.。。yes  Checkingif/grub/stage2”exists.。。yes  Checkingif/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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.