> I want to clone a hard disk to another hard disk in the same system, and
> keep the partition structure. I would also like the cloned hard drive to be
> bootable, just like the main one, so I have a 'hard copy' that I can put on
> a shelf somewhere.
> A simple dd doesn't do the trick... I tried 'dd if=/dev/hda of=/dev/hdb' and
> it appeared to work but I think the fact that the second hard drive is
> larger than the first one is affecting things, because I can't see any of
> the partitions after the dd on the second drive.
> Any suggestions?
Copying the whole image doesn't really work for hard drives that
are different sizes (and perhaps even ones that are the same size,
but from different vendors or are different models) There is data
stored on the first sector that contains information about the
size/geometry of the drive. Just copying it from another drive is
probably confusing the BIOS and/or Linux. That is probably why
you can't see the partitions on the second drive.
Try making partitions on the second drive that are the *exact* same
size as the partitions on the first using fdisk. If it is not
possible to make the partitions the exact size as the first, (if
the cylinder sizes are different) you'll have to make them slightly
larger and you'll lose a little bit of space. Then dd for each
partition. To make the second drive bootable, mount the
corresponding root partition (and any other partitions necessary
for lilo) somewhere, then run 'lilo -r /your-mount-point'
For example, if you had a /boot partition as #1, and your root (/)
was partition 2, then the procedure might look something like this:
(run fdisk/cfdisk and create your partitions on hdb)
dd if=/dev/hda1 of=/dev/hdb1
dd if=/dev/hda2 of=/dev/hdb2
mount -t ext2 /dev/hdb2 /mnt
mount -t ext2 /dev/hdb1 /mnt/boot
lilo -r /mnt
You can always use mkfs and cp -a to copy the data instead. It
may take longer, but you have less risk of messing things up with
a typo, and you will have more assurance that the filesystem is
properly sized for it's partitions.
And if you are intending to periodicly 'clone' your drive, it
shouldn't be to hard to create a script that parses either
/proc/partitions or (s)fdisk -l /dev/hda with awk or sed and
uses sfdisk to create the partitons on hdb, then creates the
filesystems and copies the data. In fact, I imagine if you
look on freshmeat.net you may find a script/program that does
it for you.