r/hashicorp•
hyper9410

Windows updates double packer image size

Hi,

I found Canonical MAAS for bare metal server deployment and it uses Packer for its image creation.

After modifying their template a bit and adding windows updates to it the finished image is more than double the size of that without updates.

How can I reduce the size of the image as it needs to be deployed over a 1GBE link over http on 30 servers at a time?

I use qemu 1.1.4 under Ubuntu and use post-processor "compress" to compress the image.

The original [canonical template](https://github.com/canonical/packer-maas/tree/main/windows)

For comparison:

Without updates: 8.9GB

With updates: 19.6GB

This is the final script which "cleans up" windows a bit.

net stop CryptSvc
net stop BITS
net stop dosvc
net stop wuauserv

$ACL = Get-ACL C:\Windows\SoftwareDistribution\Download
$Group = New-Object System.Security.Principal.NTAccount("Builtin", "Administrators")
$ACL.SetOwner($Group)
Set-Acl -Path C:\Windows\SoftwareDistribution\Download -AclObject $ACL
&cmd.exe /c rd /s /q C:\Windows\SoftwareDistribution\Download
New-Item -Path C:\Windows\SoftwareDistribution\Download -Type Directory 


vssadmin.exe delete shadows /All /Quiet

remove-item -Path c:\Windows\Prefetch\*.*
cleanmgr.exe /sagerun:1

$Host.UI.RawUI.WindowTitle = "Shrink winsxs folder"
Write-Host "Shrink winsxs folder"
Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase

Copy-Item -Path A:\Unattend.xml -Destination "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\Unattend.xml"

Optimize-Volume -DriveLetter C -ReTrim -Verbose

$Host.UI.RawUI.WindowTitle = "Running Sysprep..."
    if ($DoGeneralize) {
        $unattendedXmlPath = "$ENV:ProgramFiles\Cloudbase Solutions\Cloudbase-Init\conf\Unattend.xml"
        & "$ENV:SystemRoot\System32\Sysprep\Sysprep.exe" `/generalize `/oobe `/shutdown `/unattend:"$unattendedXmlPath"
        } else {
            $unattendedXmlPath = "$ENV:ProgramFiles\Cloudbase Solutions\Cloudbase-Init\conf\Unattend.xml"
            & "$ENV:SystemRoot\System32\Sysprep\Sysprep.exe" `/oobe `/shutdown `/unattend:"$unattendedXmlPath"
    }

Posted Dec 9, 2025, 9:47 AM UTC

22
Loading comments…