1

I have Ubuntu running live from a USB stick on a laptop. I have an external hard drive plugged in which is 2TB.

When I type fdisk -l in the terminal I see the internal hard drive of the laptop as /dev/sda:

Disk /dev/sda: 320.1 GB, 320072933376 bytes 255 heads, 63 sectors/track, 38913 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes

This /dev/sda has two partitions, the boot partition sda1 and another rescue partition sda2. I just want to create a clone of the entire sda drive, including both of those partitions.

Any idea what dd or fdisk command I can use to do this?

Would dd if=/dev/sda of=/dev/sdb/2011-09-13.img work?

When I do md5sum /dev/sda it should match md5sum /2011-09-13.img.

The thing is the 2TB drive has a different number of bytes per sector, I believe it is 4k or something. Will this cause any problems?

2 Answers 2

1

dd of=/dev/sdb/foobar.img doesn't make sense, sdb is a device, not a directory. But you can use a regular file under the location where your /dev/sdb is mounted.

It depends how much you want to preserve. If it is for forensics purpose and if you want to save potentially deleted contents, this is the way to go, but it will be quite slow. If you do not care about it, you can go much faster by cloning individual partitions using filesystem-aware tools such as dump/restore or ntfsclone.

EDIT: if the drive is encrypted, then indeed only a full device dump will do.

The difference in sector size should be transparent, although tuning dd with the bs= option might vary the performance a bit. Try bs=4096, it may match both the sector size of the newest drive and the block size of the filesystem.

You can get the device size with blockdev --getsz /dev/sda and indeed the image file size should match, rounded to the upper 512 bytes.

3
  • so the foobar.img should come out exactly the same size in bytes as the /dev/sda ? Then to restore the img i reverse it and do dd if=foobar.img of=/dev/sda... i guess. I'm thinking this could take quite some time on a 300gb drive, no idea what bs value to try using. The drive is encrypted so... using a program to do this that only copies used space would be useless so i have to copy the entire drive.
    – danielyu
    Sep 12, 2011 at 16:21
  • Hope it can be done faster than 24 hours... dd is very slow from the limited experience i have with it.
    – danielyu
    Sep 12, 2011 at 17:08
  • If it is too slow, you could create a new encrypted container and transfer in clear to avoid copying the empty data. On the other hand, proper secure initialization of the container will take about as much time. A proper implementation will use a different random key and should not leak information about the contents even if an attacker can steal both the old and the new disks.
    – b0fh
    Sep 12, 2011 at 17:12
4

How about using clonezilla live CD for this. They've done the work for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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