What I am doing
I am studying the filesystem image sparse tool: zerofree.
I imagine the steps to create the scenario should be that:
- create a file system image.
- use some way to fill it.
- clear it, but the actual space usage is not changed, which means unallocated or unused space exist on this fs.
- running zerofree, its actual space usage decrease.
But after running the zerofree to fs, the actual space usage is not shrinking.
Is there something I misunderstand? How can I do it correctly?
Any suggestion is helpful!
Record of what I tried
# root❯❯❯ dd if=/dev/zero of=fs.image bs=1M seek=1024 count=0
0+0 records in
0+0 records out
0 bytes copied, 4.8167e-05 s, 0.0 kB/s
# root❯❯❯ du -h fs.image
0 fs.image
# root❯❯❯ mkdir /mnt/test
# root❯❯❯ mkfs.ext3 fs.image
mke2fs 1.45.6 (20-Mar-2020)
Discarding device blocks: done
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: d65a10e7-4620-433b-a135-386d65acf414
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
root❯❯❯ du -h fs.image
33M fs.image
root❯❯❯ mount fs.image /mnt/test/
root❯❯❯ yes abcdefghijklmnopqrstuvwxyz0123456789 > /mnt/test/largefile
yes: standard output: No space left on device
root❯❯❯ du -h fs.image
1005M fs.image
root❯❯❯ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/loop0 976M 976M 0 100% /mnt/test
root❯❯❯ rm /mnt/test/largefile
rm: remove regular file '/mnt/test/largefile'? y
root@oe ~/../project-zerofree ❯❯❯ du -h fs.image
1007M fs.image
root❯❯❯ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/loop0 976M 1.3M 924M 1% /mnt/test
root❯❯❯ umount /mnt/test
root❯❯❯ du -h fs.image
1007M fs.image
root❯❯❯ zerofree -v fs.image
249255/249500/262144
root❯❯❯ du -h fs.image
1007M fs.image