Skip to main content

Timeline for How to make ext4 filesystem sparse?

Current License: CC BY-SA 3.0

19 events
when toggle format what by license comment
Jan 24, 2020 at 22:17 comment added Windigo One advantage of using zerofree over dd is that it only writes zeroes over the non-zero unused sectors of your disk - making it much faster and meaning it won't grow your virtual disk to its maximum size before it can be compacted.
Nov 7, 2017 at 23:43 comment added Nabi K.A.Z. I test this solution for ext4 and xfs partition, and works well. Thanks.
Jul 21, 2017 at 7:13 vote accept rajaganesh87
May 6, 2015 at 17:50 comment added pdo @OrganicMarble you need to change the of= parameter, not the if=. The example of=test.file just means put the output in a file called "test.file" in the current working directory. To zero out a different partition, you'll need to specify the output file in that different partition, for example: of=/path/to/other/partition/test.file
Apr 28, 2015 at 2:18 comment added Organic Marble I tried this on my Lubuntu virtual machine which has 2 partitions. It only filled the sda partition with zeros (although that worked great). How do I modify the if= parameter to use a different partition?
Jul 9, 2014 at 7:30 comment added CMCDragonkai Yea I was thinking about that. I wonder if it will work? I'll try and report back.
Jul 8, 2014 at 13:22 comment added pdo @CMCDragonkai you could always just turn compression off, fill the disk with zeroes, delete and shrink, then turn compression back on :)
Jul 7, 2014 at 22:56 comment added CMCDragonkai @pdo wouldn't make more sense to just add "1" to the file instead of calling random all the time? Would this be faster?
Jul 7, 2014 at 22:53 comment added CMCDragonkai That makes sense using /dev/random. But I wonder if it does reclaim the disk space from deleted stuff.
Jul 7, 2014 at 20:28 comment added pdo @CMCDragonkai If you've got compression or de-duplication turned on in ZFS filling the disk up with zeroes will likely never complete. Otherwise, it should work. If you've got compression turned on, you'll have to use incompressible data to fill the disk, change if=/dev/zero to if=/dev/random (or other randomness device as appropriate for your system). I'm not sure this will work for the purposes of shrinking the disk image afterwards though. I'll have to test it and get back to you.
Jul 7, 2014 at 5:39 comment added CMCDragonkai Would you do this for ZFS? It seems to keep going forever.
Apr 15, 2014 at 14:53 comment added Stefan dd idea worked for me too. Nicely done!
Jan 28, 2013 at 9:47 comment added ignis Do a sync after the dd.
Jun 6, 2012 at 18:19 comment added Chris Pratt This should be the accepted answer. Works beautifully.
Nov 5, 2011 at 14:58 comment added Stefano The alternative proposed (dd if=/dev/zero of=test.file) worked for me! Much simpler than other solutions.
Apr 14, 2011 at 8:37 comment added rajaganesh87 Thanks for your reply. The manpage of zerofree did not specify ext4, thats why i needed an alternative.
Apr 14, 2011 at 8:32 vote accept rajaganesh87
Apr 14, 2011 at 8:32
Apr 13, 2011 at 19:25 history edited pdo CC BY-SA 3.0
Updated to reflect actual working solution.
Apr 13, 2011 at 12:22 history answered pdo CC BY-SA 3.0