I need to get a copy of an HDD that is a real 1:1, I mean not just the filesystem but also the geometry and the partition table and everything in between.

if I'll just use

dd if=/dev/sdb of=/tmp/file

this will generate what I'm looking for ?

  • 2
    Only if the disk is sane. It will also be inefficient because dd reads only 512 bytes at a time. Add conv=noerror,sync to copy disks with errors (or better use ddrescue) and use bigger block size otherwise to improve performance (or better, use ddrescue) – Stéphane Chazelas Jun 15 '14 at 19:57

Yes, this should be fine. Be sure to unmount your disk first and make sure there is enough space in the target directory. /tmp is a tmpfs in memory and not on disk on some systems, look at the output of mount to check.

On a root shell you can also simply do:

cat /dev/sdb >/tmp/file

Alternatively, just copy it:

cp /dev/sdb /tmp/sdb.img

Please note Stephane's comment below for a potential benefit of using cp.

  • 4
    cp --sparse=always with GNU cp could help you save space. – Stéphane Chazelas Jun 15 '14 at 19:59
  • Will this copy boot loaders and partition tables? – Sparhawk Jun 16 '14 at 5:02
  • 1
    @Sparhawk - cp is at least simpler. You can likely achieve much the same performance and results using dd- and with GNU dd even something akin to --sparse=always - but it will take some tweaking. cp is pretweaked. And yes, you should be able to simply cp the image back over the /dev/ice but any such action will, of course, be completely destructive to whatever was on the /dev/ice before you did. – mikeserv Jun 16 '14 at 5:18
  • 3
    @Sparhawk, a good cp implementation will automatically optimise the block size, so will be faster than dd. Don't use --sparse=always when you copy to a disk though, only when copying to a file. – Graeme Jun 16 '14 at 8:17
  • 1
    @StéphaneChazelas For me, cp --sparse=always created an identical file to dd. I wonder if it works for volumes, but not whole devices? – Sparhawk Jul 13 '14 at 2:33

There is an informative article on the Arch distro wiki here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.