31 August 2010

Windows overwrote GRUB, and how to fix it

I don't use Windows much, and when I did, Windows 7 wanted to update a billion things (since I haven't used it for months).  Fine, but why does it have to brick my computer?  It overwrote GRUB on the MBR, so now it won't show the menu for picking which OS you want to start up in.  Now I can't boot up in Windows 7 or in Ubuntu 10.04.  How to fix it now?

The basic strategy is to boot up Ubuntu on an external disk, run some simple simple simple command line commands, and it's fixed.

The trouble is that it's my Dell Mini 10 netbook, and I don't have a DVD drive to boot from.  This means the first step is to build a bootable flash drive, and then fix GRUB.  Here's how:


First, don't do this from a Mac — I've tried, but as per my experience last time, when I first installed Ubuntu to dual-boot the new netbook, Macs just won't do the job.  I even tried different flash drives, SD cards, and even my iPod, and it just won't do.

So my recommendation is to find yourself a Windows computer and then do the following:
  1. Download Ubuntu UNR (version 10.04 currently)
  2. Download UNetbootin
  3. Use UNetbootin to write the Ubuntu UNR iso image to the flash drive or SD card (I used an SD card since the Dell Mini has a card slot)
Once that's done, you can boot up your netbook from the boot-able flash drive or SD card.  Do that, and then we'll fix GRUB by following these complicated instructions here RecoveringUbuntuAfterInstallingWindows, which are rather hard to parse through, so I'll summarize it for you by assuming a few things.

Assuming you're running Ubuntu Linux 10.04 UNR and it was up-to-date with the latest upgrades, then you should have Grub2 installed.  If you don't have Grub2, go read the complicated instructions instead.  But if you do have Grub2 because you've kept your Ubuntu install up-to-date, then just do the following:
  1. mount the partition on which you installed Ubuntu. You can do this by double clicking on the appropriate partition from, eg, Nautilus. 
  2. open a terminal
  3. in terminal, do mount | tail -1 (note that's a "dash one").  You should see something like this:

    /dev/sda2 on /media/0d104aff-ec8c-44c8-b811-92b993823444 type ext4 (rw,nosuid,nodev,uhelper=devkit)

    Note down the /dev/sda part (the number doesn't matter).  Note also the /media/0d104aff-ec8c-44c8-b811-92b993823444 part.
  4. in terminal again, do

    sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda

    (Note that it's /dev/sda without the number, but of course substitute /dev/sda with whatever you noted from the previous step.)

    It should print this out if things went fine:

    Installation finished. No error reported.
  5. If things went fine, then restart the computer and all is fixed!  If things didn't go fine, I suggest you see the complicated instructions instead in case your computer is too old or whatever.
And that's it!

Of course, for me, after I fixed it, I booted into Windows to install some software only to find later that Windows overwrote grub AGAIN!  And I had to do the above instructions again...

No comments: