Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have just created an image of an sd card using dd and the image is compressing down less than expected. I suspect this is because the card had not been zeroed out before I started to make the image. Is there a way to clear out "junk" stored on an image without having to start from scratch?

share|improve this question

The easiest way to zero out unused space is to mount the image, fill up the space with zeroes, and remove the zero-filled file.

mount -o loop /path/to/image /mnt
cat /dev/zero >/mnt/zero
rm /mnt/zero
umount /mnt

Depending on what the filesystem is, there may be tools that can work directly on the image. See this question for ext2/ext3/ext4 (answer: zerofree).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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