Friday, 11 February 2011

Fixing a fucked Grub

If you followed along with my instructions you will have a handy little grub.conf file in your /etc folder. This means that if your grub gets corrupted for whatever reason, it should be a simple matter to get it up and running again. Well, simple for Linux anyway.

Boot from another version of Linux - either from another partition in dual boot, or Live media. Run the command:

sudo fdisk -l

Check the partition ID for the one you want. In my case it was sda7. Now what we want to do is mount the whole of our LFS partition into the filesystem we are currently using. We are then going to chroot (remember that) into that system and effectively reinstall grub, thus:

sudo mkdir /media/problem
sudo mount /dev/sda7 /media/problem
sudo mount -v --bind /dev /media/problem/dev
sudo mount -vt devpts devpts /media/problem/dev/pts
sudo mount -vt tmpfs shm /media/problem/dev/shm
sudo mount -vt proc proc /media/problem/proc
sudo mount -vt sysfs sysfs /media/problem/sys
sudo mount -v --bind /tmp /media/problem/tmp
sudo chroot "/media/problem" /usr/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login

MAKE SURE the contents of /etc/grub.conf match your the partition that you want to fix. If you want to install Grub to sda7 for instance, you want to see [hd0,6] in the .conf file. If you have another bootloader in the MBR of the drive for dual booting, you want BOTH entries for in the .conf file to show [hd0,6] not one at [hd0]. If you installed to a USB Key and are reinstalling Grub on a different machine, the chances that all the partitions are the same number are very very poor indeed. If that is the case you will need to [nano] into the [conf]iguration file to set it right.

grub --batch < /etc/grub.conf

Job is, as they say, a good'un.

No comments:

Post a Comment