Saturday, March 10, 2007

Reclaim your GNU/Linux

[Technical]

One of the most common problems that people face with multiple OS's - Windows and GNU/Linux is that the boot loader (Grub) disappears upon re-installing Windows.
This also happens if you have Tux installed in a second hard-disk which you later decide to make your sole hard disk.

For LILO, earlier, with certain versions of Mandrake etc., I used to go through all steps of the installer but the last part where it copies the files (asking it not to make any changes to the partitions), by which time LILO is written on the MBR, after which I boot to Tux and modify its settings.


This is the solution for Grub which works on FC5 (and possibly all other FC distros):
http://www.fedoraforum.org/forum/showthread.php?t=975

For point 4 there, just choose the "Continue" button so that it autodetects.

After this, if the system reports that certain parts only have been mounted into /mnt/sysimage, you might not be able to install Grub on the MBR successfully.

So, vi /mnt/sysimage/etc/fstab or /etc/fstab if you have chroot'ed as mentioned there.
Correct it so that only partitions and drives which actually are present correctly are mentioned.
In the first column of each row, if you have something like "LABEL=/", correct it to the actual device name - i.e. something like "/dev/hda6".
Reboot and repeat; if your hard disk is still ok, most probably the autodetection will come out clean.

4 comments:

ksp said...

The "correct" way to solve a missing GRUB bootloader is the following:

1. In your installation CD, switch to console mode (usually Ctrl+Alt+F2), or use Knoppix or Ubuntu Live CDs.

2. Mount the partition that has /boot (usually /, root partition) to some location, say /tmp/partition/

3. Now run grub-install --no-floppy /dev/hda --root-directory=/tmp/partition

Quick and easy, and the standard way. The --no-floppy speeds up things when you don't have a floppy disk. This doesn't work when you have a separate boot partition, but it will restore the MBR anyway.

Furthermore, I fail to see the connection to the fstab entry. In FC, it's usually dangerous to change the LABEL=/ entry for the simple reason that FC expects you continue to use that scheme. In particular, upgrades to kernels beyond 2.6.19 might break your boot, because the PATA layer in the kernel has been rewritten, and uses /dev/sdX names now, even for PATA disks.
See this Kernel Newbies page

Abhijit Pai said...

"Quick and easy, and the standard way." - I wonder why Google (search) led me to think otherwise.


"I fail to see the connection to the fstab entry. In FC, it's usually dangerous to change the LABEL=/ entry " - It might be _necessary_ to change stuff in /etc/fstab as it was for me if ones hard disk setup changed.

"... break your boot" - This was being done because the boot was broken.

ksp said...

".. if ones hard disk setup changed ..."

Funnily enough, the LABEL scheme was invented just to handle this. Although FC's default choices made life problematic for those who put in two hard disks with / partitions :D Of course, you can change it with the e2label command, and I usually did to make it include my machines name.

Ubuntu uses UUID numbers which get around this, but they're too cumbersome to use as such.

Devadutta Ghat said...

Although I have done this rescue dance more than once, I really cannot recall the steps when I need them and I always fall back to inserting the disk and performing all steps of install except the copying of files.

When I get some time, I will sit and make a cheat sheet :P