This post is a work in progress and you should only try this if you're adventurous! My goal is to enable anyone to restore any Linux or Windows MBR with any Ubuntu Live CD.
Although it's been around for a while now Grub 2 introduced the problem of users not being sure what version of grub they have installed and therefore just exactly how to restore Grub after the installation of Windows, or some other event, wipes out Grub. IMHO the best solution is to mount and chroot the Ubuntu (or Mint/other derivative) to first determine what version of Grub is installed and then to "recover" Grub while in the chroot so you're dealing with the grub packages installed in that OS. This eliminates the need of using a specific version of Ubuntu/Mint/derivative Live CD.
Of course the first thing to do is learn what partition Ubuntu is installed on, and also whether or not you have a separate "/boot" partition. This would also be an excellent time to describe drive and partition designations in Ubuntu:
Drives are designated as /dev/sda, /dev/sdb, /dev/sdc, etc. the last letter indicates the drive number, eg:
/dev/sda = drive #1
/dev/sdb = drive #2
/dev/sdc = drive #3
Partititions are designated with a number following the drive designations, eg:
/dev/sda1 = drive #1/partition #1
/dev/sda2 = drive #1/partition #2
/dev/sdb1 = drive #2/partition #1
In many cases you may be able to determine the Ubuntu partition simply by running "sudo fdisk -l" (BTW that's a lower case L), but if the partitioning scheme is at all complicated, or if you simply have any doubts, I recommend running the Boot Info Script.
The first two sections of the RESULTS.txt show what OS's bootloader is installed to the mbr of which drive and a list of all partitions including what OS is installed to what partition.
I should also add some general info about my "mount and chroot" procedure. It's not a true script but rather just a series of commands connected by "space&&space", so if one part of it fails the rest will fail! I strongly recommend that you copy-n-paste all commands. This is also intended only for determining the version of and restoring grub. For installing/removing packages, etc. more commands are needed!
This procedure is actually well explained here:
Particularly pay attention to what's said there about mounting and unmounting a separate "/boot" partition if used! My "script" does NOT include the commands for mounting and unmounting "/boot"!
So once you've determined what partition to mount simply boot any Ubuntu Live CD and, in Terminal, run:
Of course the X and Y need to be replaced by your proper drive and partition designations (the easiest way to do so is to "copy-n-paste" the command and then use the left and right arrow keys to edit).
sudo mount /dev/sdXY /mnt && sudo mount --bind /dev /mnt/dev && sudo mount --bind /proc /mnt/proc && sudo mount --bind /sys /mnt/sys && sudo chroot /mnt
To be certain you've mounted the proper partition/OS run:
If that appears to be right then check the installed version of Grub:
grub-install -v && aptitude show grub|head -2 && aptitude show grub-pc|head -2 && aptitude show grub-common|head -2 && aptitude show os-prober|head -2
You can see there that the grub version is "1.98-1ubuntu6" which is grub 2, basically "0.9*" = legacy grub, and "1.9*" = grub 2. As far as packages are concerned:
grub-install (GNU GRUB 1.98-1ubuntu6)
State: not installed
grub = legacy grub
grub-pc = grub 2
grub-common is shared by both legacy grub and grub 2
os-prober is particularly necessary for the proper function of grub 2
So, if that shows you have Grub 2, as in the example, installing it to the MBR of the proper drive is as simple as:
Should that produce any errors then:
Of course in both of those examples the X must be replaced with the proper DRIVE designation! I can't stress strongly enough that it's very seldom wise to install grub (particularly Grub 2) to a partition rather than the MBR of a drive!
grub-install --recheck /dev/sdX
I've also found that if any partitioning changes resulted in the loss of grub 2 boot it's a good idea to run:
Had that shown you had legacy grub you'd need to open a Grub shell so run the command::
Note: I've noticed while working in a grub shell that the enter key in the numerical block of the keyboard doesn't always work properly, so use the enter key just above the right shift key!
That will provide an output like (hdX,Y) which you'll need to use in the next step:
You see I've used (hdX,Y) from the "find" command, of course you'll use the proper drive/partition designations as indicated by that command. Then:
There I've used only the proper drive designation indicated by the "find" command.
If correct you should see an output like:
Hopefully you see three "yes" and two "succeeded" responses. If not something is wrong.
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)"...* 15 sectors are embedded.
Running "install /boot/grub/stage1 d (hd0) (hd0)1+15 p (hd0,1)/boot/grub/stage
2 /boot/grub/menu.lst"... succeeded
When done we need to exit the grub shell so be sure to run:
Now, whether you recovered legacy grub or Grub 2, you must exit the chroot and umount when done:
Now, how to recover a Windows MBR with only an Ubuntu Live CD:
sudo umount /mnt/dev && sudo umount /mnt/sys && sudo umount /mnt/proc && sudo umount /mnt
sudo apt-get install lilo
There again, the X must be replaced with the proper drive desigantion!
sudo lilo -M /dev/sdX mbr
Note: If I use Lilo to restore a Windows MBR using my "installed" Ubuntu I always like to remove the package "lilo" when done just to prevent some later "conflict" with grub updates, this of course is as easy as "sudo apt-get remove lilo".