How-To Geek

Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out

If you run a dual-boot system with Linux and Windows, this has happened to you. You had to do your monthly reinstall of Windows, and now you don’t see the linux bootloader anymore, so you can’t boot into Ubuntu or whatever flavor of linux you prefer.

Here’s the quick and easy way to re-enable Grub.

1) Boot off the LiveCD

2) Open a Terminal and type in the following commands, noting that the first command will put you into the grub “prompt”, and the next 3 commands will be executed there. Also note that hd0,0 implies the first hard drive and the first partition on that drive, which is where you probably installed grub to during installation. If not, then adjust accordingly.

sudo grub

> root (hd0,0)

> setup (hd0)

> exit

Reboot (removing the livecd), and your boot menu should be back.


Only read below if Windows is now missing from the boot menu

If you installed Ubuntu before you installed Windows, then Ubuntu will not have anything in the grub configuration for Windows. This is where you’ll have to do a bit of manual editing to the grub boot menu file.

If you open the file /boot/grub/menu.lst with the following command:

sudo gedit /boot/grub/menu.lst

You’ll see a sample section for Windows, which you’ll want to uncomment and add to the boot menu list in whatever position you want it in. (uncomment by removing the #’s)

# title   Windows 95/98/NT/2000
# root   (hd0,0)
# makeactive
# chainloader   +1

Note that you should also verify that hd0,0 is the correct location for Windows. If you had installed Windows on the 4th partition on the drive, then you should change it to (hd0,3)

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 03/22/07

Comments (112)

  1. Nirav Thaker

    Well, it didn’t work for me, I mounted /boot to separate partition (hd0, 4) and grub failed to find the stage1 files..

    I’ve to run windows repair to rewrite the boot sector in MBR.

  2. Sam Dawson

    Thanks for this solution, however it did not help my situation as windows was kind enough to rewrite the mbr on my laptop when it went into hibernate. This laptop does not have a working cd drive, thus is unable boot from a livecd.

    Another solution I found is to use ntldr and load a version of grub from there (grub4dos). I think it would be a good idea to provide instructions for people on how to achieve this using ntldr and grldr.

    The only caveat with having a setup like this is that you will need to copy menu.lst that grub uses to the default windows partition everytime you perform an system update (otherwise it wont load the latest kernel).

    I have setup my laptop to use this method. First I added the line:

    C:\grldr=”GRUB Bootloader” to windows’s boot.ini

    I copied the file grldr from grub4dos to C:\

    Using ext2ifs on windows I copied the menu.lst from /boot/grub to C:\ on my windows install.

    After rebooting, I had a working install of GRUB. This didn’t require me to rewrite the mbr of my hard drive.

  3. Jonathan van Zuijlekom

    What you need to do before entering root (hd0,0) is the folowing:

    find /boot/grub/stage1

    This wil give you the root you have to use. In my case it wasn’t hd0,0 but hd0,1.

  4. Another Ubuntu user

    Once I’d used “find /boot/grub/stage1” on hd2, I found I had to change the original command as such:

    sudo grub

    > root (hd2,0)

    > setup (hd0)

    > quit

  5. Jason Yu

    it works on mine

    sudo grub

    > root (hd0,2) # this is sort of related to your partition ubuntu installed

    > setup (hd0)

    > exit

  6. Asim

    It worked for me. The only thing I had to do different is that I had to type


    instead of exit. exit doesn’t seem to be a known command.

  7. Proximo

    I use a program called “Super Grub Boot Disk” that allows repair of both Windows and Grub boot loaders…google it, download it and burn it to cd…works great and has loads of optins for Windows or Linux…it’ll be worth the effort,believe me….Proximo

  8. Proximo

    I use a program called “Super Grub Boot Disk” that allows repair of both Windows and Grub boot loaders…google it, download it and burn it to cd…works great and has loads of options for Windows or Linux…it’ll be worth the effort,believe me….Proximo

  9. Jenn

    is there a way to do the opposite? Restore the windows boot loader? When I bought my computer I was only supplied with the factory restore disks. I tried the wubi installer but it booted to ubuntu grub then pressed enter to boot into windows xp…it brought up a windows boat loader with windows and ubuntu. I am also looking to fix my partition table, and increase ubuntu disk space also.

  10. Bart

    The first step should be find /boot/grub/stage2 and whatever it returns should be used instead (hd0,0) in your examples.

  11. Ryan

    I’m passing back and forth between having ubuntu running and having Vista running. I used to have them both, though. After I re-installed Vista, it over-wrote my MBR. So I re-installed the grubloader (on hd0,0, my Vista partition…maybe that’s the problem?) but now even though Vista is listed on the boot menu, when I hit enter to boot into it, it returns me to the boot menu.

  12. James

    Ok guys I have a question for you. I have tried a lot of stuff on this one. Im running 2 Hard drives on my computer. My main Harddrive has windows vista on it (120gb hard drive). My second hard drive (30gb) has my linux installed on it. I cant get grub to boot. when it does boot i get a boot error. error 17. I cant even get to my second harddrive at all. I want to be able to boot into either of them when i please. What can i do to fix this guys ?!?!?!?! Thanks in advan.

  13. iced_773

    To use the Windows boot loader, you can do one of two things:

    In Win98/Me, type from a command line: fdisk /mbr

    In Win2000/XP, go to the Recovery Console and type: fixmbr

    Hope this helps.

  14. CouldBeMe

    I think VISTA would prefer to do its own thing and lead you to believe you have allowed GRUB to manage a dual-boot scenario. I see many symptoms of sneaky virtualization. You might as well run VMware.

  15. bayyou

    Thank you because of you my computer have been save..

  16. Dave

    Worked for me. I used the Fiesty LiveCD since that’s what I had installed. I originally had Vista and put Fiesty on hd0,1. Then today I installed XP in the same partition as Vista and just had to run through the recommended directions with hd0,1 for the root line. At this point I can’t boot to Vista but well, that’s no real loss.

  17. Ryan

    Thanks for the great guide. It really helped me.

  18. Van

    I’ve got a case.My computer runs Windows XP, then I installed Ubuntu Fiesty 7.04. Two days ago, I ran Update Manager, it required restart, After restarting, I couldn’t get into Ubuntu ( I remember I got error when updating). I reinstalled Ubuntu but it’s stayed the same.
    I guess the first time I installed Ubuntu, grub manager know where to boot Ubuntu. But in the second time, It can’t find because root disk is mouted differently.
    The problems are I can’t boot Ubuntu, I can’t reinstall Ubuntu again.
    Do I need install Win again that means format my primary disk to remove grub manager?
    PS: My English is not good :)

  19. faical

    with the Live CD Ubuntu

    sudo grub –batch


    grub> find /boot/grub/stage1

    grub> root (hd0,1)

    grub> setup (hd0)
    grub> quit

  20. Heather

    Thank you so much! This worked perfectly after I had tried about everything else recommend by many other sites that did not work! I had installed Vista first and then after installing Ubuntu 7.10 I was unable to see Vista listed after I rebooted.

    Also, after I did the procedure above and was able to see Vista listed in the grub menu, I got an error message about the MBR and wasn’t able to startup Vista. So, I booted from the Vista install DVD and, instead of choosing Install, I chose Repair. It found the Vista installation, recognized that it had a problem, and asked me if I wanted it to fix it. So, I of course said yes – repair it! It took less than a minute to fix. I rebooted, saw the grub menu, selected Vista, and it started up perfectly. I then restarted to make sure that I could still start up Ubuntu, and it worked perfectly as well!

    Hope this might help someone else! The Vista Recovery is awesome compared to the old XP method!

  21. Rahul Singh

    Thanks for the great help!!!

  22. Rich

    Ok, so I had Vista installed on here once long ago, I have like 5 partitions on this workstation (hardware R5 4x 300gb) I want to nuke anything even related to vista, where to find? I see that vista stuff on the import settings menu, I imagine its causing some problems here. how can I kill the beast forever?

  23. Pim

    Thanks for the information.
    I think “exit” should be “quit”, at least in Ubuntu 6.04, but that’s a minor detail

  24. Don Snabulus

    This page worked for me, but I had to first repair the partitions that Windows messed up on my MaxBlast altered hard drive. The only thing that could find my Linux partitions from my searches was Partition Table Doctor ( It cost me $50, but I was able to fix the partition table and MBR. Then I used this page (my partition was at hd0,2) to recreate the grub bootloader and VOILA! I am back to normal.

    (Interestingly, MaxBlast, Acronis Disk Manager, and the Ultimate Boot CD could not properly read the partition table and did not work. I am especially disappointed in MaxBlast as it was the cause to begin with.)

  25. D-Dan

    Thank you so much. After Windows finally died completely forcing a re-install the last thing I had to worry about was how to get Ubuntu back. This worked flawlessy, though I had no idea where Linux was in the disk map before I started.

    My solution was to boot the live CD then explore the local drives until I found it. Had a quick look at menu.lst and there was all the info I needed.

    You saved my day :)

  26. Jim Murray

    I suggest you add the following command into your procedure to insure the correct HD and partition is selected. e.g. my is on HD 0,5

    find /boot/grub/stage1

    Thus, making procedure

    sudo grub
    find /boot/grub/stage1
    root (hd?,??)
    setup (hd?)

    where hd?,?? is returned from find command.

  27. raju2626

    hello friends. my ram is 256mb so i cant install ubuntu of latest version which is live cd. so i have go to the older version of ubuntu so i installed edubuntu in my computer which is not a live cd. due to some problems in my windows xp i had removed xp and reinstalled it in my computer by this my grub has lost. i want to log in into edubuntu so i should install grub. so please help me in installing grub through edubuntu.

    or else i should completely remove the edubuntu and reinstall it again in my computer

  28. muyowa

    thanks “Jim Murray” your explanation really help cheers

  29. Bhupi

    unfornately i have failed to boot OS (XP) on my laptop which came with pre-installed Windows xp. when i boot my laptop using Windows XP CD it copies the required files but when i press ENTER to install Windows XP the message appears that ” Setup did not find any hard disk drives installed in your computer. Make sure any hard disk drives are powered on and properly connected to your computer and that any disk related hardware configuration is correct. This may involve running a manufacture supplied diagnostic or setup program.

    Setup cannot continue. To quit setup, press F3.” Please note I have C: drive installed windows xp on it, i have drive D: files are available for recovery disk pre-installed by the windows manufacturer. My laptop is HP dv5000. Please advise how to install boot laoder on this laptop.

  30. Ben

    with the Live CD Ubuntu

    grub> find /boot/grub/stage1

    grub> root (hd0,5)

    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,5)/boot/grub/stage2
    /boot/grub/menu.lst”… failed

    Error 22: No such partition

  31. gmolleda

    sudo mount -t ext3 /dev/sda2 /mnt
    sudo grub-install –root-directory=/mnt /dev/sda

    (change sda2 and sda to your linux system and drive, could be hdaX and hda)

  32. ssuper2k

    it worked for me perfectly…

    booted into livecd, and then:
    sudo grub
    > root (hd0,0)
    > setup (hd0)
    > exit

    sudo gedit /boot/grub/menu.lst
    and then uncommented, these: #

    # title Windows 95/98/NT/2000
    # root (hd0,1)

  33. Kumar

    The following worked for me=>

    Restore GRUB menu after Windows installation:

    Use the following in the terminal –

    To re-enable the GRUB

    sudo grub

    root (hd0,0)

    setup (hd0)


    To identify the name of the boot drive,

    cat /boot/grub/

    To find which drives are bootable,

    sudo fdisk -l

    gksudo gedit /boot/grub/menu.lst

    Append the following lines at the end of file:-

    title Microsoft Windows
    rootnoverify (hd0,0)
    chainloader +1

    Changed few things – Added # to hiddenmenu (Menu appears on startup to choose the operating system), changed time to 5 seconds.

    Save the edited file

  34. Sansal

    I recovered Grub successfully. But when I select the Ubuntu options on the boot menu, it says “Can not mount selected partition”.

  35. jbasko


    Another way is by using the alternate CD, and going in to rescue mode. Use the GUI to mount your original linux installation partition i.e. the root partition. After that, start a shell on that partition, then run ‘sudo grub-install’. It should fine your original grub setup and re-install it.

    Just myu $0.02

  36. Sansal

    I recovered Grub successfully. I can boot XP from the menu. But when I select the Ubuntu options on the boot menu, it says “Error 17 : Can not mount selected partition”. In addition, when ı try to open menu.lst from live cd, it seems empty. I need your help.

  37. spi

    thank you!!!!

    that was great!

  38. Pawan Kumar

    I can boot my computer through DVD but i have got the error GRUB 17 during installation time , and after that computer cnat boot please give me better solution for the same .

  39. Ben

    Okay – I messed up my mbr and tried to use Testdisk to fix it. It was visible when I ran gparted, but there appeared to be some problem. After finishing with testdisk, I tried the grub again, and eventually managed to boot Windows, which fixed up the NTFS partitions. Then I stuck in the new HDD (now have two – first is 320GB Barracuda, and the second is a 500GB – same model, but now 500GB is the cheapest size! the extra 145gb of useable space cost half as much as the first 320 but if you go to 750GB it’s too much.

    After that, windows was the only visible option, so I ran the liveCD once again, feeling very bored, and it found my boot
    sudo grub

    This is rather short – there should be another option, after ‘sudo grub’ in ubuntu I used
    grub> find /boot/grub/menu.lst
    grub> root (hd0,0)
    grub> setup (hd0)
    grub> exit

    sudo gedit /boot/grub/menu.lst
    I took ‘quiet’ out so I can see how it’s loading up.
    My first drive is the 320GB, and I have WindowsXP in the first (30GB) followed by swap of 3.4GB, I was hoping the hibernate would work – or the sleep. Hi hopes? and then linux ext3
    I will use the second drive to house two large partitions for all documents/personal stuff, and for backups. Anyone know a one click solution to making a complete image of your linux system – as they managed to do with Vista? Vista got that right, why can’t we?

    # title Windows 95/98/NT/2000
    # root (hd0,1)

  40. Troy Ferrer

    Yes, this did the trick for me on my laptop… but sadly, i couldn’t boot into WinXP although it was available as an option in the Grub list. ERROR12 was what I got. I’m trying out what the commenter named HEATHER to get my MBR back working…. wish me luck. I’ll post back the results, so here goes…

  41. Karuna

    mine says cannot mount selected partition when in comes to setup (hd0) .
    It is the correct partition tho…. anybody know whats wrong?

  42. Troy Ferrer

    Me again, this is my second post. I did what Heather did, hoping to get my XP back working after restoring my Grub… but there wasn’t a fix-MBR option in my XP installation disk. Probably my ignorance to not know where to find it, but I did go thru the installation of XP to see where it is, to no avail. So I just went with another install of XP on the same disk without touching the filesystem. That worked for my XP, but lost the grub once again. Perhaps because they’re one the same disc (hd0,0), just a guess. Anyone know?

    @Karuna: do this first

    find /boot/grub/stage1

    just for you to be sure which one it is on. Don’t forget to add the comma and the second digit. Hope this helps. I’ll post again after my grub decides to come back. ;)

  43. ivo

    I have this problem
    First disk is Windows XP
    Second disk Ubuntu 8.04 Lts
    I’ve formatted only first disk
    and after an installation of windows I’ve installed “auto super grub disk 1.0” for windows
    reboot selet super grub
    and I see

    grub> findf /boot/grub/stage1
    root (hd1,0)
    Filesystem type is ext2fs, partition type 0x83
    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)” (the cursor is here)

    and the program make nothing
    When I reboot manually, I see only windows bootloader and not grub

  44. Michael

    Wow, this seriously saved my ass. I can’t thank you enough!

  45. ivo

    start with a ubuntu live cd
    open the console
    sudo su
    find /boot/grub/stage1
    (hd 1,0)
    root (hd 1,0)
    setup (hd 0)
    restart your pc

  46. James

    Okay guys, I’m stumped. I had Ubuntu 7.10 and Vista running on seperate disks using grub to switch between them no problerm. I replaced Vista with XP SP3. Don’t laugh. lol. I had my reasons. Anyway, Windows is working fine, but Linux (or at least grub, or something I don’t know about) has gone for a burton.

    I tried booting from the Live CD, loading a terminal, sudo gedit /media/disk/boot/grub/menu.lst, fixing the entries, restart, select whichever kernel from grub: Error 17: Cannot load the selected partition.

    Then I tried sudo grub, root (hd1,0), setup (hd1)… Error 17: Cannot load the selected partition.

    As I said, I can boot a Live CD and view all my files. There is nothing wrong with the file system then, and I have grub loading with what appears to be a perfectly sound menu.lst file. But it seems no matter what I do, grub gives me error code 17.

    I can of course back up all my files no problem, but I really would prefer not to have to reinstall. I made many adjustments to Ubuntu to make it work the way I want, and it would take a lot of time to get it back that way.

    Please help!

  47. ivo

    the correct command is setup (hd 0) and not (hd 1)

  48. @wine

    Thanks guys (geeks), I have a similar problem thought not yet fixed, I now have an assurence that I will be able to solve it using the ubuntu liveCD. “The blue screen of death winXP”

  49. jyesj

    no doubt it recover my my linux grub boot loader but when i press ubuntu 7.10, kernel… on the second screen it gives
    “Error 17; cannot mount selected partition
    press any key to continue….”
    when i press any key it return to previous menue.

  50. James

    Took me ages Googling for this forum again, as I forgot the site. A few minutes after I made my last post I read the one above mine and tried that. It worked. Thank you very much ivo. :) I am about to reinstall Windows (again), and am going to print this off.

  51. Fozz

    My hero! Due to some weird error (possibly my hard drive on its last legs) I couldnt start any live cds with 8.10 kernel, but managed to get an old live cd working. I couldnt get it to “setup (hd0)” for some reason but eventually after lots of fiddling it gave a positive respone and everything worked! My hero!

  52. Ruchir Joshi

    i tried the set of commands to be written to menu.lst file but the system is unable to save it. can anybody site a reason?

  53. jyesj

    Dear can anyone help me i have dual boot windows xp and ubuntu 7.01 gusty gibbon. I was installing aMSN messenger and i downloaded and make install several missing libraries farsight2 etc. but still it was giving error that no farsight etc. anyway now b/c of these attempts of installing new libs. my ubuntu has stopped booting while i can still boot xp with no problem. Can anyone help me how to solve this issue i have tried Live CD but was insatlling a fresh ubuntu. it means that i will loose my ubuntu and may be my xp will not boot. please suggest what to do.

  54. Rhi

    Thanks!! Very helpful.

  55. Ash

    After installing windows ,Grub is showing options for windows and linux.But linux loads fine ,windows just comes to grub>. Please suggest me

  56. jyesj

    Dear can anyone help me i have dual boot windows xp and ubuntu 7.01 gusty gibbon. I was installing aMSN messenger and i downloaded and make install several missing libraries farsight2 etc. but still it was giving error that no farsight etc. anyway now b/c of these attempts of installing new libs. my ubuntu has stopped booting while i can still boot xp with no problem. Can anyone help me how to solve this issue i have tried Live CD but was insatlling a fresh ubuntu. it means that i will loose my ubuntu and may be my xp will not boot. please suggest what to do.

    Can anyone help me out there???????????????????

  57. ivo

    If you install a new release of Ubunti ie 8.10, you don’t loose Windovs xp and old configuration of gutsy 7.01
    I use aMSN and i have installed with synaptic, I haven’t download the tarball or .deb
    try to enable all repository …

  58. jyesj

    Dear ivo
    you have not mentioned that do i have to fresh install. the new version 8.10. one more thing please read my post again and see if new install will fix the problem. I am unable to boot into ubuntu anymore. it shows the boot menu and and i can boot into xp and works fine but when i select ubuntu the black screen appears and nothing happens even after 5 to 10 minutes. how can i boot into ubuntu again.
    waiting for you reply

  59. jim
  60. ron

    Exellent!, pretty easy and works as describe with M$ Crappy XP and Ubuntu 8.10

  61. ivo

    if you want there’s a program called SuperGrub
    You start superGrub in Windows and reboot your pc
    during the first start up you see a dos screen and SuperGrug make for you a configuration of dual-boot
    may be the this software make for you a correct configuration
    good luck
    but IMHO you must reinstall ubuntu: you have problems with start up, not in the boot menù …..

  62. Ben

    As others have said, totally saved my butt. Was reinstalling XP and it would go through all the steps and then have a bad partition setup. It was actually repeatedly installing install files before I realized it was taking too long even for Windows.

    Also, I ended up needing the find /boot/grub/stage1 which gave me hd(0,5) so I ran root from there, and did hd(0).

    Again, huge help, since some other solutions out there are insane.

  63. Ekim

    I’m da new new kid to linux… was a “POBG” (Prisoner of Bill Gates). First off…..WOW! Linux is KING. Burnt 10 Ubuntu 8.10 cd’s and gave them all away. Next I found out some of my programs on Win-Poo won’t work on Linux. After fighting the Grub thing I wiped out the hard drive, reloaded WinPoo and shut off all the internet stuff, removed almost everything from Xpee and only use WinPoo for making CD Covers….for more Intrepid Ibex Live CD’s. Hope this makes bill’s day.
    There ain’t no good reason to Keep WinPoo stuff on the HD anymore…..

  64. JimmoSabe

    I’ve come across this article because I reinstalled winxp after I had a working dualboot (Ubuntu/XP) config that the new win install screwed up. I did everything as indicated here, but it didn’t work for me. What I did instead was going to and I did the following:

    1. Boot the Desktop/Live CD. (Use Ubuntu 8.04 or later)

    2. Open a terminal (Applications -> Accessories -> Terminal)

    3. Start grub as root with the following command :

    sudo grub

    on the grub prompt, I typed ” find /grub/stage1 ” (without the quotes, of course ;) ) and the result was the correct place of my grub menu. (hd0,5 in my case). Then I did

    root (hd0,5)

    , then

    setup (hd0) then TO EXIT GRUB I did


    And now I got my GRUB MENU like it was before! ;)

    Hope it could be useful to you!

  65. ss

    “find /boot/grub/stage1″

    Thanks for that i highly suggest the editor of the blog adds that line !

  66. Samira

    Hi everyone

    i had the same problem after reinstalling the windows

    i tried the following, but it didnt work …

    grub> find /boot/grub/stage1
    grub> root (hd0,5)
    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,5)/boot/grub/stage2
    /boot/grub/menu.lst”… failed
    Error 12: Invalid device requested

    how can i solve this?
    (not i had ubuntu 6 installed & i entered the live CD of ubuntu 9.4)

  67. Ben2talk

    Then install ubuntu 9.04 – you can’t use Ubuntu 9.04 to fix ubuntu 6! That’s funny!

  68. hinczas

    Thanks for help. You could also try this: Run ubuntu from LiveCD. When its ready go to System>Administration>Partition Editor and set flag “boot” for partition with ubuntu. It worked for me.

  69. loganathan


    I have installed first fedora and next windows xp. after that i deleted the linux partition from my hard dist using control panel disk management. after i restart the system is didn’t boot in windows.
    its showing the command promt grub>..

    How to make my system to boot in windows..

  70. prithvi

    hey thanks guys. it worked for me… and to quote “You had to do your monthly reinstall of Windows”
    i like the phrase monthly install of windows… heh heh

  71. bastr

    i see other way >>>
    sudo fdisk -l
    sudo mount /dev/hda2 /mnt
    sudo grub-install –root-directory=/mnt /hda

    hint: hda2 mean where linux install
    thank you :)

  72. John

    This work perfectly. I had Ubuntu 9.05 and Windows XP Pro working in dual boot when I decided to complicate things by installing the Windows 7 Release Candidate. Of course Windows assumed it was the only OS on the drive and schwanked grub.

    I read the entire thread including helpful comments, found the windows partitions on my drive and was up and running in a few minutes. I was unable to find /boot/grub/menu.lst to make sure windows was in it. So I took a chance and rebooted without this step. Grub showed windows 7 as XP, but that is a minor detail I can fix easily.

    Thanks for the help!

  73. Venus

    Thanks Mr.”Jonathan vz”…Mine was “hd(0,5)”..i did never expected it’ll be upto 5..And i struck for about 20 minutes by just a small mistake, i didn’t give space after the “find” !!!…

  74. shan

    ok my situation here is i have ubuntu 9.04 installed (no partition) and i want to reinstall XP so i can run cubase

    but my xp backup disk is not being accepted by the computer

    i think full ubuntu install precludes that

    any suggestions?

    ta shan

  75. samg

    Here’s a link to Ubuntu community discussion which may help you out.

  76. rhy

    Yah it works but if you are sure what number of (hd) “heard disk” you installed windows Xp or Vista.

    type in this command:

    first – sudo grub

    second – root (hd0,0) # the number of your heard disk #

    third – setup (hd0,1) # frot he boot start up #

  77. mjt

    The *best* solution for restoring the MBR after a Windows install
    is to backup the MBR *before* the Windows install. The tried and
    true method is to use the “dd” command on the Linux side. I’ve
    been doing this for years – saving the binary file to my gmail acct.

    To backup the MBR, jump to a CLI and:
    # dd if=/dev/hda of=mbr.bin bs=512 count=1

    The result is a file (in this example), “mbr.bin” – save that off to
    a safe place …. its size is 512 bytes. Ensure you have a Live CD
    or original Linux install CD at hand. Also, the device name path
    for the hard drive will need to be adjusted – for example, you might
    have to specify “if=/dev/sda” instead of “hda”.

    Do the Windows install – then to restore your saved binary image,
    simply boot your Live CD or Linux install CD, jump to a CLI and:

    # dd of=/dev/hda if=mbr.bin bs=512 count=1

    Be sure you specify the fully-qualified path to “mbr.bin”

    mjt – author, “Inside Linux”.

  78. mjt

    I failed to mention that if you ONLY want to restore the MBR itself,
    then the “dd” command should be:

    # dd of=/dev/hda if=mbr.bin bs=446 count=1

    If you execute “dd” as I explained in my previous post, the
    partition table will be restored, in addition to the MBR. So,
    if you’ve done any partitioning during the Windows install,
    you’ll *not* want to execute “dd” as in:

    # dd of=/dev/hda if=mbr.bin bs=512 count=1

    I always recommend doing the partitioning in Linux BEFORE
    you install Windows.

    mjt – author, “Inside Linux”.

  79. gal

    Works like a charm. i’m with opensuse and windows kept overwriting my MBR. thanks a lot

  80. md imran

    I have installed Ubuntu 9.04 as windows application long back using wubi.
    Now when i restart my PC its giving the menu to select either windows or ubuntu.But when i cliked on ubuntu its giving the following error “Cannot find GRLDR”. Please tell me how to get out of this issue.Atleast how to get the ubuntu data backup.

    when i tried
    sudo grub
    find /boot/grub/stage1 its saying no file found.

    Since Ubuntu is not installed in separate external partition i am unable to get the backup..

  81. Neo

    Hi all,
    I earlier installed ubuntu 9.04. I am trying to install grub after XP.But i get following error

    grub> find /boot/grub/stage1

    grub> root (hd0,5)
    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,5)/boot/grub/stage2
    /boot/grub/menu.lst”… failed

    Error 12: Invalid device requested

    I get this error.
    I am using live cd of Ubuntu 9.04 same version dat i have installed

    Please help

  82. Jack

    When i insert the livecd and run sudo grub it says no grub installed.what should i do?

  83. Waldo-LLC

    If you look @ the latest Ubuntu help, you will find that as of KK, GRUB has been changed considerably. These instructions only apply now to JJ or earlier!

  84. Jasonv

    when I used the command fdisk -l it said it cannot open /dev/sda, and when I tried find /boot/grub/stage1 it said No such file or directory. I’m using ubuntu 8.1 boot cd if it matters.

  85. Travis G

    Thanks a bunch!

    I’ve had to deal with GRUB errors several times, and this is a perfect explanation. Your simple fix kept me from panicking when my computer suddenly wouldn’t boot!

    Another disaster avoided…

  86. Tuan N

    I have Ubuntu 9.05 in Toshiba netbook with 160GB HD. Repartition to 60GB and then install Windows 7 starter to second partition. I can’t mount sda1 that has Ubuntu, wrong FS, Gparted listed sda1 as ext4. Using find /boot/grub/stage1 and got an error 15: file not found. Since It can’t find where is stage1, I can’t reinstall grub.

    Anyone knows where is it located or how to fix this problem? Thanks in advance.

  87. QuAz@r

    Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out

    Hi i am using Ubuntu 9.10 which was installed on a partition of the main c drive and i formatted my windows partition which conatined the the grub loader for ubuntu 9.10 how can i fix this using a ubuntu 9.10 live cd? :
    I have booted from the ubuntu 9.10 cd opened a terminal and typed and tried using sudo grub and the result was : ubuntu@ubuntu:~$ sudo grub
    sudo: grub: command not found

  88. Jim

    I have encountered for the second time now that the Windows XP has gone missing from the boot menu.
    The first time I formatted the Ubuntu partition and reinstalled Ubuntu 9.1 and windows was back in the boot menu. Is there a better way than reinstalling Ubuntu? Ubuntu is booting normal but I still need XP to run a few aps that will not run in Ubuntu. I need a simple way to restore Windows XP Pro to the boot menu.


  89. Mokunen

    Thanks a lot! This has been of great help several times. However, the EXIT command doesn’t work for me, I have to use QUIT instead.

    I really hate how windows wipes out my grub loader every now and then. Today, for example, I was cleaning (i.e., formatting) the virus-filled HD of an acquaintance of mine, and I had it plugged along with my main hard drive. I put in the windows install CD, and it didn’t even have to LOOK at my main drive, just format and install on the other one, yet IT STILL BUSTED MY GRUB! WTF, Gates, do you really hate Linux THAT much that you murder its loader on sight? XD

  90. Pavel

    the trouble is that the default configuration of grub does not have the menu.lst anymore… :-(
    so if ubuntu was first, then came windows xp that installed its own boot loader to mbr,
    then we are stuck. grub is not able to load windows after it gets back to mbr…

  91. Parit

    Thank you so much. Your advice just works. I wonder if my Ubuntu was not 8.04 but the later versions, it may not work however.

  92. Pedja

    I had a strange experience with loaders on a dual boot machine (Fedora 13 / WinXP). Fedora is installed as primary OS (first two partitions on laptop hard drive) and WinXP as a secondary (third partition). I had some unallocated space at the end of the disk so I decided to create a partition with FAT32 file system to make file transfer between Fedora and XP easier. So, I did it from WinXP, since I was working with it at the moment. After I restarted the system – BOOM! Grub Error. Tried to reinstall grub, no success. After a day of work, I finally found the answer: WinXP disk manager changed the partition distribution in such a way that it inserted some unallocated space at the beginning of the disk (approximately 1MB of space ?!) and changed the MBR accordingly. However, grub recognized it but it treated it as a partition (hd0,0) and changed the root partition to (hd0,1). Since there was no system there (it was a second Linux partition, for OS), I received another GRUB error. After I manually changed it back to (hd0,0), Fedora booted as usual. On the other hand, WinXP could not boot up because in its boot.ini file the loader was directed to the wrong partition – it treated the unallocated space at the beginning of the disk as non-partition. After I increased the partition number in boot.ini, WinXP can boot normally.
    Obviously, the problem arose after creating an unallocated space at the beginning of the disk drive. Could it be your problem too? Because it is, then there is something really bad with boot loaders – either WinXp or GRUB. Fixing manually partition numbers solved the problem, but the problem should’t have been there at all. I still can’t understand why reinstalled grub didn’t recognize correctly the partition table or how WinXP could change the disk space without distroying the data (or maybe it did, and caused all other problems).

  93. CrazyHobo97

    Hello, thanks for the help who ever wrote the original article and Jonathan van Zuijlekom

    together this is what worked for me

    sudo grub

    >find /boot/grub/stage1

    > root (hd0,0)

    > setup (hd0)

    > exit

    after i typed >find /boot/grub/stage1 I got (hd0,4) put that in to the root and it worked great. now the exit did not work but that’s minor terminal is not really my field… so thanks again

  94. Allen

    I more often have problems with linux overwriting my windows boot loader and completely borking my Windows install.
    When will linux devs put on the big boy pants and lose the command line crap?

  95. kern

    I’ve managed to fix this problem with the steps from bastr.

    I have both Ubuntu 10.04 and Windows 7 on my laptop.

    Here are the steps:

    #1 – Boot off the Live CD

    #2 – Open a terminal

    #3 – Mount the partition where you’ve installed Ubuntu. You can check it with sudo fdisk -l

    sudo mkdir /mnt/linux
    sudo mount /dev/hdXY /mnt/linux

    #4 – Run grub-install

    sudo grub-install –root-directory=/mnt/linux /dev/hdX

    Thats it!


  96. Dennis Baines

    Hi y’all
    Please HELP, Recently I downloaded a file a keygen generator and after that my internet browser started to cut out and shutting down so I decided to restart my PC, when it came back up it went into grub4dos 0.4.4 2009.09.09
    Everything I do it shows Error 17 and so on, if I press the esc key a red screen appears with a Menu and there’s one saying Windows without Loader.
    My OS is Windows 7 but original OS for the machine is XP.
    Please how do I exit this grub4dos 0.4.4 without losing my data. Please HELP

    Thanks in advance.

  97. gruj

    it didnt work, even when i tried sudo grub , it couldn’t find it, so then it prompted me if i wanted to install grub, so i did, then the grub bootloader still didnt work, but this time i could go into
    sudo grub , after though it said ‘cannot mount selected partition’, after i tried the root and setup commands, then another website told me to do the
    find /boot/grub/stage1 command, but it said file not found, im starting to wonder if i never had and never will have grub on my PC, if someone could please help me with my problem, that would be much appreciated

  98. Cyano

    I just installed a new hard drive and Windows 7 on my computer (which already has Fedora 13 and Windows Vista on the original hard drive).
    When I entered
    >find /boot/grub/stage1
    it didn’t find the file, but I looked in my menu.lst file to get the hd?,? (my grub menu entry for fedora 13 had the line “root (hd0,1)”. So I ran (from the live cd):
    >root (hd0,1)
    >setup (hd0)
    And it worked. Furthermore, I noticed when I ran the setup command that the file stage1 was found at /grub/stage1 and not /boot/grub/stage1 (fortunately, the setup command automatically tries multiple locations).

    So in summary, stage1 might not be in /boot/grub/ but rather some other variation such as /grub/

  99. Paul

    Had to do something a little different when you have hardware raid (two drive mirror). I have Windows installed on hd0,0 and Ubuntu installed on hd0,1. I then added a harddrive and created a mirror and upgraded Windows Vista to Windows 7. Grub got dropped as per this article. But once you have a hardware mirror you need to run setup on both hard drives or it does not seem to work. Here is what I did to get it to work:

    with the Live CD Ubuntu

    sudo grub
    grub> find /boot/grub/stage1
    grub> root (hd0,1)
    grub> setup (hd0)
    grub> root (hd1,1)
    grub> setup (hd1)
    grub> root (hd0,1)
    grub> quit
    sudo poweroff

    Thanks for the article.

  100. Rahul Katare

    I installed Ubuntu under windows. My Windows is in C drive and I had installed ubuntu under Windows in E drive. I was working in Ubuntu when I downloaded some updates which asked Restarting ubuntu.
    When I restarted it, the following screen came
    error: “some weird text was written”
    grub rescue>

    I followed the instruction from this forum, by booting from a live CD but when in terminal I typed
    sudo grub
    it says invalid command

    Please help me!!!

  101. Giuseppe

    So, I have, linux and windows both installed on my laptop…i’ve gone through a lot of OS’s and as such have a lot of random partitions…after running the grub stage command I found out that my grub is installed on HD0,5 …if i’m correct is this why im’ getting an error for “hal.dll” when trying to load windows from grub? if this is the case, how can I fix it? Thanks a bunch.

  102. Undergerad

    Hi all, please help… I’m dualbooting like everyone else here Windows 7 Ubuntu 9.04. I install windows 7 first, create an extended partition…etc for ubuntu. I restart my machine select windows Vista(loader) from grub menu and my computer instantly reboots. I then repair windows mbr bootrec /fixmbr, which gets windows 7 working, though I don’t get a boot menu..ok no prob, I then follow the instructions on here after using ubuntu live cd:

    sudo -s


    find /boot/grub/stage1 this gives me hd(0,4) ok

    root (hd0, 4)
    setup (hd0)


    reboot and can see windows in the menu select it and my computer still reboots, I can load ubuntu no problem, I gave up partitioning my self and let ubuntu install side by side with windows and still no go, I’ve reinstalled and had to fix mbr like 20 times and still the same issues. Windows now boots from sda/dev2 boot flag set instead of sda/dev1, which i didn’t want.

    Here was my setup

    100 MB windows system reserved sda/dev
    80 Gb NTFS windows 7 sda/dev1
    60GB NTFS storage sda/dev2

    Extended partition
    root mount /
    home /home

    After many tries manually it is now:

    100MB System reserved windows don’t think this is being used boot flag no longer set
    120 GB NTFS windows 7
    ubuntu takes up remaining space with swap at the end…. which I don’t want but will suffice until I can figure out how to get windows to boot in grub.

    If anyone has any advice please help every forum posts the same stuff and none of it seems to work including the post above.

    Also is there a way to get windows to use the system reserved 100MB space again for booting, with out reinstalling windows?


  103. Undergrad

    Ok I’ve fixed the windows partitions with system reserved as active and boot, and resized. Did this with partition wizard (great program)!

    Still haveing issues with the dual boot though as stated in my last post…

  104. Marcio

    Awsome, worked perfectly. Thank you.

  105. yu76uu

    Hi, Thank you for this short way, I installed win7 after ubuntu 9.04, then ubuntu boot menu disappared so I make like this way and it worked very well. Thank u for all.

  106. mhenriday

    Would it be too much to request that this article be updated to reflect the change from the legacy GRUB to GRUB2 and the possibility of booting UBUNTU from a live USB flash drive using, eg Unetbootin ? I’d like to install 64-bit Win7 over 32-bit Vista on one harddisk on a dualboot laptop with two harddisks, the other of which has 64-bit Ubuntu 10.10 installed, but I’d very much like to avoid having to do a fresh installation of Ubuntu in the event I can’t get GRUB2 to behave….

    Thanks in advance !


  107. ash

    it showed “command not found” on terminal when i tried “sudo grub”

  108. Abellac

    Hi, i found this very interesting. I have partioned my windows 7 and have since only been able to boot it using Grub above and when i try to fix the mbr it complains that i dont have a primary partion. Can i make the grub permanent for booting my computer so that i will not need the USB disk every time i boot my computer. If there is an alternative way of bringing the normal windows boot back to normal i will also appreciate.

  109. avi didn’t work for me….
    let me tell u my problem..
    i have window 7 installed in my pc…
    after it i installed redhat on creating custom layout..on a hard drive .. mounting root on new option..
    and after it when i open windows that particular drive is shown missing on it..i do it again and again one drive get lost…..
    i’m too much in trouble…anyone who know the solution plz help me.
    waiting for your reply…
    thanking you…..nd u make a wonderful site.

  110. Nav

    when I tries running this command

    grub> find /boot/grub/stage1

    I get the following error :-

    error: unknown command ‘find’

    Please help

  111. Danny

    This saved my can. Worked like a charm.

  112. virupaksha


    [ 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. ]

    grub> root (hd0,0)

    grub> setup (hd0,1)

    Error 17: Cannot mount selected partition


More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!