Windows 7 upgrade and fixing Grub afterward.

It’s been a while since I posted anything on this site, partially due to the run-up to my recent wedding, and partially because I’ve been too busy with work and my new job to really do anything with my computer lab at home.

The wedding is now over, and the honeymoon taken, so it’s time to get back to work.  Part of that means getting back to work on my blogs and other things that have languished in the past few months as my attention has been directed elsewhere.

As part of that, last night I decided to take the plunge and upgrade the windows drive on my home office workstation from an aging Windows XP installation to the Windows 7 RC.

Since there’s no real upgrade path from XP to Windows 7,  and since I really had no desire to KEEP Windows XP,  I decided to reformat the XP drive and do a fresh install.

The installer was inexplicably slow,   especially since it was running on a Intel Core 2 Quad with 4 gigs of ram – certainly a beefy enough system to run it, and fast.  It took several minutes to get to a point where I could even start the install, and then the installer would hang at some points for absurd amounts of time spinning it’s wheels and appearing to do nothing ( it may be that it was processing in the background, but it honestly gave no indication that it was doing so).

After reading online that some people have had absurdly long install times (measured in hours) I got worried.    Especially since they indicated that after the install finished Windows failed to even start.    Thankfully, after the install completed Windows started just fine and everything seems to be working without any issues.  It would appear Microsoft needs to polish the installation a little bit more, but they’ve got some time to do that before the general release in October.

For me, the next (and last) gotcha was that this was  a dual boot windows/linux system,  and now the Grub bootloader stopped working.

This wasn’t a surprise to me – I actually expected it.   Typically, when you install a dual boot system you want to install windows first, THEN install Linux.   That’s not always feasible though, as seen in my case where I was upgrading to a new version of Windows.     Once you install windows, the bootloader no longer shows up and you can’t boot into Linux.

All is not lost!   The reason this happens is because Windows inserts it’s bootloader into the Master Boot Record (MBR), and set’s it as the priority after POST,  so instead of GRUB (or LILO, etc) loading first, the Windows bootloader does – and it doesn’t know about (or care about) Linux.

Luckily, this is ridiculously easy to fix.

The first thing you need to do is find a Linux Live CD,    in my case since I’m running Ubuntu 9.04 x64, I downloaded an ISO of the Install CD from Ubuntu.  Burn the ISO to cd, and boot to it.

Once you’re booted into the Live CD, open a terminal and type the following:

Sudo grub

This launches the grub prompt, and you should see “grub>” on your screen.   Once you see “grub>” , enter the following commands, pressing enter after each command.

Find /boot/grub/stage1

root (hd#,#)

setup (hd0)

quit

In the above commands,  the first one will tell you the location of the stage1 file that Grub needs to determine where all of it’s files are.   It will return a location in the format of something like (hd0,1) use that value that it returns in the second command.   Continuing my example that would be root (hd0,1).

The second command tells grub that it’s files  are on a particular partition of a particular drive (in the example it’s partition 1 of drive 0).

The third command tells grub to set itself up on hd0, and when given without a value for partition grub then installs itself on the MBR.  hd0 is the label grub uses for the first drive’s MBR.

Quit is self explanatory :-)

After you’ve finished that you can reboot the computer, remove the live cd and enjoy a working grub bootloader.

Popularity: 65% [?]

Related Posts

7 Comment(s)

  1. Hey great post.

    I’ve installed Win 7 on my pc with two other partitions running ubuntu linux and win vista.

    After the Win 7 installation everything seems to be correctly working. I reconfigured grub and after that win 7 isn’t booting any more. the other systems working fine, but win 7 only says “starting up” and nothing happends.

    Do you have any ideas what could be wrong with it?

    Thomas | Jun 10, 2009 | Reply

  2. Thomas,

    I’m not sure what the culprit could be on this. It sounds like Grub installed alright, and you’ve got the grub entries setup if it’s actually starting to boot into Windows 7.

    if you want, copy and paste your menu.lst file into an email to john -at – youwillgetavirus.com and I’ll see if anything stands out to me.

    john | Jun 10, 2009 | Reply

  3. windows 7
    Hi read the post got the same problem install ubantu now i cant get rid of the boot crap, followed you tips but when i get to Setup (hdo) it says `cannot mount selected partition`.any thoughts! or will i have to format to get rid of it, also ran the recovery off windows install cd no luck on that to.

    Paul | Jul 8, 2009 | Reply

  4. Paul,

    the command is setup (hd0) (as in zero), not (hdo) that may be your issue. The font on this site makes it difficult to distinguish between the two – I apologize.

    john | Jul 8, 2009 | Reply

  5. Thanks for this. It worked for me dual booting win7 & 9.04. Although in Grub windows still says “vista”, but that is easy to fix.

    For me though, I would get an “unknown command” msg if I used a upper case letter in the first word as shown in the commands. Just thought I would mention that in case other newbs like me try this.

    Graham | Aug 28, 2009 | Reply

  6. I tried to follow your instructions. got into grub, used find /boot/grub/stage1 and got (hd0,4)
    then tried to run root(hd0,4) and got “Error 27: Unrecognized command). Any idea’s?

    Brandon | Nov 8, 2009 | Reply

  7. Hi Brandon,

    Your problem is most likely that you didn’t include a space in the command root (hd#,#). In your comment you had root(hd#,#) which would very likely throw an error that it didn’t know what you were trying to do.

    Your commands would be:

    root (hd0,4)
    setup (hd0)

    john | Mar 29, 2010 | Reply

1 Trackback(s)

  1. Aug 10, 2009: from [Ubuntu] grub2

Post a Comment