Compacting VHDX Storage
The Kubemaster VM uses a dynamically expanding VHDX. It grows when data is written but does not shrink when data is deleted (the "High Water Mark" issue). Use k2s system compact to reclaim wasted space after operations like importing/deleting container images or downloading large files.
Supported setups
k2s system compact works with standard k2s and Linux-only setups.
It is not available for WSL-based or build-only installations (no Hyper-V VHDX present).
How It Works
- fstrim – Runs inside the VM (if running) to notify Hyper-V which blocks are free.
- Stop – Cluster is stopped for compaction.
- Optimize-VHD – Physically shrinks the VHDX file on the Windows host.
- Restart – Cluster is restarted by default (skip with
--no-restart).
Usage
Skip confirmation prompts:
Compact but keep cluster stopped afterwards:
Troubleshooting
VHDX locked / still mounted:
No space saved: The VHDX may already be compacted or contain mostly active data.