0

We're using RHEL 5.4 and need to clone some hard drives. What would be a good (or "correct") way to do this? I'd like to avoid using dd if I can, since that's somewhat slow. (If that's the only choice, however, then so be it.)

A few caveats:

1) Using other distros is not possible - inlcuding live CDs - as we have a very strict approval process and the only distro we can use is RHEL.

2) If at all possible we need to use software that's part of the RHEL packages. Recommendations of other software are still appreciated, but if we can use something already part of RHEL it would save us a lot of paperwork.

I realize this seems like I'm trying to make the job harder than it should be, but such is the nature of corporate regulations.

Thanks for any help!

3
  • 2
    dd is so slow because it reads the entire drive. Anything else won't be a true exact clone of the drive.
    – freiheit
    Sep 7, 2010 at 15:13
  • Thank you everyone for the suggestions. I believe the perhaps-unfortunate truth is that dd really is the best thing for us, as we wanted an exact clone of all HD contents.
    – Dave K
    Sep 7, 2010 at 16:41
  • mondorescue.org & revisor.fedoraunity.org both the product i have use with fedora you give try on above product.
    – Rajat
    Sep 7, 2010 at 17:02

5 Answers 5

3

How exact a clone do you need? If there's LVM, for instance, do the IDs need to match? ext2 (and 3, and probably really most Linux filesystems) has a Universally Unique Identifier (UUID) on each filesystem; do those need to match between original and clone?

In other words, what do you need the clone for?

There's nothing faster than dd for making a true exact clone of a drive.

Some dd alternatives

  1. Use fdisk (or parted or cfdisk or whatever) to duplicate the partitioning. lv tools if necessary. Make filesystems, use rsync or (cd /origmount ; tar cf) | (cd /newmount; tar xf -) or cp to copy the data -- This will lay out the files in a completely different arrangement of blocks, but look identical. Or don't mount the original filesystems and use something like dump -level0 -f - /dev/sda1 | (cd /mnt/sdb1; restore -f - -rf)
  2. Carefully use software RAID tools (md) to create a degraded RAID1 out of the original partitions, add the new partitions, wait for sync to finish and then break the RAID. This will probably be slower than dd, but most of the work can be done while the machine is running so it may be "faster" for certain definitions of that word.
1

These are steps I recorded for moving from a large LVM managed disk with a CentOS 5.5 install to a smaller disk (obviously the used space on the large disk was less than the size of the smaller disk). I'm sure there are better ways to do this, but this method was successful. Some steps may be specific to our situation, tweak as necessary.

Reqs:

  • Install CD
  • New disk

Steps:

  • Connect the new disk

  • Boot with the CD, at the prompt type "linux rescue" to get into rescue mode. It will ask whether you want to continue or skip the mount, you should continue (it will mount to /mnt/sysimage). Do not format the new disk if it asks.

  • Check previous geometry with fdisk -l. You'll likely have /dev/sda1 and /dev/sda2 in a regular LVM configuration. sda1 will be your /boot partition which exists outside of the LVM. Its size should be 1-13 with the rest of the disk being dedicated to the LVM.

.

# fdisk -l
...
/dev/sda1 * 1 13 ... 83 Linux
/dev/sda2  14 ...    8e Linux LVM
# fdisk /dev/sdb
>Command...:
n
>Command action
>e extended
>p primary partition (1-4)
p
>Partition number (1-4):
1
>First cylinder ...:
<default>
>Last cylinder ...:
13 (value from /dev/sda1, the original /boot)
>Command...:
n
>Command action
>e extended
>p primary partition (1-4)
p
>Partition number (1-4):
2
>First cylinder ...:
<default>
>Last cylinder ...:
<default (end of disk)>
>Command...:
t
>Partition...:
1
>Hex code...:
83
>Command...:
t
>Partition...:
2
>Hex code...:
8e
>Command...:
a
>Partition...:
1
>Command...:
w
  • Create file system for /boot on /dev/sdb1

.

# mkfs.ext3 /dev/sdb1
  • Setup new Physical Volume, Volume Group, and Logical Volumes and their filesystems on /dev/sdb2. Replace ?G with the size you want. LogVol00 should be LVM partition size minus your required swap volume size, LogVol01 should be your swap size.

.

# pvcreate /dev/sdb2
# vgcreate VolGroup01 /dev/sdb2
# lvcreate --name LogVol00 --size ?G VolGroup01
# lvcreate --name LogVol01 --size ?G VolGroup01
# mkfs.ext3 /dev/VolGroup01/LogVol00
# mkswap /dev/VolGroup01/LogVol01
  • Mount the new disk and copy contents from the old disk to it with cp -ax. Avoid copying /dev, /proc, /sys, /boot, /lost+found and /mnt

.

# mkdir /mnt/newdisk
# mount /dev/VolGroup01/LogVol00 /mnt/newdisk
# cd /mnt/sysimage
# for i in $(ls -1 | grep -v '\(dev\|proc\|sys\|mnt\|boot\|lost\)'); do echo $i; cp -ax /mnt/sysimage/$i /mnt/newdisk; done
# cd /mnt/newdisk
# mkdir {dev,proc,sys,mnt,boot}
  • Mount the new /boot and copy contents from the old disk to it, then unmount it

.

# mkdir /mnt/{boot,newboot}
# mount /dev/sda1 /mnt/boot
# mount /dev/sdb1 /mnt/newboot
# cp -ax /mnt/boot/* /mnt/newboot
# umount /mnt/newboot
  • Install grub to the new disk

.

# mount -o bind /dev /mnt/newdisk/dev
# mount /dev/sdb1 /mnt/newdisk/boot
# chroot /mnt/newdisk
# grub
> root (hd1,0)
> setup (hd1)
> quit
  • Fix your /boot/grub/grub.conf

.

# vi /boot/grub/grub.conf
:%s/VolGroup00/VolGroup01/g
:wq
  • Redo your initrds

.

# cd /boot
# for i in $(ls -1 initrd* | grep -v bak); do mv $i{,-bak}; ver=$(echo $i | sed 's/initrd-//;s/\.img//;'); mkinitrd /boot/$i $ver; done
  • Exit from the chroot

.

# exit
#
  • Fix your /etc/fstab

.

# vi /mnt/newdisk/etc/fstab
:%s/VolGroup00/VolGroup01/g
:wq
  • At this point, shut down and remove the old disk. Boot again into rescue mode. /dev/sdb will now be /dev/sda and mount to /mnt/sysimage

  • Label /boot

.

# e2label /dev/sda1 /boot
  • Remove the CD, and you should be able to boot into the resized disk at this point.
0

Well, if you're avoiding using 'dd' and any other non-RHEL provided tool, then you're stuck with duplicating file systems and copying over the contents (using your tool of choice, cpio, tar, rsync, etc) and putting GRUB on the new drive(s). This would best be done with quiesced drives (booted into RHEL rescue mode, perhaps).

0

What's the purpose of cloning the drive? To quickly install multiple systems? Then create a kickstart file from the server to be cloned and use that to install the other machines.

0

For imaging copies of your disks, you could try Ghost, Fog, Clonezilla, etc. (Even VMware Converter, etc.).

For a filesystem copy, I'd recommend rsync and the like.

You must log in to answer this question.