LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-12-2007, 10:04 PM   #1
iguthrie
LQ Newbie
 
Registered: Sep 2006
Posts: 10

Rep: Reputation: 0
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
 
Old 06-12-2007, 10:22 PM   #2
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 428

Rep: Reputation: 65
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.
 
Old 06-12-2007, 10:49 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,287

Rep: Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030Reputation: 1030
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.
 
Old 06-12-2007, 11:12 PM   #4
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 428

Rep: Reputation: 65
also run fdisk -l /dev/(drive here)
 
Old 06-13-2007, 12:51 AM   #5
iguthrie
LQ Newbie
 
Registered: Sep 2006
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 06-13-2007, 01:40 AM   #6
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 59
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
 
Old 06-13-2007, 09:38 AM   #7
iguthrie
LQ Newbie
 
Registered: Sep 2006
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 06-13-2007, 01:21 PM   #8
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 428

Rep: Reputation: 65
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?

Last edited by slimm609; 06-13-2007 at 01:22 PM.
 
Old 06-13-2007, 04:43 PM   #9
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 59
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.
 
Old 06-13-2007, 06:13 PM   #10
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
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.
 
Old 06-14-2007, 06:45 AM   #11
iguthrie
LQ Newbie
 
Registered: Sep 2006
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is "sticky bit mode" , "SUID" , "SGID" augustus123 Linux - General 10 08-03-2012 04:40 AM
dual OS install windows XPx64 linux RH4 on two RAID 1 arrays - "Grub read error" sdlinwwin Linux - Software 1 03-27-2007 01:28 PM
uninstall boot loader "Lilo" install "Grub" sethis Linux - Newbie 6 11-30-2006 09:32 AM
how to install grub using fc 4 installation cd .the cd has rescue mode amolgupta Linux - Software 2 03-15-2006 02:14 AM
Hard disk now displaying "not a valid block device" when booting in rescue mode alphasure Linux - Hardware 4 06-05-2003 07:49 AM


All times are GMT -5. The time now is 11:57 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration