How to recover GRUB Debian Sarge after reinstalling Windows

Posted by serrador on Wed 4 Jan 2006 at 07:36

Tags: ,

Many Debian newbies often have to reinstall Windows on the same machine on where Debian is installed. Usually the Windows installation does not take care of our Debian system booting process, overwriting the master boot record with Windows.

To get back our grub first stage boot, here a procedure you can use.

  • Boot from debian CD choosing linux2.4 kernel (default)
  • Change to console 2 with alt + F2 keystrokes
  • Make a new dir to mount the boot partition, for example /disk
  • mount the root partition on /disk.
  • Do a chroot to the root partition: issuing chroot /disk
  • Run grub command to enter grub shell
  • Type in the root disk for grub, for example root (hd0,1). This is /dev/hda2 on my system
  • Type the following command to install grub on /dev/hda: setup (hd0).
  • Last step, type quit, exit from chroot, unmount all disks and reboot

Some notes:

The boot partition is where you put the boot files, normally newbies use only one partition that is mounted on /. Some advanced users store boot files in a separate partition and mount it under /boot. In that case, is the partition that is mounted under /boot the known-to-grub root partition.

Thats all folks!!

 

 


Posted by rbochan (24.92.xx.xx) on Wed 4 Jan 2006 at 13:53
[ View Weblogs ]
Unfortunately, there's usually no way to recover... at least with OEM machines (which, let's face it, the majority of users in the US have). This is because the machine's owner doesn't actually own a copy of Microsoft Windows XP that they can just reinstall. If they want to just reinstall Microsoft Windows XP, they have to shell out an extra couple of hundred bucks to do so to get an actual install CD. Instead, they normally have, in the cases of HP, Compaq, Dell, and other OEMs, a hidden partition on their hard drive containing a "recovery system".
Using this recovery system reverts the machine back to it's original OEM condition -- including destroying any manual partioning, as well as all data added since the OEM install. When the underlying Linux install has ceased to exist, reinstalling grub is moot.

If my tinfoil hat was on tighter, I'd guess Microsoft thought about all those machines being dual-booted and figured out a way to make that more difficult... not that they're anti-competive or anything ;o)


...Rob
The American Dream isn't an SUV and a house in the suburbs; it's Don't Tread On Me.

[ Parent | Reply to this comment ]

Posted by john_h (194.130.xx.xx) on Wed 11 Jan 2006 at 09:22
My Dell PC came with a Windows OEM installation disk. The main PITA after reinstalling Windows to make room for Linux was having to reinstall all the drivers - especially since I'd lost the drivers disk. Download from Dell, install one driver, reboot, install another driver, reboot, install another, reboot... a mere ten or twelve reboots later, I was done!

If I had my time over again I'd try resizing the Windows partition using qtparted from a live distro, rather than reinstalling Windows - oh, except that won't work with a Dell PC, as you also need to remove the hidden "system recovery" partition that takes up 10% of your HD. grr

As for MS's motivations, though, I think you can take the tinfoil hat off. I'm sure MS couldn't care less about the relatively tiny proportion of computer users who want to set up dual boot systems - and I gather it is possible to configure the Windows bootloader (NTLDR) to boot into Linux anyway, if you feel that way inclined.

So what we're complaining about is a failure of Windows to autodetect Linux partitions during installation. It's not surprising (or particularly sinister) that MS can't be bothered to implement that particular functionality - after all, many Linux distros (though not Debian of course) will detect only themselves and Windows, ignoring any other Linux installations on the same box.

[ Parent | Reply to this comment ]

