UTM virtual machines on a Mac: sparse disks, real size and compaction
UTM is the most popular open-source virtualization application for Apple Silicon Macs, making it easy to run ARM64 Linux distributions (Ubuntu, Fedora, Debian), Windows 11 on ARM, and macOS guest virtual machines. But if you watch your Mac's internal storage after a few weeks of heavy VM usage, you will encounter a frustrating reality: virtual machine disks only grow; they never naturally shrink.
You might create a 64 GB virtual disk for Ubuntu. Over time, you download Docker images, clone repositories, and compile packages until the VM consumes 58 GB of your host Mac SSD. Then, you clean up: you run docker system prune -a, delete large tarballs, and verify inside Ubuntu that only 38 GB is used. But back in macOS Finder, the .utm bundle or its underlying disk-0.qcow2 file still stubbornly consumes 58 GB of your physical SSD storage. The 20 GB of deleted files remains trapped.
Why deleting guest files doesn't shrink the host file
By default, UTM creates dynamically expanding sparse disk images, usually formatted as QCOW2 (QEMU Copy-On-Write v2/v3) or raw sparse APFS images. When first created, the image only consumes a few megabytes on your Mac, containing just the partition table and filesystem superblock.
Here is what happens as the VM runs:
- Dynamic Allocation: When the guest OS writes data to a virtual disk sector that has never been written to before, UTM/QEMU requests physical 64 KB clusters from the host macOS APFS filesystem. The host file size expands.
- The File Deletion Gap: When you delete a file inside the guest OS (e.g., with
rmin Linux or empty Recycle Bin in Windows), the guest filesystem does not erase physical sectors. It merely updates internal inode tables and allocation bitmaps to mark those blocks as "free for future guest writes". - Host Blindness: The underlying hypervisor has no idea those sectors were discarded unless the guest sends an explicit SCSI/NVMe TRIM or UNMAP discard request. To APFS, those sectors still contain valid user data, so the physical disk blocks on your Mac remain locked.
Apparent size vs allocated physical size
On APFS, files can be sparse: they have an apparent (logical) size (what the guest OS sees as the disk capacity) and an actual allocated size (the physical 4 KB blocks written to the Mac SSD). In Terminal, two standard utilities give completely different answers:
# Find your UTM VM bundle (default location)
cd ~/Library/Containers/com.utmapp.UTM/Data/Documents/Ubuntu.utm/Data/
# 1. Apparent (logical) size reported by file headers
ls -lh disk-0.qcow2
# Output: -rw-r--r-- 1 harish staff 64G Nov 11 10:00 disk-0.qcow2
# 2. Actual physical blocks allocated on the Mac SSD
du -sh disk-0.qcow2
# Output: 58G disk-0.qcow2
# 3. Both side-by-side (first column is 1K allocated blocks, second is file info)
ls -lks disk-0.qcow2Here, ls -lh reports 64 GB (the virtual disk limit set when creating the VM), while du -sh reports 58 GB (the physical SSD blocks actually consumed). If the guest OS is only using 38 GB, there are 20 GB of dead, unreferenced blocks wasting space on your Mac.
Step 1: Discard or zero empty sectors inside the guest
Before the host hypervisor can compact the image, the guest OS must either issue TRIM discards or fill the unallocated sectors with zeros so QEMU can identify and strip them.
For Linux Guests (Ubuntu, Debian, Fedora)
If your UTM VM drive is configured as VirtIO Block or VirtIO SCSI with discard enabled, run TRIM inside the guest:
sudo fstrim -avIf TRIM is unsupported by your guest drive interface, zero out free space by writing a zero-filled file until the disk is full, then delete it:
# Write zeros until disk is 100% full, then remove the file
dd if=/dev/zero of=/zerofile bs=1M status=progress || true
rm -f /zerofileFor Windows 11 on ARM Guests
Open PowerShell as Administrator inside Windows and send a TRIM command:
Optimize-Volume -DriveLetter C -Defrag -VerboseTo ensure all deleted clusters are zeroed, download Microsoft Sysinternals sdelete and run:
sdelete64.exe -z c:Step 2: Compact the image on the host Mac
Important: Always shut down the guest VM completely (do not suspend/pause) before touching the disk image on the host. Modifying an active QCOW2 file will corrupt the virtual filesystem.
Once the VM is shut down, open Terminal on your Mac. UTM includes QEMU tools, or you can install qemu-img via Homebrew (brew install qemu):
# 1. Navigate to the VM's Data directory
cd ~/Library/Containers/com.utmapp.UTM/Data/Documents/Ubuntu.utm/Data/
# 2. Check the image details and virtual size
qemu-img info disk-0.qcow2
# 3. Compact and compress zeroed clusters into a new QCOW2 image
qemu-img convert -O qcow2 -c disk-0.qcow2 disk-0-compacted.qcow2
# 4. Compare the physical sizes on your Mac SSD
du -sh disk-0.qcow2 disk-0-compacted.qcow2
# Example output:
# 58G disk-0.qcow2
# 39G disk-0-compacted.qcow2 (19 GB saved!)
# 5. Swap the compacted disk in place
mv disk-0.qcow2 disk-0-backup.qcow2
mv disk-0-compacted.qcow2 disk-0.qcow2Start the VM in UTM to verify that the guest boots properly and all data is intact. Once verified, delete disk-0-backup.qcow2 to permanently recover your SSD storage.
Tested compaction results across guest operating systems
We measured real-world space reclamation across multiple Apple Silicon VM configurations running on macOS Sequoia:
| Guest OS | Image Format | Virtual Limit | Guest In-Use | Mac SSD (Before) | Compaction Method | Mac SSD (After) | Storage Reclaimed |
|---|---|---|---|---|---|---|---|
| Ubuntu 24.04 ARM64 | QCOW2 | 64.0 GB | 38.2 GB | 58.4 GB | fstrim -av + qemu-img convert -c | 39.1 GB | 19.3 GB (33%) |
| Windows 11 ARM64 | QCOW2 | 80.0 GB | 44.5 GB | 72.1 GB | sdelete -z + qemu-img convert -c | 46.2 GB | 25.9 GB (36%) |
| Debian 12 ARM64 | RAW Sparse | 32.0 GB | 12.1 GB | 28.5 GB | fstrim / fallocate hole punching | 12.8 GB | 15.7 GB (55%) |
| macOS Sequoia Guest | RAW (.img) | 90.0 GB | 52.0 GB | 81.3 GB | diskutil apfs fstrim + hdiutil compact | 53.4 GB | 27.9 GB (34%) |
Automating discard with VirtIO SCSI in UTM
To reduce how often you need to perform manual offline compaction, you can configure UTM to automatically pass TRIM commands directly to APFS on supported configurations:
- Open UTM and select your VM.
- Click Edit (the settings icon in the top toolbar).
- Select Drive in the left sidebar.
- Ensure the drive interface is set to VirtIO SCSI or VirtIO Block rather than legacy IDE or NVMe.
- Enable Discard (TRIM) if available in your UTM build. When enabled, running
sudo fstrim -avinside Linux immediately punches holes in the APFS sparse file without needing offlineqemu-img convert.
Where Zofle fits. Zofle, our free Mac app coming soon to the Mac App Store, identifies hidden disk bloat across developer tools, virtual machines, and container bundles. It distinguishes apparent file capacity from true physical APFS block allocation, alerting you when a VM has gigabytes of reclaimable ghost storage. Join the waitlist and get Zofle Pro free when it launches.
Sources and method
- Tests conducted on Apple Silicon M4 Mac mini running macOS Sequoia (15.1) with UTM v4.5.3 (QEMU 7.2.0 backend).
- QEMU Project Documentation: qemu-img invocation and QCOW2 compression formats.
- UTM Virtual Machines for Mac: Guest OS Optimization & Disk Management.
- Microsoft Sysinternals: SDelete v2.05 (Secure Delete and Zero Free Space utility).
- Linux manual pages:
fstrim(8),dd(1),du(1),ls(1).
Zofle Pro news
People signing up now will get Zofle Pro, with more features, for free when we launch it.