So my setup is like this.
$ truncate -s 1T volume
$ losetup -f --show volume
/dev/loop0
$ mkfs.ext4 /dev/loop0
$ ls -sh volume
1.1G volume
$ mount /dev/loop0 /mnt/loop
Now I have a 1.1TB volume, as expected. The overhead of ext4 expanded the sparse file to 1.1G, but that's fine. Now to add a file.
$ dd if=/dev/urandom of=/mnt/loop/file bs=1M count=10240
$ ls -sh volume
12G volume
Cool, now I don't want the file.
$ rm /mnt/loop/file
$ ls -sh volume
12G volume
The free space is still taking up space, as expected, and $ fallocate -d volume
frees up 1gb.
My question is, how can I zero out the free space here without expanding the volume to the full size? $ dd if=/dev/zero
will expand it to full size, and with conv=sparse
makes it create a useless sparse file inside the volume.
TL;DR: Is there a way to make losetup
ignore writes of null blocks to null sectors, while allowing everything else?
fallocate -a
to free up the spaces. If you did not secure erase the file while it was still here, it would be painful to secure erase the entire disk afterwards, either byfstrim
or bydd sparse
the entire (loop) disk.