Posted by Steve (82.41.xx.xx) on Wed 11 Jan 2006 at 10:14
[ View Steve's Scratchpad | View Weblogs ]

There was an interesting blog entry by Raymond Chen a while back on Why does Windows setup lay down a new boot sector?.

Not 100% related since it doesn't talk about detection of other installed operating systems, but topical because one of the big irritations with installing Windows is the fact it will trash any existing loader..

Steve

[ Parent | Reply to this comment ]

Posted by Anonymous (194.44.xx.xx) on Wed 4 Jan 2006 at 14:54
Thank you!

For the Ukrainian-languages beginners: translating into their native language - http://linux.org.ua/cgi-bin/yabb/YaBB.pl?num=1136386185/0#0.

Good luck!

[ Parent | Reply to this comment ]

Posted by Anonymous (201.211.xx.xx) on Wed 4 Jan 2006 at 20:57
An even easier way to do it:
1) boot with the Knoppix of your choice and become root
2) type grub
3) on the grub comand line type:

root (hd0,0)
setup (hd0)
quit

4) reboot

NOTE: Adjust (hd???) to your machine.
NOTE2: the main difference is thata there's no need to mount partitions.

[ Parent | Reply to this comment ]

Posted by Anonymous (80.74.xx.xx) on Mon 9 Jan 2006 at 17:10
any idea how to do this with SATA drives? Knoppix fails to see them so I cannot fix GRUB.
Thanks, Roman

[ Parent | Reply to this comment ]

Posted by Anonymous (69.76.xx.xx) on Wed 4 Jan 2006 at 22:28
Of course there is an even easier solution:

When Windows has fscked up yet again and you have to reinstall:
1) Collect all important documents from "My Documents," "My Pictures," and any other "My" folder you can think of.
2) Install ext2fsd to mount your linux partition and copy all of these files onto it.
3) Reboot into Linux using a bootable CD
4) Using fdisk, delete windos partition
5) Use parted to move and resize the linux partition(s) to use free space (optional)
6) Continue following instructions for installing grub above
7) Celebrate! Don't reboot your computer until next year, let alone reinstall the OS!

[ Parent | Reply to this comment ]

Posted by Anonymous (137.213.xx.xx) on Thu 12 Jan 2006 at 13:40
Why do you need to do all that chroot stuff? When this happened to me, I just booted from a debian cd, and entered 'boot=/dev/hdb1' when the CD prompt appeared and off it went. I then ran through the GRUB stuff once the OS had loaded up..

The real problem for 'newbies' is that they won't necessarily know what /dev/hda1 is, or even if that is the correct partition!

[ Parent | Reply to this comment ]

Posted by Anonymous (212.235.xx.xx) on Sun 22 Jan 2006 at 20:12
You are not right. It sometimes doesn't work. I had the same problem not long ago.
And if you accidentialy forget or don't know on which partition your debian is (a common problem with newbies) it comes handy.

A good tip, for those who didn't already knew it.

Regarding the debian Boot CD, i think it should be noted that you have to pass instalation procedure to the point where he want's to partition your hard drive, and THEN press Shift+F2 to switch to the other console, otherwise you can't mount the disk.

[ Parent | Reply to this comment ]

Posted by jmrSudbury (66.186.xx.xx) on Fri 3 Feb 2006 at 21:59
I think it is Alt+F2 not Shift+F2

Yesterday, I patched my debian 3.1 system which included a kernel update. That warned me that it changed my modules. After that, it would not reboot. Grub came up, but it only had Linux entries and they could not find the drive. I could not figure it out then, so after several attempts at restalling today, I finally figured it out. The first reinstall attempt, I could not remember where grub was to be installed (it should be /dev/sda for my system). I have a scsi drive for windows and an ide for debian and data. The primary boot device is the scsi, but debian defaulted to the ide. After several fixmbr (and a fixboot when only GRUB would show up on boot after erroneously installing grub to /dev/sda1) using my windows xp pro cd, I finally got it installed and booting by manually changing the grub drive to hd0 from hd1 (to boot windows) or to hd1 to hd0 to boot linux. Once it booted, I changed my menu.lst then found out that I could have just changed my device.map file. Oh well. As long as it works.

