When using Linux in Virtualbox and dynamically-allocated disk, it keeps growing even though almost half of space is free:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        94G   12G   78G  13% /

This disk takes >24G on disk and keeps growing, filesystem ext4.


In order to discard unused blocks on filesystem there is a command fstrim, part of util-linux package. But to use it on Virtualbox, it is needed to enable discard option on your virtual disk by stopping you VM and running the following command:

VBoxManage storageattach <VM name> --storagectl "SATA" --port 0 --discard on

where "SATA" and 0 are parameters of your disk controller, can be checked in VB settings for your specific VM.

Then boot your machine and run

# fstrim /

To automate this process, add this command to cron, once in a week is usually enough.

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.