Command line tool
vdtrim is the command line edition of Virtual Disk Trim, for scripts, scheduled tasks and servers without a desktop. It uses the same engine and the same licence as the window application, and has a few extra features: choosing the block size and the layout of a VMDK, zeroing free space, and extra checks for a trim in place.
vdtrim trim [options] <image> <output>
vdtrim trim --replace [options] <image>
vdtrim trim --in-place [options] <image>
vdtrim batch [options] <image or folder>...
vdtrim recover <image>
vdtrim license <key file> | show | remove
Run without arguments, vdtrim prints this summary with all options. batch, recover, the JSON report and the exit codes are described in Batch mode and scripting.
Analysing an image
analyse reports what is in an image and what a trim would free. It makes no changes and needs no licence.
File: D:\VMs\openSUSE Tumbleweed.vmdk
File size: 747.6 MB (783941632 bytes)
Container: VMDK, 64.0 KB blocks, 512-byte sectors
Virtual size: 24.0 GB (25769803776 bytes)
Blocks: 393216 total, 11913 present, 0 zero, 381303 unallocated
Partitioning: GPT
1. GPT: BIOS boot at 1.0 MB, 2.0 MB
Name: p.legacy
Not trimmed: no recognised file system (copied verbatim)
2. GPT: EFI system at 3.0 MB, 512.0 MB
Name: p.UEFI
File system: FAT16 "EFI", 8.0 KB clusters
Used: 4.1 MB (0%)
Free: 507.5 MB (99%)
3. GPT: Unknown {4F68BCE3-...} at 515.0 MB, 23.4 GB
Name: p.lxroot
File system: btrfs crc32c "ROOT", 4.0 KB clusters
Used: 659.0 MB (2%)
Free: 22.8 GB (97%)
Reclaimable at 64.0 KB blocks: 59.3 MB (7% of the file)
Reclaimable is what a trim would free. If the trim writes a different block size, a second line gives that figure. An image that cannot be trimmed prints Declined: with the reason.
Trimming
vdtrim trim "D:\VMs\Windows 10.vhdx" "E:\Trimmed\Windows 10.vhdx"
:: replace: write beside the image, verify, swap it in
vdtrim trim --replace "D:\VMs\Windows 10.vhdx"
:: trim the image file itself, with only a little free space
vdtrim trim --in-place "D:\VMs\Windows 10.vhdx"
The copy form refuses to write over an existing file. The replace form keeps the image’s format and layout, always verifies, and declines when the result would be no smaller. A run interrupted with Ctrl+C removes its unfinished output and leaves the image untouched.
The in-place form changes the image file itself and keeps no original, so back the image up first. It needs only a little free space for its journal and always verifies. A VHDX with larger blocks is trimmed at 1 MB. An interrupted run is finished or undone by vdtrim recover.
| Option | Effect |
|---|---|
--format fmt |
The format of the output: raw, vhdx, vhd, vdi, vmdk or qcow2. By default it follows the extension of the output name. Not with --replace or --in-place. |
--discard list |
Leave out page files, inactive hibernation files, swap space, or all three; several are separated by commas. |
--zero-free |
Also fill with zeros the free space of the recognised file systems inside the blocks that are kept. Not with --in-place. |
--block-size n |
The block size of the output, for example 512K, 1M or 2M. The default is the format’s own: 1 MB for VHDX, VDI and raw, 2 MB for VHD, 64 KB for VMDK and qcow2. With --in-place, only for a VHDX: the block it is trimmed at, 1 MB by default. |
--layout how |
For VMDK output: keep (the default) leaves a split disk split, single writes one file, split cuts the disk into pieces of 2 GB. Not with --replace or --in-place. |
--zero-blocks |
With --in-place: also free kept blocks that hold only zeros, which reads every kept block first. A copy leaves them out by itself. |
--verify-all |
With --in-place: take a checksum of every kept block before the trim writes anything, and read them all again after it. |
--no-verify |
Skip the comparison of the output with the source. Not with --replace or --in-place. |
--json file |
Also write the report as JSON; - prints it in place of the text. |
--progress |
Show the percentage done on standard error. |
--password - |
Ask for the password or recovery key of a BitLocker volume, to trim it too. Read from standard input when piped. |
--recovery-key - |
The same, for a recovery key only. |
--password-file file, --recovery-key-file file |
Read them from a UTF-8 file, one per line. The image is declined if none of them fits. |
A password is never taken on the command line itself, where others could see it.
Converting between formats
Because the output format follows the name of the output, a trim can also move a disk from one hypervisor to another in one pass:
vdtrim trim server.vmdk server.vhdx
:: VirtualBox to QEMU, dropping page and swap files
vdtrim trim --discard page,swap desktop.vdi desktop.qcow2
:: a split VMware disk into a single file
vdtrim trim --layout single "Kali.vmdk" "Kali-single.vmdk"
For a split VMware disk, name the descriptor file — the small .vmdk file without a number, not one of its pieces. A disk written in another format gets a new identity, as it would from the hypervisor’s own converter, and has to be attached to the virtual machine in place of the old one. The guide How to convert a virtual disk compares this with the usual converters.
A trim removes whole blocks that hold nothing, but a block that is partly in use is kept as it is, including whatever deleted files left in its free part. Before handing an image to someone else, add --zero-free to clear the free space of the recognised file systems as well. It is not a secure wipe: unrecognised volumes, gaps between partitions and the unused tail of a file’s last cluster are left as they are.
Licence
vdtrim license mykey.txt
:: show whose licence is installed, or remove it
vdtrim license show
vdtrim license remove
Analysing, listing with batch and recover work without a licence; trimming requires a licence. A key entered in the window interface also serves the command line tool of the same user, and vice versa.