I tried the chroot idea in the original post, but the command was not available. Nor could I figure out how to mount hd0 in an Alt+F2 console when booted to the Debian install CD. As well, I don't know how to make the drive editable when using Knoppix, so I just went with the easy, though time consuming, reinstall method. Sure I lost all my linux data, but it probably had to be cleaned up anyway. It was a bit easier to fix a similar kernel update overwritting important files problem in SUSE 9.2 using their install disk. The Debian installer would not allow me to reinstall grub without wiping out the drive. I tried several times. Next time I could probably try new ideas like figuring out how to mount the hda1 drive, but that is assuming I remember, understand my notes, or can find a good resource online.

I hope my experience helps someone.

John M Reynolds

[ Parent | Reply to this comment ]

Posted by Anonymous (68.123.xx.xx) on Mon 6 Feb 2006 at 00:06
After installing Windows XP on my Dual-boot laptop, I could not boot into my Debian anymore. I found the methods posted here and solved my problem quite easily. Thanks Guys.

Here is what I did:

Boot with Knoppix LiveCD
Become root by typing "su"
Type "grub"
Type "root (hd0,1)", since my Linux boot partition is on /dev/hda2
Then "setup (hd0,1)" to reinstall grub on the Linux partition instead of MBR
Type "quit" to finish

Then I used the dd commend to create a floppy boot disk:

dd if=/dev/hda2 of=/dev/fd0

and made a linux.bin file for dual-boot:

dd if=/dev/hda2 of=/mnt/hda3/linux.bin bs=512 count=1

Reboot into Windows and use the util "explore2fs" to copy the linux.bin from Linux partition to my C:\ drive under Windows.

Modify the boot.ini to add
C:\linux.bin="Debian"

Reboot into Debian by choosing from the multiboot list

[ Parent | Reply to this comment ]

Posted by Anonymous (89.32.xx.xx) on Sat 18 Feb 2006 at 20:52
Yeap! That's it...

[ Parent | Reply to this comment ]

Posted by umatur (80.172.xx.xx) on Mon 6 Mar 2006 at 23:15
I was able to restore GRUB using a "Ubuntu Live CD" and the following the instructions set by Serrador. However I have a little problem. Well it's not a problem its more a curiosity. First I tried to use the Debian install cd(using the temporary concole) but I couldnt mount the root partition. How is it done?

Thanks

[ Parent | Reply to this comment ]

Posted by serrador (80.28.xx.xx) on Tue 7 Mar 2006 at 15:06
I think the problem is with device names. With debian cd you get /dev/disk/disk0/part1 devices instead of /dev/hda.

[ Parent | Reply to this comment ]

Posted by Andrew_Indrawn (195.201.xx.xx) on Sun 16 Apr 2006 at 12:38
Thank you for this article.

I have cofiguration:
(hd0,0) winXP
(hd0,1) /boot /dev/hda2 /dev/discs/disc0/part2
(hd0,2) swap /dev/hda3
(hd0,3) /____ /dev/hda4 /dev/discs/disc0/part4

Since my /boot is a separate partition, I have mounted /boot partition before chroot:

mkdir /disc/boot
mount /dev/discs/disc0/part2 /disk/boot

So, I am applied commands:
#Boot from debian CD choosing linux2.4 kernel (default)
...
# Run grub command to enter grub shell

After "grub" I have got "Unable to handle kernel NULL pointer... segmentation fault..."

So, I tried:
grub-install /dev/hda

Then reboot to get into "GNU GRUB version 1.93"
I have run:

grub> linux (hd0,1)/vmlinuz-2.6.16.4 root=/dev/hda4
grub> boot


After booting I can execute without problem:
grub
root (hd0,1)
setup (hd0)
quit


After rebooting, I see Grub welcome screen.
That's all.

[ Parent | Reply to this comment ]

Posted by Anonymous (59.167.xx.xx) on Tue 25 Apr 2006 at 03:28
Hi, I readly could do with this article, however I do not have the experience in Linux to understand the steps, please see below.

