I have an unexpanded partition on my SD card configured as needed. I want to backup the 2.9G data to a less than or equal 2.9G image file. My current SD card is 32G, so when I:

dd if=/dev/rdisk2 of=/path/to/backup.img bs=1m

I end up with a 32G image file. How do I make an image with only the space I have used??

2 Answers 2


you have to type a different command, because this:

dd if=/dev/rdisk2 of=/path/to/backup.img bs=1m

will copy the whole SD card. I'm not sure about the naming system on the computer you use, but most likely you'll be able to find the proper partition name using command df:

$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs          15104000   1685436  12768772  12% /
/dev/root       15104000   1685436  12768772  12% /
devtmpfs          240208         0    240208   0% /dev
tmpfs              49696       588     49108   2% /run
/dev/mmcblk0p1     57288     19040     38248  34% /boot

in this output /dev/mmcblk0p1 is the first partition on the SD card and you may deduce that others will be named as /dev/mmcblk0p2 and so on. Look at the second column for the size, you're supposed to find something like 29xxxxx for a 2.9G partition.

Having said all this, I'd like to notice, dd is not a backup tool. It can copy all you data all right, but the restore part is the most important, and with a dd you most likely won't be able to restore the data properly and end up with a 2.9G blob of something you cannot use. Please, consider copying your files with something like a tar + gzip.


You can't with dd. dd is a low level tool that reads the raw data from the drive (hard disk, sd card, whatever), so dd sees your partition as a 'full of data', it doesn't distinguish your actual data from the format partition data.

You can solve this using two approachs, at least:

  • Backup your data using commands that works with disk data, being the most typical the tar command. tar allows you to copyu and compress only the actual data of your partition.
  • Using dd but compressing the resulting image. Check this answer from https://unix.stackexchange.com/ about how to generate a dd image and mount it on the fly, I think it can be helpful.

Your Answer

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

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