[conspire] dd if=/dev/zero of= ...

Michael Paoli Michael.Paoli at cal.berkeley.edu
Thu Oct 6 00:12:26 PDT 2016


Also very handy for filesystems that use compression and/or deduplication.
Write a bunch 'o nulls, remove the file, and then there's a bunch more
usable space compared to before.  I often do this with virtual machines
on my laptop.  E.g. they'll have backing store that's on a ZFS filesystem,
with aggressive compression, deduplication, and strong verification on
the deduplication (all a space/performance tradeoff).  So, often, within
the VM, it will have relatively large amount of virtual space, e.g.:
# virsh dumpxml debiansidplusexperimentalamd64 | fgrep sda
       <source file='/var/tmp/ISOs/debiansidplusexperimentalamd64-sda'/>
# fdisk -l /dev/loop0
Device       Boot Start     End Sectors Size Id Type
/dev/loop0p1 *     2048 8386559 8384512   4G 83 Linux
# losetup -d /dev/loop0
# ls -onsh /var/tmp/ISOs/debiansidplusexperimentalamd64-sda
404M -rw------- 1 0 4.0G Sep 20 06:24  
/var/tmp/ISOs/debiansidplusexperimentalamd64-sda
#
So ... 4 GiB of virtual disk, consuming ~404 MiB of actual used storage.
Also, since it's on a filesystem that also does deduplication and is  
shared with
other ISOs and images, many of which may be relatively similar, there's some
fair bit more deduplication that may also happen from that and further  
save space.
Sparse file might look similar, but this gets a bit more "interesting" and
complex with compression and deduplication on the filesystem itself.

> Date: Tue, 4 Oct 2016 20:41:32 -0700
> From: Rick Moen <rick at linuxmafia.com>
> To: conspire at linuxmafia.com
> Subject: Re: [conspire] (forw) Re:  (forw) Re:  VirtualBox

> Quoting Carl Myers (cmyers at cmyers.org):
>
>> > BTW, after reducing the partition size, I did a backup using live
>> > Linux on USB.? First `dd if=/dev/zero ...` to write big files of all
>> > 0's.? Next pipe the entire partition through gzip.? The result was a
>> > file of about 45 GB.
>>
>> This is well after the fact, but I just wanted to say that this never
>> occurred to me, and is a brilliant way to make sure the empty space is
>> highly compressible.
>
> Isn't it just?  It's an old trick, but a good one.





More information about the conspire mailing list