Do yourself a favor and never do this if you have other things on your mind. The information is sparse and not very well written, so I'm going to fix that right now. Today I had to install Windows XP on my wife's laptop because some company that makes software that she needs decided that it would be too easy to allow people to use virtual machines to run their software. When I installed Ubuntu on the machine a few months back, I left a 30GB partition at /dev/sda1 to put Windows on there at a later date should she need it. Well, she needed it and I installed it. Once installed, I needed to get GRUB back. If you haven't done this with GRUB2, consider yourself lucky. Here's the easiest way to do it.
- Boot to the LiveCD Desktop (Ubuntu 9.10 or later).
- Open a terminal by selecting Applications, Accessories, Terminal from the menu bar.
- Determine the partition with the Ubuntu installation. The fdisk option "-l" is a lowercase "L".
sudo fdisk -l
If the user isn't sure of the partition, look for one of the appropriate size or formatting.Running sudo blkid may provide more information to help locate the proper partition, especially if the partitions are labeled. The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second, etc. For most users the MBR will be installed to sda, the first drive on their system. The partition is designated by the Y. The first partition is 1, the second is 2. Note the devices and partitions are counted differently.
- Mount the partition containing the Ubuntu installation.
sudo mount /dev/sd''xY'' /mnt
Example: sudo mount /dev/sda1 Note: If the user has a separate /boot partition, this must be mounted to /mnt/boot
- Run the grub-install command as described below. This will reinstall the GRUB 2 files on the mounted partition to the proper location and to the MBR of the designated device.
sudo grub-install --root-directory=/mnt/ /dev/sdX
Example: sudo grub-install --root-directory=/mnt/ /dev/sda
- Refresh the GRUB 2 menu with sudo update-grub
That doesn't look that difficult, does it? Yeah, well, it was a pain in the ass to get to that point. If you notice, I highlighted the example for #5. If you do what I did and try to sudo grub-install --root-directory=/mnt/ /dev/sda1, then you're going to end up getting something that looks like this:
grub-setup: warn: Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea.
grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged.
You don't want this. You're going to try to force it and you're going to fuck something up. Make damn sure you do it right. Let's look at my particular situation.
My setup looks like this:
/dev/sda1 is NTFS
/dev/sda2 is ext4
/dev/sda3 is swap
I would have to enter the following commands:
sudo mount /dev/sda2 /mnt sudo grub-install --root-directory=/mnt/ /dev/sda
After knocking that out, it should tell you that it's been successful and all you now need to do is reboot! It took me 5 different times to get this damn thing back. I ended up bombing out the Windows MBR by installing GRUB on it, which made me have to do a fixboot/fixmbr from the windows recovery console and start all over again. Once I was back to square 1, following the commands above got me done in 5 minutes.
I hope this helps you!