LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to install GRUB from "linux rescue" mode? (https://www.linuxquestions.org/questions/linux-general-1/how-to-install-grub-from-linux-rescue-mode-561347/)

iguthrie 06-12-2007 10:04 PM

How to install GRUB from "linux rescue" mode?
 
I am running RHEL 4 as a host in VMware 6.0.
I wanted to test recovering the system after the MBR has been erased.

My plan was to erase the MBR by executing:

dd if=/dev/zero of=/dev/hda bs=512 count=1

then boot into rescue mode from the first installation CD and reinstall GRUB by executing:

grub-install /dev/hda

After booting into rescue mode I discovered that "grub-install" was not available. It is not included in the rescue mode environment.

Plan B was to NFS mount the RPM that contains grub-install and install it. However this failed because the rpm command requires several other programs/commands which are not included in rescue mode.

My questions are:

1) How do I reinstall GRUB on the MBR from the rescue mode?
2) Is GRUB the only program in the MBR? That is, did the dd command erase anything else other than GRUB?

Thanks in advance.

Ian

slimm609 06-12-2007 10:22 PM

you have to ensure that the root partition is mounted and if not mount it to somewhere then chroot to that drive and try your command again.

syg00 06-12-2007 10:49 PM

Quote:

Originally Posted by iguthrie
2) Is GRUB the only program in the MBR? That is, did the dd command erase anything else other than GRUB?

Nope.
You wiped out the partition table as well.

Can't comment on the rescue mode, never used it.
If you can get to a directory containing grub you can re-install - even from something like Knoppix.

slimm609 06-12-2007 11:12 PM

also run fdisk -l /dev/(drive here)

iguthrie 06-13-2007 12:51 AM

After executing the dd command (in this example on the drive containing the /boot and / file systems), the partition table is indeed erased. I say this because on booting from the CD into rescue mode I get the message "You don't have any Linux partitions". Also, fdisk -l /dev/hda produces the message "Disk /dev/hda doesn't contain a valid partition" table.

This means I am unable to mount the root file system because with out a partition table for the drive there can be no file systems on that drive. Correct?

In this scenario, once the partition table on the drive containing /boot and / has been erased, doesn't this mean the system can only be restored by reinstalling the OS?
Even if the partition table is rebuilt with fdisk, all data is still lost. Correct?

Ian

Junior Hacker 06-13-2007 01:40 AM

From a live CD like Knoppix, you can use testdisk to restore the partition table, just type testdisk in a terminal, then you can restore grub, try saikee's advice on restoring grub:
http://www.linuxquestions.org/questi...d.php?t=551370

iguthrie 06-13-2007 09:38 AM

I should mention that I am doing this as practice for my RHCE exam. I won't have access to any tools except those on the RHEL installation CDs.
Given this, is there a way to recover the system after the MBR and partition table have been erased from the drive where / and /boot reside?

Ian

slimm609 06-13-2007 01:21 PM

there is a way to fix grub without other tools but not the partition table. They don't delete the partition table on the RHCE test.

How long have you been using linux and also how long have you been using RHEL 5?

Junior Hacker 06-13-2007 04:43 PM

Quote:

Originally Posted by iguthrie
Given this, is there a way to recover the system after the MBR and partition table have been erased from the drive where / and /boot reside?

Ian

I just installed Fedora 7 the other day, as soon as I configured it the way I wanted it and applied all available updates, I made a compressed image of the / partition, I don't have a separate /boot partition (you can choose to not make one with RHEL also).
Because all my Linux systems reside on the same size partitions, I did not make note of the size because it's easy for me to remember, but I do make note of where my shared swap partition is located. I store the OS images on a shared NTFS data partition on the same drive and have everything including the images from that data partition backed up on an external USB drive.
Sooooooo!
If for any reason my drive fails and I have to transfer everything to another drive, I just plug in another drive, create the proper size partitions, make sure swap is in the same spot as the first drive and restore the images and I'm back up and running in as little as 1.5 hours. If I had a separate /boot partition and had an image of it also, that also would not be a problem, and because of the way my boot manager works, none of them have to be in the same spot as the original drive except for swap, I can even have multiple bootable copies of the same image all over the drive. The new drive can be of a different size, model, make. This is all made possible with my boot manager called "bootitng", I have seven operating systems at present.
To answer your question quoted above, "YES", with some pre-planning and backup strategies.

saikee 06-13-2007 06:13 PM

There is no need to run dd command to risk erasing the partition table.

In rescue mode of a Red Hat distro you boot to the installation CD Linux and is given the root console by default.

To install Grub in the MBR any time and as often as you want the commands are
Code:

grub
root (hd0,0)
setup (hd0)

The above assumes you /boot partition, which has /grub directory inside, is the 1st partition of the 1st disk known to Grub as (hd0,0). The "setup" command installs Grub in the whole of the 1st boot disk (hd0) and that is the MBR.

iguthrie 06-14-2007 06:45 AM

I have been using RHEL4 for about 4 months but I have several years experience with Unix in general.

OK...I got it...I know how to fix grub now. Thanks all for your timely and thoughtful responses. It's greatly appreciated!

Ian


All times are GMT -5. The time now is 06:16 PM.