CentOS Grub, BASH fault, solution, centosbash

Source: Internet
Author: User

CentOS Grub, BASH fault, solution, centosbash


Introduction:

Two common faults of Grub: Grub. conf file loss and MBR damage (no matter what the recovery is, back up the file first)

1. Grub. conf file loss

Shell> rm-rf/boot/grub. conf # delete files, simulate faults, shell> reboot

# Faults:

GNU GRUB verstion 0.97 (634k lower / 1046400k 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>

# In this way, you cannot log on to the system. The solution is as follows:

Grub> root (hd0,) # Enter root (hd0,). Then press the TAB key to print all the partitions in the system (note that TAB is not supported in emergency mode, which is very harmful ~ ) Possible partitions are: Partition num: 0, Filesystem type is ext2fs, partition type 0x83Partition num: 1, Filesystem type unknown, partition type 0x82Partition num: 2, Filesystem type is ext2fs, partition type 0x83

#0, 1, 2 indicates the partition number. The above shows the file system and partition type. For example, 83 is a common Linux partition, and 82 is a virtual partition SWAP (hard disk partition knowledge)
# Hd0 indicates the first hard disk, hd0 indicates the first partition of the first hard disk, regardless of IDE/SATA, in the system, sda1 is used to represent the first partition of the first hard disk.

Grub> root (hd0, 0)/# Enter root (hd0, 0)/click the TAB key here to search for the kernel not in this partition (boot partition ), if the following information is output (try 83 partitions and 82 is a swap partition, it is unnecessary to try) Possible files are: lost + found grub efi. VMlinuz-2.6.32-504.e16.x86_64.hmac System. map-2.6.32-504.e16.x86_64 config-2.6.32-504.x86_64 symvers-2.6.32-504.x86_64.gz VMlinuz-2.6.32-504.e16.x86_64

# If you can see the vmlinuz-And initramfs-words, this is what we want

Grub> root (hd0, 2)/# The following cannot be found. Take a closer look (it is found that this is the root partition Ah ~~ Hd0 and 2 are root partitions. We use SATA, so the root partition is/dev/sda3 !) Possible files are: lost + found boot dev proc sys var tmp etc root selinux lib64 usr bin home lib media mnt opt sbin srv. autorelabelgrub> root (hd0, 0) # bind the boot partition Filesystem type is ext2fs, partition type 0x83grub> kernel/VMlinuz-2.6.32-504.e16.x86_64 ro root =/dev/sda3 # specify the boot kernel, ro read-only mode, root = specifies the root partition, which must be a pair (it is possible if the boot does not have a separate partition not specified) grub> initrd/initramfs-2.6.32-504.e16.x86_64.img # This is the kernel image (kernel, initrd are found above, enter a little press TAB can complete) grub> boot # Start the system, manually write grub. conf or restore the backup shell> vim/boot/grub. confdefault = 0 # Start which system timeout = 5 # Wait time title CentOS 6.6 # description information kernel/VMlinuz-2.6.32-504.e16.x86_64 ro root =/dev/sda3 # kernel initrd/initramfs-2.6.32-504.e16.x86_64.img # Start Image

# Here is a vim usage. On the host, vim cannot copy the command line content with the mouse. the kernel and initrd are so long and hard to remember.
# Method: Input in last line mode .! Ls/boot/vmlinuz-press TAB to complete the information. Press Enter to put the information in the current file.

shell > reboot

# In this way, the recovery is successful! Remember to back up

# If the kernel does not refer to the root partition, this will happen ~ Restart the system and try again.

dracut Warning: Signal caught!?dracut Warning: Boot has faild. To debug this issue add "rdshell" to the kernel command line.?Kernel panic - not syncing: Attempted to kill init!?Pid: 1, comm: init Not tainted 2.6.32-504.e16.x86_64 #1?Call Trace:[<ffffffff815292bc] ? panic+0xa7/0x16f? [<ffffffff815292bc] ? do_exit+0xa7/0x16f? [<ffffffff815292bc] ? fput+0xa7/0x16f? [<ffffffff815292bc] ? system_call_fastpath+0xa7/0x16f??

Ii. MBR damage

Shell> dd if =/dev/zero of =/dev/sda count = 1 bs = 200 # overwrite MBR, simulate a fault (MBR is the first 512 bytes in/dev/sda) shell> reboot

# Faults:

Operating System not found # basically, the System cannot be found on the local hard disk, obtained from PXE, DHCP xxxxxxxxxxxxx

# Solution: Use emergency recovery

> Insert the system disc and enter the emergency mode (this will be the first aid mode. Choose CentOS directly, RedHat boot: linux rescue)

Shell> grub # Go to grub mode grub> root (hd0, 0) # directly specify the partition where the kernel is located and cannot TAB (you must find a way to find it, for example: first, chroot/mnt/sysimage, and then df-HT can see all the partitions. If sda1 is the start partition, then the corresponding partition is hd0, 0.) grub> setup (hd0) # re-install MBR to the disk, which is actually/dev/sdagrub> quitshell> reboot

# Now you can successfully access the system. The MBR has been repaired.

Additional: BASH fault solution

Shell> rm-rf/bin/bash # Delete bash, simulate fault shell> reboot

# Failure: the system cannot be initialized, And the init command does not exist. In fact, no command can be executed.
# Enter Emergency mode and reinstall bash

Shell> mkdir/media # directly operate on the disc system, because you cannot chroot to/mnt/sysimageshell> mount/dev/sr0/media # mount the disc image, /dev/sr0 indicates the optical drive, if the IDE interface should be/dev/hdcshell> cd/media/Packagesshell> rpm-ivh -- replacepkgs -- root/mnt/sysimage bash-4.1.2-29.e16.x86_64.rpm # Install bash to -- root to specify the root directory -- replacepkgs replaces the original package shell> reboot

# OK, the fault has been fixed!

Related Article

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.