NotebookForums.com › Forums › General Notebook Discussions › Linux & Other OS's › restoring grub after winXP install
New Posts  All Forums:Forum Nav:

restoring grub after winXP install

post #1 of 19
Thread Starter 
Hi all, i've been using ubuntu dapper for a couple weeks now, just wanted to say im really liking it and have found this forum pretty useful.

anyway, i reformatted my windows partition today and, as expected, lost the grub menu at system start up. I made a Super Grub Disk and tried to have it automatically restore grub to the mbr, but for whatever reason that isnt working. whats the simplest fix for getting my dual boot setup back? thanks.
post #2 of 19
Quote:
Originally Posted by ocspecv
whats the simplest fix for getting my dual boot setup back? thanks.
Did you try booting from the Ubuntu install CD and then reinstall grub? (I don't know Ubuntu enough to know if that's the procedure, but it's the way you would do it under Gentoo..)
post #3 of 19
i may be wrong what what you gotta do is boot a livecd (ubuntu cd is fine) then chroot into your installed environment (see Gentoo Handbook for instructions) and then install and configure grub (don't forget to double check the menu.list to make sure its accurate) then unchroot and reboot.
post #4 of 19
Quote:
Originally Posted by abf
i may be wrong what what you gotta do is boot a livecd (ubuntu cd is fine) then chroot into your installed environment (see Gentoo Handbook for instructions) and then install and configure grub (don't forget to double check the menu.list to make sure its accurate) then unchroot and reboot.

Yea ABF is correct. Grub has its own commandline tool to install it, but you need to boot into your environment via live CD and do it by hand at this point I believe. I am not sure if you NEED to chroot into it, but it wouldn't be a bad idea.

Also as ABF mentioned the Gentoo documentation is a good place to go for instructions on how to do this. Check the gentoo handbook for how to do all of the above.

Seablade
post #5 of 19
Thread Starter 
Quote:
# chroot /mnt/gentoo /bin/bash # env-update >> Regenerating /etc/ld.so.cache... # source /etc/profile # export PS1="(chroot) $PS1"
this is what i found on chrooting in the gentoo handbook, my question is what goes in place of 'gentoo' in the first line? secondly how do I install and configure grub? ive tried a google search but im getting a variety of confusing methods. thanks for the replies.
post #6 of 19
Quote:
Originally Posted by ocspecv
this is what i found on chrooting in the gentoo handbook, my question is what goes in place of 'gentoo' in the first line? secondly how do I install and configure grub? ive tried a google search but im getting a variety of confusing methods. thanks for the replies.
Actually it would be in place of /mnt/gentoo What you would want to do is mount your entire linux filesystem in some folder off the live CD, say /mnt/linux Then after that you would type.. chroot /mnt/linux Not sure if /etc/profile exists in other distros, can't remember right off hand, someone help me out on that one? The section on installing grub is found later in the gentoo handbook. That should answer your question, just make sure if you don't have a floppy drive, you pass the appropriate flag to it(In this case I believe the command would be 'grub --no-floppy' without the apostrophes obviously, but feel free to double check on that) Seablade
post #7 of 19
Thread Starter 
Quote:
Originally Posted by seablade
Actually it would be in place of /mnt/gentoo What you would want to do is mount your entire linux filesystem in some folder off the live CD, say /mnt/linux Then after that you would type.. chroot /mnt/linux
trying to do this now without any success. how do i mount to a folder off the linux live cd? (im presently using the livecd)
post #8 of 19
Quote:
Originally Posted by ocspecv
trying to do this now without any success. how do i mount to a folder off the linux live cd? (im presently using the livecd)

Since I am not the best person at explaining things I would reccomend reading this post through entirely before you attempt anything so that any of my out of order thoughts don't get lost.

Well you don't mount a folder, you mount a partition to a folder/location on your current linux filesystem tree.

When you install linux, even if you don't realise it, your HD is partitioned in a certain way. What happens in a partition may be created for the /home directory, but when it is created it has no clue that is it the /home directory. That gets decided later on, Ill come back to it in a moment.

Now.. When Grub boots(Or lilo, etc) it reads a file off your boot partition as it is saved in the MBR. Very simplified there, but the details can be confusing even for me, and we don't need to know them completely to do this.

At any rate, in the file it reads, in our case it is menu.lst it is told what partition is equivalent to the root partition of our linux install. The root partition is not to be confused with the folder and its contents /root which is in actuality the /home directory for the superuser. The root partition we are referring to for this is the '/' directory on your linux filesystem. So /home is in actuality the home folder on the root directory.

So why do we need to know this? Because what you need to mount is the partition that is your root partition. Depending on wether your HD is IDE or SATA/SCSI will determine where it is located. IDE HDs are in general /dev/hdx where the 'x' in hdx can be ANY letter. However for most people this will be 'hda' as that equates to the master device on your primary IDE channel. hdb would be the slave device if I remember right, though it has been some time since I bothered much with it. Pretty much the simplified way to remember it is it is the order in which your computer detects your devices. If in doubt mount /dev/hda and then cd to the directory you mounted it at and see if it is correct, if not go to the next device("/dev/hdb" in this case)

No for SATA and SCSI devices it is nearly identical but instead of being /dev/hdx it would be /dev/sdx again where the 'x' can be any letter.

Now the catch is, in most cases a typical hard drive will have more than one partition. As such we don't want to mount the entire hard drive, and will probably get an error if we try. As such in linux we determine what partition we are referencing in the above commands, by attaching the partition number at the end of the device ID. So for example... /dev/hda1 would be the first partition on the first IDE device(Usually the Hard Drive as I mentioned earlier) /dev/hda2 would be the second partition on the first IDE device, and so on. /dev/sda2 would be the second partition on the first SATA device. /dev/hdc1 would be the first partition on the third IDE device. Make sense so far I hope?

So what you would want to do is mount the correct partition at whatever location you wish to use to access it, and then use that location in your chroot command above. If you are in doubt as to which partition is correct, go ahead and mount them one at a time, cd to that folder, check if it is the correct partition. If it is not, cd OUT of that folder, and use the command umount to unmount that location, and move on to the next partition, repeat step one, until you find it Then you can move on.

For the purposes of reinstalling grub, you need to make sure your /boot directory on your linux HD is mounted BEFORE you attempt to install grub. Otherwise it will hopefully just fail On most general distros like Ubuntu, Suse, whatever, the boot folder is located on your root partition, so there is no extra work involved, though some people(Like myself) have it on its own partition as it is not needed at all once linux is booted, unless you are doing something like recompiling the kernel, in which case I mount it by hand.

Hope I wasn't to confusing, have fun.

Seablade
post #9 of 19
Thread Starter 
seablade - thanks for ally our help and quick responses on my system there are 3 partitions on 1 hdd, when i run the fdisk -l command it shows:
Quote:
Disk /dev/sda: 80.0 GB, 80060424192 bytes 255 heads, 63 sectors/track, 9733 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 8165 65585331 7 HPFS/NTFS /dev/sda2 8166 8426 2096482+ 82 Linux swap / Solaris /dev/sda3 8427 9733 10495938+ 83 Linux
now i did 'mount dev/sda3 /mnt' and succesfully mounted my linux partition, chrooted into /mnt, and checked the menu.lst file and everything looked ok. so now how do i get grub back into the mbr? thanks again for all your help and babying me through this process =)
post #10 of 19
I believe we are discussing a x86 install here, so I grabbed that part of the appropriate manual, but it probably wont make the least bit of difference to be honest...

http://www.gentoo.org/doc/en/handboo...p=10#doc_chap2

Is the handbook pages from Gentoo on how to set up grub. You want section 10.b and then scroll down until you see "Alternative: Setting up GRUB using manual instructions"

That should walk you through using the grub commandline utility to reinstall it on the MBR. If your menu.lst is already correct(Sounds like you already checked that and it is) this should walk you through it pretty well.

The only thing that gets covered earlier, is that GRUB has its own numbering scheme for partitions and drives. The command root (hd0,0) that you will see in the example means the first partition of the first drive. Grub uses numbers to determine which drive AND partition, and the numbering scheme actually starts at 0. There is reason to this, but it will only make sense to programmers, trust me At any rate, just remember your first drive, or your first partition would be number 0, NOT 1. Your second drive, or second partition would be number 1, NOT 2, and so on.


Seablade

PS I suppose I should have put in your case, most likely what you would want that command to be would be....

root (hd0,2)

for the third partition of your first drive.

and the next command would be

setup (hd0)

to install GRUB on the MBR of that drive.
post #11 of 19
Thread Starter 
right, ive been staring at that page for a good 30 minutes now, in the grub> prompt when i put in those commands i get "Error 21: Selected disk does not exist"

perhaps im not running it from the proper location?

edit: yep, just ran it as root and seems like it succeeded. now to test it out. cant thank you enough seablade, your help is much appreciated.
post #12 of 19
Thread Starter 
hmmm...well now the grub bootloader comes up, but i cant boot into ubuntu, i get an unable to mount error. When i was restarting out of the livecd i was unable to unmount the partition, it said the command was not recognized. could this be why? back to the livecd i go...
post #13 of 19
Hmm you have not changed the menu.lst file at all have you? Or installed a new linux system?

If you can't figure it out, post up your menu.lst file like you did the output of those other commands and we can take a look at it. Also do you happen to remember what you formatted that partition as? Most likely it is ext3, but I just want to make sure.

If you can, run dmesg after a failed boot(In the chroot), and see if any of the messages at the end are timestamped for your most recent boot, look towards the end and see if you see anything that might help us and post it up as well.

At least you are learning a bit about how linux operates

By the way, when attempting to unmount the partition after leaving the chroot, did you type umount or unmount (Note the extra 'n' in the last version) umount is what you would want, and yes you would probably need to run it as root.

Seablade
post #14 of 19
I came across this somewhere on the internet (a memory is a terrible thing to lose) I haven't had occasion to try it personally, but I'm not sure why I never thought of it myself. Once you have it working again, it might not be bad to make yourself a backup (I did)

Quote:
As a precaution to this type of problem I have been making my own backup of the master boot record using dd:

dd if=/dev/hda of=/boot/092006.mbr bs=512 count=1

This will create a 512 byte file named 092006.mbr in the /boot directory. If I ever botch my master boot record I can just copy the known working 092006.mbr file back to the master boot record like so: (using Knoppix)

dd if=/mnt/hda1/boot/092006.mbr of=/dev/hda
post #15 of 19
Thread Starter 
i suspect there is something wrong with the menu.lst file as well. when it failed to boot it showed the root=sda2 for the kernel i selected, which i believe is incorrect, it should be sda3. anyway now im having trouble chrooting into the mounted partition, because of a "cannot run command '/bin/bash': no such file or directory.

edit: well this is lovely, i think i wiped out the /dev/sda3 partition, i thought i had unmounted it and tried to remove the folder i created to mount it to, and i guess since it wasnt unmounted it deletes the data on the partition? anyway now to reinstall ubuntu, fortunately there wasnt anything crucial on there. thanks for all the help nonetheless.
post #16 of 19
Quote:
Originally Posted by ocspecv
i suspect there is something wrong with the menu.lst file as well. when it failed to boot it showed the root=sda2 for the kernel i selected, which i believe is incorrect, it should be sda3. anyway now im having trouble chrooting into the mounted partition, because of a "cannot run command '/bin/bash': no such file or directory.

edit: well this is lovely, i think i wiped out the /dev/sda3 partition, i thought i had unmounted it and tried to remove the folder i created to mount it to, and i guess since it wasnt unmounted it deletes the data on the partition? anyway now to reinstall ubuntu, fortunately there wasnt anything crucial on there. thanks for all the help nonetheless.


Uh... I would be REALLY impressed if you wiped out the partition, that takes some incredible luck, even doing something like that.

Seablade
post #17 of 19
Thread Starter 
apparently so, when i went about remounting to do a different folder the folder is empty. is that typically not possible? do delete a folder containing a mounted partition and deleting the files from that partition? the partition itself is still there it just shows as being 289 mb where it was upwards of 5 gigs before. anyway yes at least i learned alot from this whole process. hopefully it will be of some help to others as well.
post #18 of 19
Yea sounds like the FS table was a bit screwed up then, it probably stopped in mid-write for whatever reason then, causing the problem you are seeing. For next time(Or this time if you haven't already) fsck can be useful to see if it might be able to repair it. It should be on ANY linux install.

Seablade
post #19 of 19
I'm gonna just reiterate what been said by others about getting a gentoo disc to fix grub... This is one of those times that it's REALLY useful to have at least gotten the gentoo basic install under your belt. I've had two cases where I've had to fix grub and it took less than 10 minutes doing the gentoo chroot method. If you have the time i'd suggest taking about 2 hours to get gentoo to boot to the command line off the hd. You'll learn a tremendous amount if you follow the guide carefully. From there i'd just wipe it and reinstall ubuntu as I think it's too tedious to get gentoo working well on a laptop.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux & Other OS's
NotebookForums.com › Forums › General Notebook Discussions › Linux & Other OS's › restoring grub after winXP install