A freshly installed Windows 10 image is usually 15 to 20 GB before compression, so a clean install will not fit a 5 GB limit by default. This guide shrinks a Windows 10 bare-metal image by removing reclaimable data from the source system, then capturing it with maximum compression.
Applies to: Windows 10 (x64) reference system, deployed to a dedicated or bare-metal server. Results vary with installed software, so check the final size rather than assuming 5 GB.
Why the image is large
Common space consumers are the WinSxS component store with superseded updates, hiberfil.sys, pagefile.sys, temporary files, and previously used disk blocks that still hold old data. Install only what the server needs, and leave out user data and installers.
Before you start
- Work on a reference system, not a live production server. Some steps cannot be undone.
- Take a snapshot or backup of the reference system.
- Use an administrator Command Prompt for every command below.
Step 1: Remove unused applications and files
- Uninstall software, drivers, and Windows features you do not need.
- Empty the Recycle Bin and delete large installers and downloads.
- Run Disk Cleanup, select Clean up system files, and choose Windows Update Cleanup, Temporary files, and Delivery Optimization files.
Step 2: Clean up the component store
Check whether cleanup will help:
DISM /Online /Cleanup-Image /AnalyzeComponentStoreIf cleanup is recommended, run:
DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBaseWarning: /ResetBase removes all superseded component versions. Existing update packages can no longer be uninstalled, although future updates are not blocked. Install all required updates and confirm the system is stable first. Never delete the WinSxS folder manually.
Step 3: Disable hibernation
If the server does not use hibernation or Fast Startup, run:
powercfg /hibernate offThis removes hiberfil.sys. A server does not need a hibernation file.
Step 4: Enable Compact OS
compact /compactos:alwaysConfirm with compact /compactos:query. Compact OS stores Windows files in compressed form. It can take 15 to 20 minutes. To reverse it, run compact /compactos:never.
Step 5: Shrink the page file (optional)
Set the page file to a small fixed size, or let the deployed server recreate it. Skip this step if the application needs a large page file.
Step 6: Zero the free space (disk images only)
Use this step only if your provider accepts a raw, VHD, or qcow2 disk image. It is unnecessary for WIM files.
- Download SDelete from Microsoft Sysinternals.
- Run it. This temporarily fills free space, so make sure the drive is not nearly full:
sdelete64.exe -z C:The -z option zeroes free space so compression and sparse-image tools can discard it.
Step 7: Capture or convert with maximum compression
Option A: WIM image.
Boot the reference system into Windows PE and capture the OS volume to a second drive:
DISM /Capture-Image /ImageFile:D:\win10.wim /CaptureDir:C:\ /Name:"Windows 10" /Compress:max /CheckIntegrity/Compress:max gives the best compression but takes longer. Use /ConfigFile with a WimScript.ini file to exclude folders you do not need.
Option B: Disk image.
If you already have a raw or other disk image, convert it to compressed qcow2 on a Linux machine with qemu-img:
qemu-img convert -c -p -O qcow2 win10.raw win10.qcow2Compression with -c applies to qcow2 only, and compressed clusters are read-only; rewritten data is stored uncompressed.
Verify the result
- Check the file size: dir D:\win10.wim (WIM) or qemu-img info win10.qcow2 (qcow2).
- Deploy to a test server and confirm that Windows boots and applications run.
If the image is still above 5 GB:
- Run DISM /Online /Cleanup-Image /AnalyzeComponentStore again and look for leftover reclaimable packages.
- Check the biggest folders with dir C:\ /s or a disk-usage tool and remove unneeded data.
- Remove optional Windows features and built-in apps you do not need, then repeat Steps 2 and 7.
- Confirm that you captured only the OS volume and did not include extra drives or recovery partitions.