5

This is for guest Linux under VMware Workstation.

I tried vmware-toolbox-cmd disk shrink / on btrfs which mounted as compress=zstd,noatime,nodiratime,space_cache,ssd,discard. However, the image just expanded to maximum size and cannot be shrinked.

It seems compressed btrfs will not write zero file as zeros.

I find there are some ioctl patches on zero-fill at https://lwn.net/ml/linux-btrfs/aed736d257f7e91cf3b0cf4d1fdfc247212d8bf7.1524233244.git.dsterba@suse.com/.

How can I call BTRFS_CLEAR_OP_ZERO_NOUNMAP from guest Linux ?

Galaxy
  • 237

2 Answers2

1

As far as I know there is no direct way to fill the unused space of a Btrfs filesystem with zeros. However, you can achieve the same thing by just filling the filesystem with zero filled files and then deleting them, sfill is one way to do that: sfill -llz \dev\X. Sfill is part of the secure-delete toolkit: https://github.com/GIJack/secure_delete.

But as you noted that won't work with filesystem compression enabled, because there is nothing easier to compress than a bunch of zeros. You'd have to remount the filesystem without the compress=zstd mount option to make it work. Or set the no compression flag to the root of your Btrfs file system with btrfs property set <object> compression "", if your system is on Btrfs subvolumes you have to mount the filesystem root first. That flag can currently only be removed with chattr -c.

VMWare images don't shrink automatically, but there are ways to shrink them.

0

I'll add my answer from here

mkdir -p btrfs-zero
btrfs property set btrfs-zero compression none
cat /dev/zero > btrfs-zero/zero
rm btrfs-zero/zero
laktak
  • 5,946