Sign in with
Sign up | Sign in
Your question

Recovering Grub Boot Loader

Last response: in Linux/Free BSD
Share
January 6, 2007 2:38:49 PM

Hi ,

I just Instaled Windows XP and the Grub Boot loader is corrupted :(  .

I have Installed FC5 and the partitions are

/Boot, Swap, /, /Home .

so now how can I install Grub Boot loader with the Rescue CD?

seeking suggestions

Thanks
January 7, 2007 12:29:38 PM

Well if you will play with the evil Bill... :wink:

You could do a lot worse than have a look at this Linux Questions thread talking about the same problem..

www.linuxquestions.org

And just to be on the safe side... Here is an article on getting XP back onto your list of bootable OS after restoring GRUB.

www.linuxquestions.org

Please post back and let us know how you get on.. Hope this gets you back up and running.
January 13, 2007 3:30:55 AM

It's not that bad when you realize what's happened, and as such it's pretty easy to fix.

What happened:

To understand what happened here, it helps to understand how grub works.

At the very beginning of the harddisk, there's code to boot an OS (a boot loader). It must reside inside of a small area of the disk (<512 bytes total), which was fine in the early days of less-sophisticated OS's like DOS, but to support booting multiple different OS's and graphics and network booting and more, well you can see that trying to fit all this into the small start of disk (called the Master Boot Record, or MBR) becomes impossible.

So, the idea of a multi-staged bootloader came about. The code that exists in the MBR is enough to get the system going (this is "Stage 1" in GRUB parlance) and load up more code that exists outside of the MBR (it actually resides right after the MBR as this space is left unused for DOS compatibility and legacy purposes). This code (called "Stage 1.5") is capable of reading normal filesystems and can thus read the contents of your /boot directory and thus can pass off the rest of the booting responsibilities to code that resides here ("Stage 2").

Now, how Windows boots

The Windows bootloader also starts at the MBR, which then reads the first sector (a section of a hard disk, the smallest singularly accessible part of a hard disk, usually 512 bytes) of the first bootable partition it sees which, after a Windows install is C[\i],which contains ntldr, the second stage that preps the system for boot and reads various boot-time config files (like boot.ini, etc.)

How to fix it

With that quick and dirty overview, what happened is that Windows overwrote what GRUB had put in the MBR during the install. All of the still-correct setup data still resides in /boot, you just need to reinstall GRUB into the MBR and let it resume it's superior job of starting the computer.

Use a Linux LiveCD of your choice or any boot recovery disks you may have, boot into Linux, start a terminal. Generally LiveCD's will either make you the root user or give you unprotected access to the sudo command, if the latter is the case, simply append sudo to the commands (except when you are in the grub shell, as you'll be "root-ified" inside)
[code:1:cc352fe236]//First and foremost, this is assuming a standard Fedora install and
//I make assumptions on harddrive layout, adjust as needed.
//ASSUMED LAYOUT: one hard disk, 3 partitions:
//1st is NTFS with Windows installed
//2nd is probably EXT2 or EXT3 and is your /boot parition
//3rd is a Linux Logical Volume Manager partition, Fedora loves to use this.
//An LVM parition can contain multiple other "partitions" (volumes), so
//your root (/) and swap probably reside here
//To verify the physical layout of the disk, use the following

/sbin/fdisk -l

//Look for the listing that matches the size of your hard disk and check
//the layout, adjust as needed. Output of above command for the proposed
//layout would be something like

Device Boot Start End Blocks Id System
/dev/sda1 * 1 7649 61440561 7 HPFS/NTFS
/dev/sda2 7650 7658 72292+ 83 Linux
/dev/sda3 7659 16413 70324537+ 8e Linux LVM

//Again, adjust as needed. This also assumes either SATA or SCSI drives,
//with IDE the listings would be for /dev/hdX, X being a,b,c,...
//Now that we see what looks to be your /boot partition (the Linux one
//that's not an LVM), check to make sure that the contents of that
//partition are infact the boot files.

cd /root // get you back to a known location
mkdir temp //make a temporary mountpoint (where you attach a physical
//filesystem to the overall filesystem currently setup)
mount /dev/sda2 temp //this makes the "attachment"
ls temp

//Output should look something like this
config-some-version-of-linux lost+found
grub System.map-some-version-of-linux
initrd-some-version-of-linux.img vmlinuz-some-version-of-linux

//Don't worry if it doesn't match exactly, just that it kinda "feels" like that.

umount temp
rmdir temp

//Now that we've verified that that's the partition we want, we have to
//go about letting grub know about it and re-install itself in the MBR

grub //After this command, you will be in the grub shell. If you have been
//using "sudo", you no longer have to/should

