About that "copying disks" thread and dd

Mikkel L. Ellertson mikkel at infinity-ltd.com
Thu Sep 6 18:44:54 UTC 2007


Paul Johnson wrote:
> 
> I think it is probably better for us non-experts to rely on higher
> level tools than dd when they do this.  There is less danger of human
> error. I see many people recommending "partimage" for this job, but it
> appears that is not in Fedora's distribution, and that makes me think
> it is somehow untrustworthy or dangerous.
> 
> After copying disks 15 times, testing various methods, I think the
> best approaches I've found are
> 
> 1. If two disks are Identical (same brand, same number of sectors,
> cylinders, and all those other things I don't understand very well),
> then the best way to get an exact copy is to run "g4u", which is a
> program that you install on a bootable CDR and its "copydisk" command
> produces an exact byte-for-byte copy of the whole disk, including the
> MBR, partition table, etc.  For all I know, it may be using dd under
> the hood, but the "copydisk" command takes the human error out of the
> equation.  It gets the boot sector and everything.  g4u is about the
> best documented piece of free software I've found.  (The best is CVS,
> by far!)
> 
> 2. If two disks are not identical, be more cautious.
> 
> In the future, here is how I'm going to copy content from 1 disk to
> the other of a different type/size.  Boot the system and make sure
> both disks are recognized by the OS.  Use gparted to study the
> partition table on the source disk, and then on the target disk, use
> gparted to create partitons that are AT LEAST AS BIG as the originals.
> 
> Then copy the content from one to the other.  You can use the
> equivalent of dd in gparted--it has a menu driven approach too copy
> one partition to another, and you can apply that one partition at a
> time.  You can use dd in a terminal if you want, of course.  Using the
> gparted or dd to copy the content is slow because it copies everything
> bit by bit, including the empty parts of the disks.
> 
> There are many ways to just copy the files from one system to another.
>  These will be faster than dd.  Old school Unix people recommend using
> tar or cpio for things like that.  For me, this has always worked:
> Mount the 2 partitions, and then run "find /original -xdev | cpio
> -padm /target ".   New kids seem to feel comfortable with "cp -Ra".
> Some people recommend avoiding copying the system-created partitions
> like /proc, and /sys when making this copy, but I don't think it is
> really necessary because a re-boot wipes those out anyway and builds
> new ones.
> 
> If your target disk is not as big as the source, you should not use dd
> or gparted to copy the content anyway, and so you have to copy the
> content with tar or such.
> 
> After you copy the partitions over, then you need to do 2 things
> manually.   First, use e2label to check the labels on each partition
> of the first disk and then use e2label to write the same labels on the
> target disk.  If you don't do that, chances are the system will not
> boot because Fedora uses labels to find partitions. Note that e2label
> does not work on swap disks, and one must use mkswap with the -L
> option to set a label on a swap partition.   Second, run grub to
> re-write the mbr on the target disk.
> 
> This has been a humbling experience.  If anybody does come with with a
> step by step fool proof way to make this work, I would be really glad
> to hear it.
> 
> PJ
Unless you have a good reason for it, dd is not the right tool to
copy a partition from one disk to another. You are much better off
using a tool like parted, or one of the GUI interfaces for it. This
is because parted understands about file systems. This has several
benefits - you only copy the part of the file system that is in use.
For example, if you have a 40G partition, and only 10G is used, then
you only have to copy 10G, where you have to copy all 30G with dd.
You can also copy to a different size partition. It wil adjust the
file system to the new size. (You must have room for the all the
data on the source partition.)

The drawback is that it can only copy partitions with a file system
that it understands, and it can have problems with file systems that
have errors on them.

In any case, when you are coping a disk, unless you are coping to an
identical disk with dd, and coping the entire disk - MBR and all,
you are going to have to re-install grub on the new disk. This is
because of the way the grub first stage works. The first stage only
know how to load the next stage, and it has the physical location of
what it has to load stored as part of the first stage boot loader.
With most coping methods, the second stage  is not going to be at
the same place on the disk as it was on the original drive.

I find that using a tool like the System Rescue CD works well for
this type of job. You boot from it first to copy the disk. Then you
boot from it again after you have the disk in the new system to
re-install grub. You can re-install grub while the disk is still in
the old system, but this is harder for a new user. You can also use
the Fedora install disk in the rescue mode to do the grub re-install.

http://www.sysresccd.org/

Now, if you are using LVM, it gets much harder to do the copy. It
can be done, but as of yet, the tools are for experts. It would be
nice to have a LVM aware version of parted.

Mikkel
-- 

  Do not meddle in the affairs of dragons,
for thou art crunchy and taste good with Ketchup!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20070906/975ebe03/attachment-0001.bin 


More information about the users mailing list