3

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 ?

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.

| improve this answer | |
  • It is still simply write some files with 00h. <github.com/GIJack/secure_delete/blob/master/sfill.c#L198> – Galaxy Sep 17 at 1:31
  • True, I overread the line about btrfs with compression. I'll edit it. – damian101 Sep 18 at 10:44
  • 1
    filling the filesystem Be careful. COW filesystems tend to stop allowing any updates at all when they get completely full. – Andrew Henle Sep 18 at 11:28
  • It seems set compression to none is a way. Another way should be to use some btrfs API. – Galaxy Oct 14 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.