Making new hard drive bootable in GRUB

Q I've been trying to duplicate a Linux system drive - it's a SCSI drive, if that makes any difference. I have a new drive, which I've partitioned in broadly the same way with swap and root partitions; the root is ext3. Another drive, which I'm not concerned with, is mounted in /home. I booted Knoppix, mounted both drives and successfully copied everything over using dump piped into restore. Everything compares nicely and I have a reliable duplicate.

The last bit is to make the new drive bootable, and this is where I'm getting stuck. The old drive is /dev/sda (sda1:swap, sda2:ext3) : grub: hd0. The new one is /dev/sdb (sdb1:swap, sdb2:ext3) : grub: hd1. When I then remove the old drive and try booting, I get 'GRUB boot disk error' or something similar. I have tried a variety of things - too many to list - but it seems to me that the problem could be linked to the fact that I install Grub on an address that it isn't booting from. Thus I'm booting from /dev/sda and installing Grub on hd1 and then removing /dev/sda, so hd1 becomes hd0 and Grub can't find it. Is this possible? If so, how do I get around it?

A Grub numbers the drives in the order in which they are discovered by the BIOS. When you remove the first drive, the remaining drives move up a number, so hd1 becomes hd0, as you suspected. There are two ways you can deal with this. The easiest involves using a Live CD that includes Grub, such as Knoppix or a Gentoo minimal installation CD (which is a much smaller download than the standard Knoppix install). After removing the old hard disk, boot from the Live CD. If you're using Knoppix, type knoppix 2 at the boot prompt to take you straight to a root console. Then install Grub on your hard disk, as you did before, with

grub-install /dev/sda

If grub-install gives problems, you can install manually from the Grub shell with

grub
root (hd0,0)
setup (hd0)
quit

I take it you have already edited /etc/fstab and /boot/grub/menu.lst to use /dev/sda instead of /boot/sdb. The other way of doing it is to use the feature available in some BIOSes to swap the boot order of the hard disks, so that your new drive is discovered first. As the new disk doesn't have Grub installed yet, the computer would still boot from the second (old) disk, but when you run grub to install it to the new hd0, this disk would be booted from next time onwards. You could then swap out the old disk and set the BIOS back to its previous boot order. This method is more fiddly than the first and is not guaranteed to work on all hardware, so only try this if you cannot use a Live CD for any reason.

Back to the list