Recovering GRUB

GRUB pretty much wins hands down for the most inscrutable configuration file of any product (sendmail comes second). So, if you are faced with having to recover GRUB (because your system won't boot), your best option is by far and away to use the Ubuntu boot repair tool.

Simply boot up the Mythbuntu install disk (making sure that you have a working Internet connection) and, when it is finished booting, select the "Try Mythbuntu" selection. This will eventually bring up the desktop.

Once you are looking at the desktop, under the Applications/Accessories/ Terminal menu choice, launch a terminal window. Type the following commands into the terminal window:

     sudo apt-add-repository ppa:yannubuntu/boot-repair
     sudo apt-get update
     sudo apt-get install -y boot-repair
     sudo boot-repair

You can disregard the whining by apt-get when you run update (truly, an idiot message that reads "..., run apt-get update to fix these problems", when you are running apt-get update is way beyond idiotic). Select the "Recommended repair" choice and follow the tool's instructions. Hopefully, when it's done you're good to go.

Alternately, if boot-repair doesn't work, or you want to do it yourself, or you don't have an Internet connection whereby you can install boot-repair, you can follow the steps above to fire up a terminal window, and then do the repairs from the command line. From the command window, proceed as follows:

     sudo fdisk -l

This will list all of the disk partitions. Figure out which of the partions is the actual boot partition. If you only have two partitions on the system disk (e.g. "/" and swap), then your boot partition is "/". If you have a separate boot partition (e.g. "/boot"), then your boot partition is "/boot". Mount the boot partition:

     sudo mkdir /mnt/bootdisk
     sudo mount /dev/sdxx /mnt/bootdisk

Replace "sdxx" with the name of your boot partition.

If you know how to use vi, you can edit your GRUB configuration file using it. Or, if you do have an Internet connection and you want to use gedit, you can install it like this:

     sudo apt-get install gedit

Using whatever text editor you choose (you can even boot another operating system such as Knoppix and edit the GRUB config file with it), edit the GRUB config file (grub.cfg). Make sure that you are editing the one under /mnt/bootdisk, not the one that comes with the trial Mythbuntu. Bear in mind that you only want to monkey with this file as little as possible. Probably, you will only need to alter one or two menu entries, and then only to change the UUIDs of the various boot partitions. If you search for your old disk's UUIDs, you'll see what needs to be changed. More likely than not, you'll only need to change the first or second menu entries (although, if your system has been upgraded, there may be more, which point to prior versions of Ubuntu). A typical menu entry should look like this:

     menuentry 'Ubuntu, with Linux 3.2.0-24-generic' --class ubuntu \
       --class gnu-linux --class gnu --class os {
         recordfail
         gfxmode $linux_gfx_mode
         insmod gzio
         insmod part_msdos
         insmod ext2
         set root='(hd0,msdos1)'
         search --no-floppy --fs-uuid \
           --set=root 5c5f0c51-55cc-47e3-b77e-ca400b46af9b
         linux /vmlinuz-3.2.0-24-generic \
           root=UUID=325cef3c-97ce-47de-f7ff-e4ff0a2101f0 \
           ro quiet splash $vt_handoff
         initrd /initrd.img-3.2.0-24-generic
       }

The UUID of your separate boot partition follows the "--set=root" parameter of the search command, if you are using a separate boot partition. Otherwise, this is the UUID of your system partition. If you are using a separate boot partition, the path names like "/vmlinuz..." and "/initrd..." start with "/". Otherwise, they will start with "/boot/". The "root=UUID=" parameter of the linux command is the UUID of your system partition.

These are usually the only things that you will need to edit. If you think that you need to change "(hd0,msdos1)", you probably shouldn't. If you are now trying to boot Mythbuntu from a GPT instead of MSDOS partition table, you should read these three notes on how to do it:

     https://www.anchor.com.au/blog/2012/10/\
       the-difference-between-booting-mbr-and-gpt-with-grub/
     http://www.wensley.org.uk/gpt
     http://www.rodsbooks.com/gdisk/booting.html

Once you have done making changes to grub.cfg, you can reinstall GRUB onto your system disk, pointing it at the appropriate spot in the mounted partition:

     sudo grub-install --boot-directory=/mnt/bootdisk/boot /dev/sdx

or

     sudo grub-install --boot-directory=/mnt/bootdisk /dev/sdx

You should now be able to boot the system from the new or moved disk.