The Linux BOOTF partition is emptied of the recovery steps __linux

Source: Internet
Author: User
Tags gpg ssh secure shell

If the brain residue, the system/boot partition of the contents of all deleted, but do not want to reinstall the system, you can use the Linux rescue mode to restore the boot partition.

The following experimental platform is CentOS 6.2.

Root User Login system, use the rm–rf/boot command to delete/boot, will be mentioned/boot cannot be deleted, but/boot all the data is deleted.

After removing the/boot partition, reboot the system, and certainly not even the grub boot interface, only a "error 5" error black screen.

From the System CD Boot, select "Rescue installed System", that is, rescue mode, enter into the subsequent boot process, select the default option is. Www.it165.net

There is a step-by-step hint "Do you want to start the" network interfaces in this system, choose Yes or no no, this article for the convenience of writing documents, to use SSH connection, so chose Yes, and set the network mode to DHCP.

Finally select shell start Shell to open a shell environment.

At this point the current directory of the system is/mnt/sysimage,

With Ifconfig you can see that the system automatically obtains the IP address, but uses the service sshd Start command is invalid, prompts "unrecognized service",

Use the chroot command to switch the current directory to the root directory.

Then use the service sshd Start command to open SSH service normally.

This allows you to use SSH Secure Shell client to remotely access the system above, primarily to facilitate the copying of commands and results (if all hands are knocked, it will be dead ~)

The operation process is as follows:

[Root@localhost ~]# ls/boot/

(Note: You can see that the boot is an empty directory at this time)

[Root@localhost ~]# ls/mnt/

[Root@localhost ~]# Mount/dev/cdrom/mnt

Mount:block Device/dev/sr0 is write-protected, mounting read-only

(Note: Load CD to/MNT)

[Root@localhost ~]# Ls/mnt

Centos_buildtag Packages rpm-gpg-key-centos-security-6

EULA release-notes-en-us.html rpm-gpg-key-centos-testing-6

The GPL repodata TRANS. TBL

Images rpm-gpg-key-centos-6

Isolinux rpm-gpg-key-centos-debug-6

[Root@localhost ~]# cd/mnt/packages/

(Note: Enter into the packages directory where the packet is stored)

[Root@localhost packages]# RPM-IVH--force kernel-2.6.32-220.el6.i686.rpm

Preparing ... ########################################### [100%]

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

[Root@localhost packages]# ls/boot/

config-2.6.32-220.el6.i686 system.map-2.6.32-220.el6.i686

Initramfs-2.6.32-220.el6.i686.img vmlinuz-2.6.32-220.el6.i686

Symvers-2.6.32-220.el6.i686.gz

(Note: Reinstall the kernel, use the--force option, force the installation, you can see at this time/boot directory with kernel files, etc.)

[Root@localhost packages]# Grub-install--root-directory=//DEV/SDA

[Root@localhost packages]# Ls/boot

config-2.6.32-220.el6.i686 symvers-2.6.32-220.el6.i686.gz

Grub system.map-2.6.32-220.el6.i686

Initramfs-2.6.32-220.el6.i686.img vmlinuz-2.6.32-220.el6.i686

[Root@localhost packages]# ls/boot/grub/

Device.map ffs_stage1_5 minix_stage1_5 stage2 xfs_stage1_5

E2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5

Fat_stage1_5 jfs_stage1_5 stage1 vstafs_stage1_5

(Note: Reload Grub to/boot,

# Grub-install--root-directory=//DEV/SDA

The--root-directory=/in the command refers to the relative path of the/boot, and the--root-directory value can be null, that is,

# Grub-install--root-directory=/DEV/SDA

A grub folder will be generated under/boot and a grub file will be stored inside, and if written as--root-directory=/boot, the system would generate a boot folder under/boot and a grub folder in it. That is, the grub file is stored in the/boot/boot/grub/directory, which is incorrect.

The data in the above/boot/grub/can also be copied directly from/usr/share/grub/i386-redhat/.

In the/boot/grub data listed above, it is found that the key grub.conf file is not. Need to be created manually-this is a test of memory, if each system is backed up by the grub.conf file, it would be fine, of course, it can be copied from other versions of the system, modified to be available-this is manually created one.

[Root@localhost packages]# cd/boot/

[Root@localhost boot]# Touch grub/grub.conf

[Root@localhost boot]# ls

config-2.6.32-220.el6.i686 symvers-2.6.32-220.el6.i686.gz

Grub system.map-2.6.32-220.el6.i686

Initramfs-2.6.32-220.el6.i686.img vmlinuz-2.6.32-220.el6.i686

[Root@localhost boot]# echo vmlinuz-2.6.32-220.el6.i686 >> grub/grub.conf

[Root@localhost boot]# echo initramfs-2.6.32-220.el6.i686.img >> grub/grub.conf

(Note: Create grub.conf files under/boot/grub, write files for Vmlinuz and Initramfs files to grub.conf files)

[Root@localhost boot]# Vim grub/grub.conf

Default=0

timeout=10

Title CentOS 6

Root (hd0,0)

kernel/vmlinuz-2.6.32-220.el6.i686 ro Root=/dev/mapper/vg_itpro-lv_root Quiet

Initrd/initramfs-2.6.32-220.el6.i686.img

(Note: Edit grub.conf content, note that "title CentOS 6" is not "=", and save exit;

Recommended to use VIM instead of VI, because VIM coloring, it is easy to know if your input error, of course, SSH remote can not see the coloring;

If you forget root=/dev/mapper/vg_itpro-lv_root, you can view it through the Df–h command, as shown in Figure P-03

When the above settings are complete, uninstall the disc and reboot the system.

[Root@localhost boot]# Umount/dev/cdrom/mnt

Umount:/mnt:not Mounted

[Root@localhost boot]# Eject

[Root@localhost boot]# Init 6

init:failed to connect to Socket/com/ubuntu/upstart:connection refused

[Root@localhost boot]# reboot

Shutdown:unable to shutdown system

[Root@localhost boot]#

Broadcast Message from Root@localhost.localdomain

(/dev/pts/0) at 15:31 ...

The system is going down for reboot now!

The above init 6 is invalid and reboot is invalid, which means that both commands are not available in rescue mode.

You need to go to the local system and exit the shell with the Exit command.

Then select the "Reboot reboot" option to reboot the system (as shown in Figure P-01).

The first reboot, slow speed, there is a longer period of repair process, as shown in Figure P-03;

After the repair, the system will automatically restart again, normal access to the login interface.

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.