For backup reasons I need to use dd to copy a whole hard drive (including MBR, partitions,...). The hard drive is 80 GB in size where only 1.8 GB are used.

The command I'm using is the following:

dd if=/dev/sda bs=8M | gzip -9 > /mnt/backupserver/ddCopy.bin.gz

My question here is: Is that already the best way to minimalize how much space is used, or is there any other (better way?)

To take the above example with the 1.8 GB used on a 80 GB drive....the copy takes up way over 2 GB despite the zipping.

Edit as it was asked in a comment here the details about sda:

  • Contains a NTFS partition whose size is 80 GB (as that whole drive only has 1 partition)
  • du says 1.8 GB of sda are in use
  • Contains a windows xp as OS
  • 2
    1) Before copying fill the unused space with zeros 2) Use a better compression algorithm than DEFLATE, e.g. LZMA2 – Marco Jan 18 '16 at 11:05
  • Or zpaq - usually better compression, but slower. – Tom Zych Jan 18 '16 at 11:08
  • Also see Clear unused space with zeros (ext3,ext4) and Which file compression software for linux offers the highest size reduction? (hint: have a look at pixz if you need some speed). – Marco Jan 18 '16 at 11:08
  • @marco speed is not really a concern for me (it can take a full day without a problem). The only problematic thing is disk space for me. – Thomas Jan 18 '16 at 11:52
  • Specifying the filesystems and specific OS would probably help. Also when you say "1.8GB are used", I supposed that's spaced used within the filesystem(s), rather than space used by the filesystem(s) (i.e. partitions)? – jcaron Jan 18 '16 at 12:33

Checkout ntfsclone. I believe that's what you're looking for. From the man page:

ntfsclone will efficiently clone (copy, save, backup, restore) or rescue an NTFS filesystem to a sparse file, image, device (partition) or standard output. It works at disk sector level and copies only the used data. Unused disk space becomes zero (cloning to sparse file), encoded with control codes (saving in special image format), left unchanged (cloning to a disk/partition) or filled with zeros (cloning to standard output).

  • 1
    +1 Good point about ntfs clone. Sadly though I tried that one before I tried dd and somehow it .....failed. unix.stackexchange.com/questions/255474/… is the question I made there as sadly not working I went the dd route (as the problems with ntfsclone are very specific for me I +1 this answer as normally it would be a very good option!) – Thomas Jan 18 '16 at 11:59
  • Just left you comment over there to possibly troubleshoot that further. – Paul Calabro Jan 18 '16 at 12:09
  • Tnx. Saw it and answered. Both commands (the one here with the dd and the one over there with ntfsclone) I'm using on the same clients and with the same server in use. – Thomas Jan 18 '16 at 12:12

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.