Title: reasons for a dd image of an almost-empty drive not be small after gzip
Tags: filesystems;dd
Question: i just cleaned a 50GB partition with dd if=/dev/zero of=/dev/sda1
then added some data to it (actually installed a linux distro) some 3Gb on ext4.
and decided to make a image.
dd if=/dev/sda1 | gzip -9 &gt; sda1.dd.gz
and to my surprise, that file has 45GB!
my thinking would be that the this file would have some 4GB as most of the size would be tailing zeros that gzip would take care of.
where am I wrong? anyway to check how back the fragmentation is after the add-data step?
Also, if it is fragmentation, any way to fix it? i'm now writing /dev/zero to a file until the drive is full...
Comment: turned out that the install, for some reason, scattered data all over the disk. I redid the `cat /dev/zero > /mounted_drive/zero` _after the install_ and then removed the file and redid the `dd`, turned out to be a 1.3Gb file after gzip.

Comment: I guess if you enabled full-disk encryption, that'd explain it. Or maybe if you ran badblocks (in write-destructive mode) as part of making the filesystems.

Here is the accepted answer: From OP's comment:
Turned out that the install, for some reason, scattered data all over the disk. I redid the cat /dev/zero &gt; /mounted_drive/zero after the install and then removed the file and redid the dd, turned out to be a 1.3Gb file after gzip.
With this, the question is effectively answered (and, as a side-effect, removed from Unanswered Questions queue).
Comment for this answer: i think i wrote that as an answer and the site moved up to a comment because it was too short..? it does that sometimes. thanks


{'source': 'StackExchangeDataset', 'subset': 'unix.stackexchange.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:02/25/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<filesystems><dd>', 'Title': 'reasons for a dd image of an almost-empty drive not be small after gzip', 'ViewCount': 430, 'id': 66018, 'user_AboutMe': '<p>indifferent dilettante.</p>\n', 'user_AccountId': 61445.0, 'user_DisplayName': 'gcb', 'user_Reputation': 304.0, 'user_Views': 32.0, 'user_id': 11805.0}}