Search This Blog

Monday, 6 February 2012

Windows Killed my MBR

Having recently acquired a SSD and some more geebees I re-installed Ubuntu x64.  The SSD already had a OEM Windows partition and I (foolishly) decided to just resize it 50/50 and put Linux on the back end.  With a mind to come back and build the Windows OS as a dual boot.

Well this morning I went back, built the Windows OS and then fried my GRUB boot loader.  Bye bye Ubuntu, insert sad face.

Recovering it wasn't so bad although as usual there is LOTS of conflicting documents and ways to get yourself out of this mess.  This method worked for me :
  • Boot Ubuntu DVD in live mode.
  • Jump into a terminal and switch to sudo -i and run parted -l to establish which partition you need to rebuild the MBR for.
~$ parted -l
Model: ATA SAMSUNG SSD PM83 (scsi)
Disk /dev/sda: 128GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type      File system     Flags
 1      1049kB  106MB   105MB   primary   ntfs            boot
 2      106MB   45.1GB  45.0GB  primary   ntfs
 3      45.1GB  128GB   82.9GB  extended
 5      45.1GB  120GB   74.4GB  logical   ext4  <---- Ubuntu Install
 6      120GB   128GB   8453MB  logical   linux-swap(v1)

  • mount the partition 
mount /dev/<partition> /destination
eg : mount /dev/sda5 /media/sda5

  • run 
grub-install --root-directory=<mount> <disk>
eg : grub-install --root-directory=/media/sda5 /dev/sda 
Assuming you get a success message your good to go.  Reboot and you should have Linux back and in my case Windows 7 also now existed on the GRUB loader.

Caveat : The first time I tried to boot Windows it complained of a missing loaded.  The second time it worked fine .. I never got to the bottom of that.

Moral of this story is install Windows first and Ubuntu second.  Ubuntu is a clever OS and Windows is not.