To get back our grub first stage boot, here a procedure you can use.

* Boot from debian CD choosing linux2.4 kernel (default)
Could do this OK.

* Change to console 2 with alt + F2 keystrokes
Could follow this

* Make a new dir to mount the boot partition, for example /disk
I guess that this was;
cd /
mkdir /disk

* mount the root partition on /disk.
Have no idea what to do here, except that mount will be used but what do I mount?
what is the format of the command?

* Do a chroot to the root partition: issuing chroot /disk
I guess that I enter (but not being able to mount hda0 how am I to do this?)
chroot /disk

* Run grub command to enter grub shell
what is the grub command ?

* Type in the root disk for grub, for example root (hd0,1). This is /dev/hda2 on my system
?

* Type the following command to install grub on /dev/hda: setup (hd0).
?

* Last step, type quit, exit from chroot, unmount all disks and reboot
Hey I think I could follow this one : )

Thanks,

George Kirkham.

[ Parent | Reply to this comment ]

Posted by Anonymous (58.162.xx.xx) on Mon 12 Jun 2006 at 14:10
Follow the steps above for the grubby stuff

But something missing is the problems I have encounted with windows. It wants to own the drive. no other partitions can exist first.
Don't use windows tools to backup windows data to your linux partitions, ever heard of a cd/dvd burner or thumb drive.
If the doze file system isn't toast, run linux, mount the windows partition (ro),
don't forget to grab your email, address book (not in a My directory ;)
Copy across, then burn cds, you will feel much more comfortable if it all goes pear shaped.
Use cfdisk or fdisk, note beginning sectors and sizes of all partitions.
Remove all linux partitions.

Install windows

Put your linux partitions back. Now do your grubby best,
But make debian the boot default and don't bother putting your data back in windows because you will need it in Linux.

Go Well,
Colin

[ Parent | Reply to this comment ]

Posted by Anonymous (213.240.xx.xx) on Wed 16 Aug 2006 at 09:30
How do you mean boot from Debian CD? Debian is not live CD. When you insert it it goes through a process of ninstalation, and you do not want that, right?

[ Parent | Reply to this comment ]

