Restore Grub Bootloader for Servers
GRUB is the default Bootloader program in Ubuntu. It takes care of getting the operating system started up. It is also responsible for allowing the user to select between multiple operating systems at boot. Sometimes, GRUB can begin acting funny, and it may not let you boot into Ubuntu to fix the problem.
Important Note About GRUB Updates!
If you need to configure grub-pc (for example, after an update), installing grub to all devices will break GRUB. You will need to install to /dev/sda (not /dev/sda1) **only**. Installing everywhere **will** break the bootloader.
Reinstall GRUB Bootloader and MBR (Master Boot Record) for Ubuntu 9.10 and Later
Insert an Ubuntu Install CD. You can find instructions for burning them Here. Then boot to it. Open a terminal (Applications > Accessories > Terminal) and run this command:
sudo fdisk -l
This will list all of the partitions on your hard disk:
Disk /dev/sda: 320.1 GB, 320072933376 bytes 255 heads, 63 sectors/track, 38913 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0006628a Device Boot Start End Blocks Id System /dev/sda1 * 1 19891 257847 83 Linux /dev/sda2 19891 22326 19557376 83 Linux /dev/sda3 22326 22845 4166656 83 Linux swap / Solaris /dev/sda4 22845 26003 159767739+ 82 Linux Partition table entries are not in disk order
- Note that these are examples, and not an actual disk.
Identify your boot partition and root partitions. They should be about 250MB and 15 GB, respectively. So here, they're /dev/sda1 and /dev/sda2.
Next, mount both partitions (root first), then bind important system directories there. Replace my examples with your actual disk information:
sudo mount /dev/sda2 /mnt sudo mount /dev/sda1 /mnt/boot sudo mount --bind /dev /mnt/dev sudo mount --bind /proc /mnt/proc
Copy over your nameserver configuration:
sudo cp /mnt/etc/resolv.conf /etc/resolv.conf
Finally, chroot into your root partition and reinstall grub:
sudo chroot /mnt grub-install --force /dev/sda
After this, reboot your computer, removing the disk when prompted, and Ubuntu should boot.
If the chroot command returns with the error "chroot: cannot run command `/bin/bash': Exec format error", this probably indicates that the Ubuntu Install CD is not compatible with that of the installed system.
For example, the error is most frequently seen when trying to chroot to a 64-bit system (eg. amd64) from a 32-bit Install CD (eg. x86).
The solution is to use an Install CD which is using the same architecture as the installed system (i.e. 32-bit Install CD for 32-bit targets / 64-bit Install CD for 64-bit targets).