Restoring Grub Bootloader on Ubuntu 5.10
Microsoft does not believe that any other operating system should be running on a computer other than Windows. So if you install Windows after Linux, your master boot record (MBR) will have been overwritten with Microsoft's and you will no longer be able to boot into Linux. To fix this, you need a Linux boot cd to install grub back into the MBR.
- Boot your computer with Ubuntu CD.
- At the "boot:" menu type "rescue"
boot: rescue
- Follow the install process until you reach "[!!] Enter rescue mode" screen. It will ask you to choose which device to mount as your root filesystem. Select the partition that you installed Ubuntu on. If you aren't sure, just select one, it will give you an error screen if it was unable to mount the partition or find a shell on the partition.
- After you successfully mounted the file system you will be taken to a shell. If you try to run
grub, it will complain with the error:
sh-3.00# grub
Probing devices to guess BIOS drives. This may take a long time.
Error opening terminal: bterm.
- To get around this, I set my TERM to xterm. (vt100 and ansi terms also gave me display problems so I just used xterm).
sh-3.00# export TERM=xterm
- You should now be able to run
grub. Now it is time to reinstall the bootloader. Once you are at the grub prompt, type root ( and then the <TAB> key. Grub has a bash like auto complete that will detect the partitions and filesystems on your computer. Choose the hard drive and then the partition which has Ubuntu installed (almost always the one with the ext3 filesystem). On my system it is (hd0, 2) which represents the 3rd partition on the first hard drive (hd0).
sh-3.00# grub
grub> root (hd0, 2)
grub> setup (hd0)
grub> quit
- Alternatively, instead of running the
grub command, you can use the grub-install <device> command to restore your bootloader, where <device> is the name of the device where ubuntu is installed. I did not have much luck using this command so I cannot comment on it's effectiveness.
sh-3.00# grub-install /dev/hda
Troubleshooting
- If you upgraded your linux kernel through Ubuntu's Update Manager and you can no longer boot into Ubuntu, it may be because your partition tables changed since your last kernel upgrade. This might happen if you added additional hard drives and/or repartitioned your drive. To fix this, you will need to run the update-grub command. But before this, you need to edit your /boot/grub/menu.lst.
# vi /boot/grub/menu.lst
- Look for the comments containing the groot and kopt options. After a kernel update, Ubuntu will call update-grub, which uses these variable to recreate the the menu.lst. If these option are misconfigured, update-grub will break your menu.lst. Make sure groot, and kopt are set to the correct hard disk and partition.
# groot=(hd0,2)
# kopt=root/dev/hda3 ro
- Now run update-grub command
# update-grub
Searching for GRUB installation directory ... found: /boot/grub .
Testing for an existing GRUB menu.list file... found: /boot/grub/menu.lst .
Searching for splash image... none found, skipping...
Found kernel: /boot/vmlinuz-2.6.12-10-686
Found kernel: /boot/vmlinuz-2.6.12-10-386
Found kernel: /boot/vmlinuz-2.6.12-9-686
Found kernel: /boot/vmlinuz-2.6.12-9-386
Found kernel: /boot/memtest86+.bin
Updating /boot/grub/menu.lst ... done
- Your menu.lst should now be correct. Reboot your computer you should be able to boot Ubuntu through the grub menu.
References
--
JesseSuen - 04 Mar 2006