dd - cloning a disk.

Kevin Kinsey kdk at daleco.biz
Sun Mar 12 03:06:02 UTC 2006


Grant Peel wrote:

> Hi all,
>
> Here is a simple (I think!) question for the I/O savy among you:
>
> If I had two identical disks, say, 73 GB Seagate 10K SCSIs, one 
> completely
> operational fully setup FreeBSD with all the trimmings, and the other 
> blank,
> or perhaps loaded but no longer usable, is 'dd' and appropriate tool to
> completely clone the Good disk to the not so good disk....therefor
> making the second disk identical to the first? Bootable and all?
>
> -Grant



Hi, Grant:

Yes, dd, will copy/clone a disk.

There was a fairly long, good thread on this subject on this
list sometime in the last 3-5 weeks.  Giorgios Keramidas
commented that "dd" was too slow for his tastes and
suggested dump and restore for this type of work.

Now, I'm no expert at fdisk and bsdlabel scripting, but here's
a plan I adopted as a result of that thread.  It includes manual
labor via the sysinstall front end to fdisk and bsdlabel, and
then is "automagic".

1.  Set up the hardware--- I'm assuming extant drive on primary
IDE master and new drive as same channel slave.

2.  Run sysinstall as root, choose "Configure (Post Install Configuration)
and run Fdisk.  Dedicate the entire new disk and set it bootable.  Write
out the changes with, um "W", isn't it (IIRC)....

3.  Exit sysinstall and then start it up again.  Run the "disk label editor"
and set up partitions of a sufficient size for the clone procedure 
(generally,
same size or larger; in a pinch, could be smaller than the original 
partition
but, obviously, must be large enough for the data on the original 
partition).
Write out the changes, exist sysinstall.

4.  Run this script (edit it to reflect your actual layout):

    #!/bin/sh

    mkdir -p /1
    mkdir -p /2
    mkdir -p /3

    mount /dev/ad1s1a /1
    mount /dev/ad1s1d /2
    mount /dev/ad1s1e /3

    dump -0 -a -L -f - / | ( cd /1 ; restore -ruvf - )
    dump -0 -a -L -f - /var | ( cd /2 ; restore -ruvf - )
    dump -0 -a -L -f - /usr | ( cd /3 ; restore -ruvf - )

Quick, easy, fast.  Probably someone with a better handle on
fdisk/bsdlabel could script steps 2-3 above.  And, with thought,
#4 could be improved, too.  But, it is faster.

Basically, I'm thinking this:

A.  With the "dd" approach, you don't need to know anything
about the extant filesystem's layout.

B.  But, if you use dump | restore, you trade a little foreknowledge
of the extant filesystem's layout for flexibility (disk doesn't have
to be identical); and speed (the only thing copied is the data, not the
blank space, and from a filesystem viewpoint instead of block level
copying).

We've used this successfully to create a number of disks for
"cheap" workstations at a client of ours---as a result, they have
plenty of stations available with almost no time spent in "tweaking"
the installation other than hostname and interface configuration
in rc.conf.

YMMV, and all that.  HTH, (or at least provides another perspective).

Kevin Kinsey

-- 
My doctorate's in Literature, but it seems like a pretty good 
pulse to me.




More information about the freebsd-questions mailing list