// A word about GRUB's hard disk numbering: It's not that bad, just
// convert from a->0, b->1, c->2.... and 1->0, 2->1, ....
// so /dev/sda4 would be (hd0,3) and /dev/sdb2 would be (hd1,1)
//Our example, /dev/sda2 is (hd0,1)

root (hd0,1) //Confusing terminology here: they actually mean
//"where is /boot located", should be called "boot" instead
//Output should confirm what we know

Filesystem type is ext2fs, partition type 0x83

//If it says something about Unknown filesystem or partition type other
//than 0x83, stop and review the steps. Come back to the forums if needed
//Otherwise, tell grub to install itself onto the MBR

setup (hd0)

//It will give you some diagnostic output here, just make sure there are
//no serious errors. If all is good, go ahead and exit the GRUB shell

quit
[/code:1:cc352fe236]

If you made it through that marathon description (sorry, but I like to know what I'm doing before just blindly following directions and assume others do too :)  ), congrats, you should be back in business. If not or something else goes arwy, come back and we'll do our best to help you through.
Related resources
January 16, 2007 7:04:46 PM

Excellent explanation :-D :trophy: :trophy:


Another way to do this is to mount your partitions, chroot to your root partition edit /etc/grub.conf if necessary and run /sbin/grub-install $options /dev/sd?

Where $options = --recheck

sometimes you have to specify

--grub-shell=/path/to/grub

normally

--grub-shell=/sbin/grub

and

--root-directory=/mnt/.........

normally

--root-directory=/

of course /dev/sd? is your HDD usually /dev/sda, /dev/sdb etc

man grub-install for more info

GL :-D
January 23, 2007 12:14:39 PM

well Thanks for those Valuable information. I understood the stuffs clearly.

but sorry for the delayed response.

let me clarify my partitions first.(I have given LInux parttions here).
=========start==========end==========blocks======i d=====system

/dev/hda3 -- 16710 ---------19457 --------- 22073310(/)--- 83----- Linux
/dev/hda8---15666----------15729----------514048(/boot)--83------Linux
/dev/hda9---15730----------16048---------2562336(swap)--82---Linx Swap
/dev/hda10--16049----------16709----------5309451(/home)--83---Linux

but when I say "grub-install /dev/hda" it says /dev/hda:Not found or not a block!!.
above all

after "Linux rescue" it attepmts to recover the Installed Linux but it says "
it says an error occured trying to mount some or all of your system.some of it may be mounted under .mnt/sysimage.

press enter to get a shell.system reboots once you exit from the shell.
.


by the way when I say fdisk -l at the Boot prompt it says Could not find the Kernel Image..
but works fine on SHELL prompt.


I attepmted on Shell prompt but the problem persists still.





[/b]
January 23, 2007 8:50:27 PM

Those are some whacky partition numbers, what else have you installed on this machine?
January 24, 2007 12:51:28 PM

Man I have installed windows XP as well.

fdisk -l displays all the devices starting from

/dev/hda1 to /dev/hda10. but here I have given the Linux partitions only.

and my /, /boot, swap and /home partitions are indicated as well.

did you find anything messed up here?

by the fdisk -l doesnot work on Boot prompt for me

it says "Kernel Image not found".
I executed fdisk -l on Shell prompt.

if you need clear fdisk -l output with all partitions I post for sure .

Thanks
January 24, 2007 6:45:05 PM

Yes, please post the entire output of fdisk -l
January 25, 2007 12:37:52 PM

Disk:/dev/hda:160.0GB

Device===boot ===start===end===blocks=======ID===System

/dev/hda1 * ===1===1305===10482381======C===W95 Fat32(LBA)
/hda2=======1306==16709==123732630======F===W95 Ext(LBA)
/hda3=====16710==19457==22073310=======83===Linux
/hda5====1306====5874==36700461========B===W95 Fat32
/hda6====5875===10443==36700461========B===W95 Fat32
/hda7===10444===15665==41945683+===B===W95 Fat32
/hda8===15666===15729==514048+====83===LInux
/hda9===15730===16048==2562336=========82=Linx Swap/Solaris
/hda10==16049===16709==5309451========83===Linux

yeah Man. this is the output of fdisk -l executed on Shell Prompt.

No of Blocks in /hda7 and /hda8 is suffixed by +. why is it so?

I dont have /hda4

Thanks
January 26, 2007 2:53:18 AM

anything fishy in fdisk -l output?

am I still able to install Grub on it?
January 27, 2007 4:32:18 PM

Do you know what exists on each of those partitions? It seems very unusual to have 4 FAT32 partitions on a single drive.

Not having hda4 is OK, as any of the partitions above hda4 are actually logical partitions encapsulated in the hda2 extended partition (a work-around to a legacy limitation on number of partitions based on the MBR's partition table).

In light of the layout of your disk, you should be able to run my instruction with the modification that you told the installer not to use LVM and as such, you need to figure out which partition (type 0x83, Linux) contains your /boot partition (likely hda8)

I would most certainly figure out a cleaner scheme for you disk layout, then again that is my personal preference.
January 28, 2007 2:00:05 AM

yeah Man

/hda1 is my C drive,

I guess /hda2 is the total of /hda5,/hda6./hda7 which is my D,E,and F drives respectively. which are 35, 35, and 40GB respectively.

and /hda8 is my /boot partition
/hda10 is my /Home partition.

anysuggestion for tye disk layout are most welcome Man.

so how can I approach to install the Grub boot loader.
January 30, 2007 3:19:43 AM

Get a so-called grub boot disk/CD to get you to a grub prompt. Once there, since you know the layout of the disk, follow my first post's instructions from the part after the "grub" command, being mindful of the change from hda2 to hda8 and (hd0,1) to (hd0,7).

You can get a grub iso from here or simply use a livecd such as the standard ubuntu install disk.
February 1, 2007 1:40:14 PM

yeah Man!

it worked!!!!!!!!!!!! :D 

Thanks a Lot Man!! Thanks to the Forum as well!!!


but one problem persists eversince I installed FC5. once I getinto Graphics screen after some time System get Stuck. the only way to work around this is to restart the System. why it happens so? :( 

Man are you a Linux Developer?

Thanks for your timely Help again!! :) 
February 3, 2007 12:54:24 AM

Quote:
but one problem persists eversince I installed FC5. once I getinto Graphics screen after some time System get Stuck. the only way to work around this is to restart the System. why it happens so?


Can you clarify here a little? Are you saying that, after having used the system for a while it will freeze or that, after using the system and logging out (going back to the login screen) it will freeze, or something else? It sounds like an X driver issue nonetheless (or possibly something worse, hardware instability 8O ), but a little more info may help narrow down the problem.

Quote:
Man are you a Linux Developer?

I am in the sense that I use Linux as my dev system but the only patch I've ever submitted for the kernel was rejected (someone did a better job of patching the problem than I).
February 3, 2007 8:44:36 AM

Development does not just equal coding in my book, you have to look at the whole software life cycle. As a developer you are well aware that most of the cost in software is in the maintenance and support stage.

A kernel patch or module does carry bragging rights and membership of a fairly small club but its not the only side of Linux development. Developing user knowledge and awareness, testing new releases ahead of less experienced users. It is all part of the process.

I'd say you are an active developer :wink:
February 3, 2007 8:55:48 AM

well I dont think it is due to Hardware Instability. as I had Red Had Linux 9.0 with 2.4 Kernel Version.everything was alright with that.I did not have any sort of problems.

what happens after working for some time on XWindow the Linux system come sto halt.it hangs in other words.

but everything goes fine with Text terminals.

what could be the reason?

I have Krypton Motherboard with Nvidia Chipset. with AMD Athlon 64 Bit Processor.
February 3, 2007 11:09:10 AM

nVidia chipsets are usually very good :-D

What kind of VGA card do you have? Onboard nVidia? AGP? PCI-E? PCI?

Please post the full output of lspci for us.

Also when X freezes can you hit ALT + CTRL + BACKSPACE ( not delete ) to kill X and respawn the X server?

Have you checked /var/log/* for any relevant log entries?


GL :-D


Quote:
well I dont think it is due to Hardware Instability. as I had Red Had Linux 9.0 with 2.4 Kernel Version.everything was alright with that.I did not have any sort of problems.

what happens after working for some time on XWindow the Linux system come sto halt.it hangs in other words.

but everything goes fine with Text terminals.

what could be the reason?

I have Krypton Motherboard with Nvidia Chipset. with AMD Athlon 64 Bit Processor.
February 3, 2007 1:22:41 PM

yeah Man I have onboard VGA.
yeah I cant even Kill the Xserver when the system freezes.

anyway I am gonna Install FC6 soon :D 
if the Problem persists then as well we shall discuss more on it! :) 

as Red hat 9.0 was well on my Motherboard I dont think hardware instability comes into picture.

well let us see what happens with FC6!!! :lol: 

I always upgrade my Linux!


Thanks Man
February 4, 2007 8:38:40 PM

Make sure you install the updates!

Normally, if you have a very fast internet connection you run:

[code:1:0e40a78614]
yum update
[/code:1:0e40a78614]

There may be several Gigs of updates if you install everything so you may have to find a local mirror.

GL :-D
!