Restore Grub 2.0 after Windows 7 Install (Ubuntu 11.04, 10.10, 10.04 or 9.10)

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 3.40 out of 5)
Loading ... Loading ...

I had Ubuntu 9.10 (this approach works for 10.04 Lucid and 10.10 Maverick, 11.04 Natty as well) already installed on a machine and wanted to dual boot it with Windows 7. Dual booting Ubuntu with Windows 7 already installed is easy, as described here. The reverse of it, i.e. creating dual boot Windows 7 with Ubuntu already installed is not that difficult either. You start by first resizing your Ubuntu partition, then create a Windows NTFS partition. You can do so using an Ubuntu Live CD or a Gparted Live CD. Then boot with Windows 7 DVD and install it. The problem is that the Grub would be gone and you won’t be able to boot into Ubuntu anymore.

This post discusses the easy way of restoring Grub2 using Ubuntu Live CD. First, boot with the Ubuntu Live CD. Now mount the partition, which has Ubuntu installed on it. If you had a separate partition for /boot, then you would have to mount that too. Mounting the partitions is super easy. Just go to Places in the top Gnome menu and try browsing to your corresponding partition by clicking on it. It would automatically get mounted and open in nautilus.

Now just run the following command to install Grub2 in the Master Boot Record (MBR) of your first booting hard drive.

sudo grub-setup -d /media/XXXXX/boot/grub -m /media/YYYYY/boot/grub/device.map /dev/sda

Where XXXXX represents the name or UUID of the partition that you have mounted. If your /boot partition is separate from your / partition then YYYYY above would be different from XXXXX, else both of them would be identical. The command above assumes that /dev/sda is your primary or first device in hard disk boot order. If not then replace it with /dev/sdb or sd_ fill the blank with appropriate letter.

If you don’t have a device.map file, you should try this way (thanks cibonato for pointing this out):

sudo grub-setup -d /media/XXXXX/boot/grub ‘(hdx)’

Where x is the letter corresponding to the hard drive number-1, for example if you want to install grub on first physical hard disk (we are not talking about partitions), then x = 0. For second drive it would be hd1.

After you have run the command, reboot and you should be able to boot in Ubuntu but not in Windows, to fix it run the following command in a terminal and Grub boot list would be updated to include Windows in it. Also if you want to change boot order read this.

sudo update-grub

Now reboot and you should have the choice to boot in both Windows and Ubuntu. For more information about Grub2 setup see this.

If you found this useful, please consider leaving a comment or liking us on Facebook or following us on Twitter or subscribing to the RSS feed to have future articles delivered to your feed reader.

You might also like

Install Gnome3 / Gnome Shell on ubuntu 11.04 (Natty)/Ubuntu 10.10 (Maverick) While Gnome3...
Install VirtualBox Guest Additions in Ubuntu 11.04 Natty Guest VirtualBox...
Ubuntu 11.04 Natty Narwhal (Alpha 1) Preview It is going...
Change Default Boot Order for Grub in Ubuntu 10.10 Maverick Meerkat Command-line...

About the Author

has written 1285 posts on this blog.

Meditating towards his "nerdvana", lifehacker is a teacher by the day and a nerdy blogger by the night. He lives to learn and yearns to learn living.

10 Comments on “Restore Grub 2.0 after Windows 7 Install (Ubuntu 11.04, 10.10, 10.04 or 9.10)”

  • Tobias Gies wrote on 14 July, 2010, 9:31

    Thanks for the guide! I just had to reinstall Windows 7 and couldn’t get to Ubuntu any more. Your post put me back on track. Thanks again!

    Like or Dislike: Thumb up 1 Thumb down 0

    [Reply]

  • Fatman wrote on 17 September, 2010, 8:54

    I don’t have a device.map file. What do I do?

    Like or Dislike: Thumb up 2 Thumb down 0

    [Reply]

  • Ubuntufreak wrote on 17 September, 2010, 10:21

    @Fatman
    Which version of Ubuntu are you using?

    Like or Dislike: Thumb up 0 Thumb down 2

    [Reply]

  • Fatman wrote on 20 September, 2010, 8:39

    Well, hard to say… I suppose technically it’s Lucid, but it’s been upgraded one version at a time all the way from Gutsy so it’s picked up all kinds of cruft along the way. I’m surprised it hasn’t picked up a device.map, actually.

    $ uname -a
    Linux hostname 2.6.32-24-generic #42-Ubuntu SMP Fri Aug 20 14:24:04 UTC 2010 i686 GNU/Linux
    $ lsb_release -a
    LSB Version: core-2.0-ia32:core-2.0-noarch:core-3.0-ia32:core-3.0-noarch:core-3.1-ia32:core-3.1-noarch:core-3.2-ia32:core-3.2-noarch:core-4.0-ia32:core-4.0-noarch
    Distributor ID: Ubuntu
    Description: Ubuntu 10.04.1 LTS
    Release: 10.04
    Codename: lucid

    Like or Dislike: Thumb up 0 Thumb down 0

    [Reply]

  • Ubuntufreak wrote on 20 September, 2010, 11:57

    @Fatman – Hmmm, very strange. Were you able to find a fix for your issue. I would love to know the fix, how are you booting to Ubuntu now?

    Like or Dislike: Thumb up 1 Thumb down 0

    [Reply]

  • Art wrote on 16 April, 2011, 23:06

    Nice job after all the forums i’ve been searching for days this is by far the most accurate and easiest way to do this and it worked for me in one try
    thanks again for taking your time and helping others

    Like or Dislike: Thumb up 1 Thumb down 0

    [Reply]

    lifehacker Reply:

    @Art, You are most welcome. I’m glad that you found it useful.

    Like or Dislike: Thumb up 0 Thumb down 0

    [Reply]

  • cibonato wrote on 1 May, 2011, 11:42

    If you don’t have a device.map file, you should try this way:

    sudo grub-setup -d /media/XXXXX/boot/grub ‘(hd0)’

    I have Ubuntu 10.04 installed and also do not have this file, but I could check the content of this file in another computer and it is just a line mapping /dev/sda to (hd0). That’s because I tried ‘(hd0)’ (I read the manfile and the device should be between ‘ ‘ – don’t forget that).

    After running this command, everything is working again.

    Greetings

    Like or Dislike: Thumb up 1 Thumb down 0

    [Reply]

  • rajesh wrote on 29 September, 2011, 11:02

    thanks for the simple and nice tutorial.

    Like or Dislike: Thumb up 0 Thumb down 0

    [Reply]

Trackbacks

  1. Dual Boot Windows 7 and Ubuntu 10.04 Lucid Lynx | Hack Your Life!

Write a Comment

Gravatars are small images that can show your personality. You can get your gravatar for free today!

*

Copyright © 2014 Hack Your Life!. All rights reserved.
Proudly powered by WordPress. Developed by Deluxe Themes