dd image size - does it equal the size of the partition?

/dev/sda1       220G  5.8G  203G   3% /

/dev/sda1 is 220 GB in size, and has 5.8 GB used. So:

  1. dd makes a byte-for-byte copy, so the total size of the partition matters, not what's in the partition.
  2. Yes. It will grow to 220 GB.
  3. You can compress the resulting image using gzip or xz:

    sudo dd if=/dev/sda1 | xz > /tmp/ubuntu.image
    
  4. Depends on what you call a better tool. For some tasks, a byte-for-byte copy is needed (say, data recovery from a failing disk). In such cases, dd + compression is the simplest way. If not, consider something like partimage .

Well... you have good answers about the size of the dd file (which if uncompressed is the same size of the partition).

But I see another problem here: you have:

bash$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       220G  5.8G  203G   3% /
[...]

... and /tmp is not mounted elsewhere, so it's on /dev/sda1, and /dev/sda1 is mounted.

So if you do:

 sudo dd if=/dev/sda1 of=/tmp/ubuntu.image 

you are copying an image of /dev/sda1 partition on a filesystem on the same partition --- which will cause:

  1. to fill the partition before the command will have a chance to finish (think about it), unless compressing on-the-fly and being lucky, but

  2. to record a file with a completely inconsistent copy of that partition; mounted partitions are changing all the time in a multitasking operating system.

As a rule of thumb, you dd a partition only when it is not mounted.

Moreover, given that the partition is the / partition of your system, and that you are executing the command as root, you will completely fill your root partition (root reserved space will be used up), and you risk to need to boot with a rescue disc to recovery the mess...


It's my understanding that dd makes an exact clone of the drive, including empty space. If your drive is 220GB, dd will make a copy that is 220GB, regardless of how much of that space is used.

This answer on ServerFault recommends piping through gzip which should be a pretty efficient way to compress the unused space.

dd if=/dev/sda1 | gzip -c  > /tmp/ubuntu.image

You may also wish to defragment first and write zeros to the empty space, both of which could theoretically make the compression more efficient.