OMG OMG OMG… I have lost my grub!1!1…

Hi folks…

I have heard this sort of whining on many occasions… The most often cases of grub borkage that I have heard about are “I had a problem with Windows and I had to reinstall it and I can only boot to Windows now and not to my PCLinuxOS…”. Second one is “I have installed a second distro on my HDD and it comes with Grub 2 and now it shows both OSes as choice but it only boots to one…”.

Today I will try to show You how to fix the first case.

1. Boot to PCLinuxOS LiveCD.
2. Check what partitions are listed on Your HDD

A) Open terminal
B) Type in su
C) Type in root’s password: root
D) Type in fdisk -l (fdisk space dash lowercase L)

The output will look somewhat like this:

[root@icsserver andrzejl]# fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x24502450

Device Boot Start End Blocks Id System
/dev/sda1 * 63 97691264 48845601 7 HPFS/NTFS
/dev/sda2 52420095 312576704 130078305 5 Extended
/dev/sda5 63 52420094 26210016 83 Linux
/dev/sda6 52420158 56613059 2096451 82 Linux swap / Solaris
/dev/sda7 56613123 77577884 10482381 83 Linux

This tells us that the HDD is a 160 GB one. And that it has Windows (red one) and Linux (green and blue) partitions on it. Partition sda1 is NTFS formatted. Partitions sda5 and sda7 are formatted with some Linux file system (ext4 more then likely) and sda5 is formatted as swap. If it only shows Windows partitions – I am afraid I have bad news… If it shows both Windows and Linux partitions – You’re good to go.

Now we need to install the Grub in the MBR (Master Boot Record).

In the same terminal type in:

A) grub and press ENTER
B) This will open (after a while) the grub command line editor with a prompt:

GNU GRUB version 0.97 (640K lower / 3072K 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. ]


C) Now type in find /boot/grub/menu.lst and press ENTER

D) This will return some value (different for everyone) in my case:

grub> find /boot/grub/menu.lst

This means that the menu.lst file is located on the first (hd0) hard drive and on the partition number 1 (grub sees the partitions in a “weird” way – always -1 so if it shows 0 – it means first partition). So hd0 – disk 1, 0 – partition 1. Now this also tells us one more thing hd0,0 is (more then likely) our / (root) partition.

Soooo knowing all this You need to type in two commands (modified to reflect the output of the find command):

root (hd0,0)

grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83

setup (hd0)

grub> setup (hd0)
Checking if “/boot/grub/stage1” exists… yes
Checking if “/boot/grub/stage2” exists… yes
Checking if “/boot/grub/e2fs_stage1_5” exists… yes
Running “embed /boot/grub/e2fs_stage1_5 (hd0)”… 17 sectors are embedded.
Running “install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst”… succeeded

and then type in quit to go back to normal terminal prompt.

That’s it – You have just reinstalled Your grub. Now type in reboot press ENTER and keep Your fingers and toes crossed :).

Hope this helps.




"Never meet Your heroes. Most of the time you'll only end up disappointed." White Polak Male Husband Employee Hetero Carnivorous Fugly Geek @$$hole with ADD Catholic “Some men just want to watch the world burn.”

Comments are closed.