Posted by Steve (62.30.xx.xx) on Thu 17 Aug 2006 at 00:10
[ View Steve's Scratchpad | View Weblogs ]

Boot it and when the installation "proper" starts you can press "Alt + F2" to switch to a shell.

You can go part-way into the installation, entering language etc, until you get to the first destructive operation which I guess is the partitioning setup. If you do that you should have networking and the hardware detection should have finished; allowing you to mount your disk(s).

Steve

[ Parent | Reply to this comment ]

Posted by morequarky (58.75.xx.xx) on Sat 16 Sep 2006 at 13:20
This is a GRRRRREEEAT thread on grub re-installation.

EXCEPT

It leaves out my problem.

To make a long story short...my MBR was toasted by another member of my family.

Your documentation in this thread only works to a point it seems on my system. I reinstalled grub using hda2 blah blah blah.

GRUB now works just dandy which would seem to contradict my statement that my problem is not talked about in this forum. My debian(ubuntu) install has /home and /usr and /var and two others I can't remember on different partitions.

I reinstalled GRUB and GRUB works just fine, but now after my kernel on hda2 is loaded, it crashes to what seems like a useless prompt because it can't find the "filesystems" located on other partitions.

How do I fix this using a liveCD?

[ Parent | Reply to this comment ]

Posted by cordeb (192.109.xx.xx) on Wed 20 Sep 2006 at 15:47
hy,

it seems you are missing your root partition / mount point
# start with a live cd like knoppix or debian rescue shell and
# than become root
su -

# if you do not know your partition table anymore, get at first a overview/list
# by fdisk or similary tools (here the first harddrive "hda" is used,
# for second drive use "hdb"...)
fdisk -l /dev/hda

Disk /dev/hda: 10.2 GB, 10248370176 bytes
255 heads, 63 sectors/track, 1245 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 2 16033+ 83 Linux
/dev/hda2 3 4 16065 83 Linux
/dev/hda3 5 36 257040 82 Linux swap
/dev/hda4 37 1245 9711292+ f Win95 Ext'd (LBA)
/dev/hda5 37 559 4200966 83 Linux

# than, mkdir a tmp directory/directories for mounting them and look on that for
# files and directories on that partitions:
mkdir -p /mnt_tmp/hda1
mkdir /mnt_tmp/hda2
mkdir /mnt_tmp/hda5
...

# than mount these partitions and have a look on it:
mount -t ext2 /dev/hda1 /mnt_tmp/hda1

# please use type of partition as listed by fdisk, so for reiserfs use
mount -t reiserfs /dev/hda1 /mnt_tmp/hda1

ls -l /mnt_tmp/hda1

# do this for the other partitions too
# UNTIL you know where your root partition is!
ls -w 1 /mnt_tmp/hda5
bin
boot
data1
data2
dev
etc
home
lib
lost+found
media
mnt
mnt_tmp
opt
proc
root
sbin
smb
srv
tmp
usr
var



# and now check and compare, if you have also configured and/or installed grub
# correctly (like the "root=/dev/hda5"):

</boot/grub/menu.lst>
title linux SuSE 8.2
kernel (hd0,0)/vmlinuz root=/dev/hda5
initrd (hd0,0)/initrd

title Linux SuSE6.x
root (hd0,1)
kernel /vmlinuz root=/dev/hda2
initrd /initrd

</end>

# so if you have not set this on the correct partititon, grub cannot find the
# root mount point _and_ of course will fail to do so.

# do you have a difference between the menu.lst and your root partition is
# anywhere else, you have to install grub again with the
# correct "root=/dev/hdXY".
# or using the solutions written above, in this case you have to do:
grub
root (hd0,4)
setup (hd0)
quit

# reboot now. I hope this helps a little bit
init 6

# sincerely

[ Parent | Reply to this comment ]

Posted by Anonymous (62.79.xx.xx) on Wed 7 Mar 2007 at 16:13
This becomes a tad more complicated in the case where your / resides in a LVM volume (and $DEITY help you if your /boot does too). I found that the easiest way to handle this was to start an expert installation and play along until the disks where mounted, then open the shell and follow the original article.

[ Parent | Reply to this comment ]

Posted by Anonymous (193.50.xx.xx) on Tue 18 Nov 2008 at 15:18
For non newbies !
If you have more than 1 partition ! for exemple /usr in an other partition you may mount this partition first before chroot, even you won't be access to grub command

[ Parent | Reply to this comment ]

Posted by Anonymous (221.221.xx.xx) on Wed 17 Dec 2008 at 03:51
I got a way to recover it.
1.use debian install CD,and exe an shell,mount your Debian pratition,read out your menu.lst of your boot info.Like this:
title Deian Linux on (hd0,3) (Sample)
root (hd0,2)
kernel /boot/vmlinuz-2.6.18-6-686 root=/dev/sda3 ro
initrd /boot/initrd.img-2.6.18-6-686
the menu.lst is at /boot/grup/menu.lst
2.reboot your PC and enter your Windows system. download GRUB for windows.
modify the menu.lst of it. add the bootinfo to it ,like above. then reboot.
3. to select to bootyour Debian,and enter root CLI.
run grub-install --recheck /dev/sda.reboot
4. Now the bootmenu is like before and select Windows to boot.then you will see another grup title under your Windows boot title.
bakup modify the boot.ini on your system disc. remove c:\grldr="启Ã&ye n;Š¨Grub" .
5. reboot the system, and you will see it will like before.

[ Parent | Reply to this comment ]

Sign In

Username:

Password:

[Register|Advanced]

 

Flattr

 

Current Poll

What do you use for configuration management?








( 122 votes ~ 0 comments )