Monday, February 8, 2010

Had to fix GRUB in Ubuntu 9.10

When I was trying recover data, I had logged out of Windows and into Ubuntu a few times. The first time I left the external drive plugged in when I logged out of Win 7 to log back into Ubuntu, GRUB hung. I believe it had to do with the External hard drive was set sda with a boot flag, as was my HDD. I had to do a hard reset, this I believe this is what corrupted my MBR. I followed this guide from Web Upd8

Booting from a LiveUSB ( I used Ubuntu 9.10) I needed to find my Linux partition , I opened a terminal and entered. 

$ fdisk -l 

This was the out put /dev/sda5 is what L was looking for

Using the terminal again I made a directory:

$ sudo mkdir /mnt/ubuntu

And then mounted the partition sda5 at the directory I created:

$ sudo mount /dev/sda5 /mnt/ubuntu

I needed to  simulate a persistant  root login shell. normal sudo rights would not be enough:

$ sudo -i

I needed /dev from my actual install to be used instead of /dev from the Live instance. By using the bind option it would mount it at /dev in the Live instance

# mount -o bind /dev /mnt/ubuntu/dev

Next run chroot (chroot has live usb use the
directory /mnt/ubuntu as the root directory)

# chroot /mnt/ubuntu

Now to install grub in a terminal

# grub-install /dev/sda

Now I rebooted and continued my work.

I was interested in what chroot was exactly. So the at the  Wikipedia page I got this explanation: A chroot on Unix operating systems is an operation that changes the apparent disk root directory for the current running process and its children.

Thanks Web Upd8 , if you need more info follow the Web Upd8 tutorial. I am just chronicling how I am fixing my goof ups, and trying to understand better the system commands I make as I go.