2

I'd like to simply duplicate a hard disk drive to another hard disk drive of the same size.

I know I can simply do:

dd if=/dev/sda of=/dev/sdb

(or whatever the names of the drives are in /dev).

Is there a better tool for this which will show me visual progress? If I'm only using 30GB of the drive, will it only take as long as it takes to transfer 30GB or will it take as long as the drive capacity?

2
  • You say drive, but your command use partitions
    – enzotib
    Dec 20, 2011 at 20:08
  • So a drive would be /dev/sda and /dev/sdb, right? That's what I meant, sorry. Dec 20, 2011 at 20:09

3 Answers 3

4

You can make GNU dd show you progress - to quote the man page:

Sending a USR1 signal to a running `dd' process makes it print I/O statistics to standard error and then resume copying.

$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid

Schily's dd (sdd) has a similar option and uses SIGQUIT by default (Ctrl+\).

Regarding your second question: Yes, dd just copies all the blocks if used by the filesystem or not - which takes DEVICE_CAPACITY/TRANSFER_RATE seconds.

If you want to avoid copying unused disk blocks you can use tar:

# cd /mnt/sda
# tar -c -f - . | tar -C /mnt/sdb -x -f -

GNU tar also has timing options:

# tar -c -f - . --totals=SIGQUIT | tar -C /mnt/sdb -x -f - \
                                      --totals --totals=SIGQUIT

Thus you get read/write statistics when hitting Ctrl+\ and at the end.

Another possibility is to use parted or gparted for copying a filesystem - which should be done in a efficient way with filesystems it has enough knowledge of. At least gparted should display a nice graphical progress dialog.

4
  • I'll need to copy all the blocks then, as I have HFS+, NTFS, and ext4 partitions on the same drive. Dec 20, 2011 at 20:45
  • Ctrl+? Ctrl+\​? No, that sends SIGQUIT. There's no key for SIGHUP. An easier, and generally more robust way of copying files on a Linux system is cp -a . /mnt/sdb, or rsync -aP . /mnt/sdb if you want a progress indicator. Dec 21, 2011 at 2:19
  • @Gilles, yes Ctrl+backslash is SIGQUIT - mixed that up - I will update the question. cp -a is not portable - GNU cp has -a but it is not in POSIX. A correct implementation of cp -a should work as well as the tar pipe (modulo use of --totals option) - but why should it be more robust? Dec 21, 2011 at 8:51
  • @maxschlepzig My recommendation of cp -a is from an experience a few years ago, transferring home directories of people with a propensity for using advanced features of anything they touched between filesystems that weren't supported by the same unix variant. GNU cp -a over NFS caused no complaint. tar choked on files with a hard link count >1 whose path was >100 bytes. pax missed named sockets and a few other oddities. I forget what other solutions I tried. I remember some not preserving file access times, too. Dec 21, 2011 at 16:46
3

Maybe you can use ddrescue /dev/sda /dev/sdb which support errors and have a progress bar

1
  • Probably need the -f flag for GNU ddrescue to overwrite destination device Dec 21, 2011 at 12:30
3

I suggest that you use the pv program (it is on the repos of all the distros i know of). It will give you an nice progress bar.

$dd if=/dev/sda |pv -s 80g |dd of=/dev/sdb

with the -s you add the amount of the original prtition/disk you are copy (the if in the dd command). If you wouldn't put the -s argument it just give you a moving bar to indicate that data is moving, but wouldn't give you how much.

of course add sudo if you need.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .