|
| 1 | +--- |
| 2 | +title: Prepare a custom image for Microsoft Dev Box |
| 3 | +titleSuffix: Microsoft Dev Box |
| 4 | +description: Learn how to prepare a custom Windows image that meets all Microsoft Dev Box requirements, including image definition configuration, OS requirements, disk configuration, and sysprep settings. |
| 5 | +services: dev-box |
| 6 | +ms.service: dev-box |
| 7 | +author: RoseHJM |
| 8 | +ms.author: rosemalcolm |
| 9 | +ms.date: 03/18/2026 |
| 10 | +ms.topic: how-to |
| 11 | +ai-usage: ai-assisted |
| 12 | +ms.custom: awp-ai |
| 13 | + |
| 14 | +#customer intent: As a platform engineer, I want to prepare a custom Windows image that meets all Microsoft Dev Box requirements so that I can use it to create consistent dev box definitions. |
| 15 | +--- |
| 16 | + |
| 17 | +# Prepare a custom image for Microsoft Dev Box |
| 18 | + |
| 19 | +This article explains how to prepare a custom Windows image so it passes Microsoft Dev Box image validation and can be used in dev box definitions. |
| 20 | + |
| 21 | +If your image doesn't meet Dev Box requirements, validation can fail with an error like: |
| 22 | + |
| 23 | +```console |
| 24 | +Image failed to validate. SourceImageInvalid: The image is not valid. At this time, only generalized generation 2 Windows Enterprise (10, 11) images are supported. |
| 25 | +``` |
| 26 | + |
| 27 | +## Prerequisites |
| 28 | + |
| 29 | +- An Azure subscription. |
| 30 | +- An Azure Compute Gallery with permissions to create image definitions and image versions. |
| 31 | +- Permissions to create and manage gallery resources and role assignments, such as **Owner** or **Contributor** on the subscription or resource group that contains the gallery. |
| 32 | +- Permissions to create or update Dev Box resources, such as **DevCenter Project Admin** (or higher) on the dev box project. |
| 33 | + |
| 34 | +## Configure the image definition |
| 35 | + |
| 36 | +Configure these settings when you create the Azure Compute Gallery image definition. You can't change these settings after the image definition is created. |
| 37 | + |
| 38 | +- Security type: Trusted Launch |
| 39 | +- VM generation: Generation 2 (Hyper-V v2) |
| 40 | +- OS state: Generalized |
| 41 | +- (Recommended) Enable hibernation support |
| 42 | + |
| 43 | +The following Azure CLI example shows how to create an image definition with the required settings: |
| 44 | + |
| 45 | +```azurecli |
| 46 | +az login |
| 47 | +az account set --subscription "<subscription-id>" |
| 48 | +
|
| 49 | +az sig image-definition create \ |
| 50 | + --resource-group "your-resource-group" \ |
| 51 | + --gallery-name "your-gallery-name" \ |
| 52 | + --gallery-image-definition "your-image-definition" \ |
| 53 | + --publisher "YourPublisher" \ |
| 54 | + --offer "YourOffer" \ |
| 55 | + --sku "YourSKU" \ |
| 56 | + --os-type Windows \ |
| 57 | + --os-state Generalized \ |
| 58 | + --hyper-v-generation V2 \ |
| 59 | + --features "IsHibernateSupported=true" "SecurityType=TrustedLaunch" |
| 60 | +``` |
| 61 | + |
| 62 | +> [!IMPORTANT] |
| 63 | +> Dev Box image requirements can be stricter than requirements for deploying a VM directly. For baseline gallery requirements and additional performance guidance, see [Configure Azure Compute Gallery for Microsoft Dev Box](how-to-configure-azure-compute-gallery.md). |
| 64 | +
|
| 65 | +## Verify operating system requirements |
| 66 | + |
| 67 | +Use a Windows operating system that meets all requirements: |
| 68 | + |
| 69 | +- Windows 10 Enterprise or Windows 11 Enterprise (supported version) |
| 70 | +- Single-session image (multi-session images aren't supported) |
| 71 | +- Standard edition (not N edition, not LTSC) |
| 72 | +- General availability release |
| 73 | + |
| 74 | +> [!TIP] |
| 75 | +> Start from a Windows 365 or Dev Box-compatible Azure Marketplace image (for example, a Visual Studio image), then customize it for your organization. |
| 76 | +
|
| 77 | +For supported Windows versions and other baseline image requirements, see [Configure Azure Compute Gallery for Microsoft Dev Box](how-to-configure-azure-compute-gallery.md#image-version-requirements). |
| 78 | + |
| 79 | +## Verify disk configuration |
| 80 | + |
| 81 | +Make sure the image meets these disk requirements: |
| 82 | + |
| 83 | +- OS disk size is 64 GB (default). Dev Box adjusts the OS disk size during provisioning. |
| 84 | +- No data disks are attached to the VM before you capture the image. |
| 85 | +- No recovery partition is present. |
| 86 | +- BitLocker isn't enabled. |
| 87 | +- No disk encryption set is applied to the image. Customer-managed keys (CMK) aren't supported for Dev Box images. Use platform-managed keys (PMK). |
| 88 | + |
| 89 | +### Remove a recovery partition (if present) |
| 90 | + |
| 91 | +If your source VM has a recovery partition, remove it before you run Sysprep and capture the image. |
| 92 | + |
| 93 | +```console |
| 94 | +diskpart |
| 95 | +select disk 0 |
| 96 | +list partition |
| 97 | +select partition <recovery_partition_number> |
| 98 | +delete partition override |
| 99 | +exit |
| 100 | +``` |
| 101 | + |
| 102 | +> [!WARNING] |
| 103 | +> Deleting partitions is destructive and can make the VM unbootable if you select the wrong partition. Validate the partition number carefully before you delete it. |
| 104 | +
|
| 105 | +## Verify pre-Sysprep requirements |
| 106 | + |
| 107 | +Before you run Sysprep, confirm that the source VM has never been joined or enrolled in any identity or management service. |
| 108 | + |
| 109 | +- Never joined to Active Directory |
| 110 | +- Never joined to Microsoft Entra ID |
| 111 | +- Never enrolled in Microsoft Intune |
| 112 | +- Never enrolled for co-management |
| 113 | + |
| 114 | +For background and troubleshooting, see [Sysprep won't run correctly on MDM-enrolled devices](/troubleshoot/mem/intune/device-enrollment/troubleshoot-sysprep-windows-10-device-enrolled-mdm). |
| 115 | + |
| 116 | +## Run Sysprep |
| 117 | + |
| 118 | +Run Sysprep with these required options: |
| 119 | + |
| 120 | +- `/generalize` removes unique system information, such as SIDs. |
| 121 | +- `/oobe` configures Windows to boot to the out-of-box experience. |
| 122 | +- `/mode:vm` optimizes the image for VM deployment and avoids a lengthy driver search during first boot. |
| 123 | + |
| 124 | +### Manual capture |
| 125 | + |
| 126 | +Use `/shutdown` when you're manually capturing an image from the VM. |
| 127 | + |
| 128 | +```console |
| 129 | +C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /mode:vm /shutdown |
| 130 | +``` |
| 131 | + |
| 132 | +### Packer capture |
| 133 | + |
| 134 | +If you're using HashiCorp Packer to build the image, use the quiet options because Packer controls shutdown and capture. |
| 135 | + |
| 136 | +```console |
| 137 | +C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /mode:vm /quiet /quit |
| 138 | +``` |
| 139 | + |
| 140 | +For more information about Sysprep options, see [Sysprep Command-Line Options](/windows-hardware/manufacture/desktop/sysprep-command-line-options?view=windows-11#modevm&preserve-view=true). |
| 141 | + |
| 142 | +## Apply performance optimizations |
| 143 | + |
| 144 | +The following optimizations are optional, but we recommend them to reduce provisioning time and improve startup performance. |
| 145 | + |
| 146 | +### Enable Virtual Machine Platform |
| 147 | + |
| 148 | +```powershell |
| 149 | +Enable-WindowsOptionalFeature -FeatureName VirtualMachinePlatform -Online |
| 150 | +``` |
| 151 | + |
| 152 | +### Disable reserved storage |
| 153 | + |
| 154 | +```console |
| 155 | +DISM.exe /Online /Set-ReservedStorageState /State:Disabled |
| 156 | +``` |
| 157 | + |
| 158 | +### Clean up the component store |
| 159 | + |
| 160 | +```console |
| 161 | +DISM.exe /Online /Cleanup-Image /StartComponentCleanup |
| 162 | +``` |
| 163 | + |
| 164 | +### Defragment the OS disk and optimize boot |
| 165 | + |
| 166 | +```console |
| 167 | +defrag c: /FreespaceConsolidate /Verbose |
| 168 | +defrag c: /BootOptimize /Verbose |
| 169 | +``` |
| 170 | + |
| 171 | +### Disable scheduled defragmentation |
| 172 | + |
| 173 | +```powershell |
| 174 | +Disable-ScheduledTask -TaskName "ScheduledDefrag" -TaskPath "\\Microsoft\\Windows\\Defrag" |
| 175 | +``` |
| 176 | + |
| 177 | +> [!NOTE] |
| 178 | +> For more performance guidance that can help reduce first-boot time, see [Configure Azure Compute Gallery for Microsoft Dev Box](how-to-configure-azure-compute-gallery.md#reduce-provisioning-and-startup-times). |
| 179 | +
|
| 180 | +## Configure Azure Compute Gallery permissions |
| 181 | + |
| 182 | +To use a gallery image in a dev box definition, Dev Box validates the image and replicates it to the regions required by your network connections. The Dev Box service performs these actions by using the dev center's managed identity. |
| 183 | + |
| 184 | +At a minimum, make sure that: |
| 185 | + |
| 186 | +- You're using a standard Azure Compute Gallery (not a community gallery). |
| 187 | +- Your dev center has a managed identity configured. |
| 188 | +- The dev center managed identity has the **Contributor** role on the gallery. |
| 189 | +- Your image is replicated to the target regions where dev boxes are created. |
| 190 | + |
| 191 | +For detailed gallery configuration steps, see [Configure Azure Compute Gallery for Microsoft Dev Box](how-to-configure-azure-compute-gallery.md). |
| 192 | + |
| 193 | +## Configure Packer (if applicable) |
| 194 | + |
| 195 | +If you use HashiCorp Packer with the `azure-arm` builder, make sure your `source` configuration creates a Trusted Launch VM. |
| 196 | + |
| 197 | +Ensure your `source "azure-arm"` block includes: |
| 198 | + |
| 199 | +- `secure_boot_enabled = true` |
| 200 | +- `vtpm_enabled = true` |
| 201 | +- `security_type = "TrustedLaunch"` |
| 202 | +- Base image is Windows 10/11 Enterprise from Marketplace |
| 203 | +- Target image definition has Trusted Launch security type |
| 204 | + |
| 205 | +The following example shows the required settings: |
| 206 | + |
| 207 | +```hcl |
| 208 | +source "azure-arm" "devbox" { |
| 209 | + # Trusted Launch (REQUIRED) |
| 210 | + secure_boot_enabled = true |
| 211 | + vtpm_enabled = true |
| 212 | + security_type = "TrustedLaunch" |
| 213 | + |
| 214 | + # VM settings |
| 215 | + vm_size = "Standard_D8s_v5" |
| 216 | + license_type = "Windows_Client" |
| 217 | + os_type = "Windows" |
| 218 | + |
| 219 | + # Base image |
| 220 | + image_publisher = "MicrosoftWindowsDesktop" |
| 221 | + image_offer = "windows-11" |
| 222 | + image_sku = "win11-23h2-ent" |
| 223 | + image_version = "latest" |
| 224 | + |
| 225 | + # Gallery destination |
| 226 | + shared_image_gallery_destination { |
| 227 | + gallery_name = "your_gallery_name" |
| 228 | + image_name = "your_image_definition" |
| 229 | + image_version = "1.0.0" |
| 230 | + replication_regions = ["eastus", "westus2"] |
| 231 | + storage_account_type = "Premium_LRS" |
| 232 | + } |
| 233 | +} |
| 234 | +``` |
| 235 | + |
| 236 | +A reference implementation is available in the [carmada-dev/demo-images](https://github.com/carmada-dev/demo-images) repository. |
| 237 | + |
| 238 | +## Quick reference |
| 239 | + |
| 240 | +Use the following table to quickly verify the most common Dev Box image validation requirements. |
| 241 | + |
| 242 | +| Setting | Required value | |
| 243 | +|---|---| |
| 244 | +| Security type | Trusted Launch | |
| 245 | +| VM generation | Gen2 | |
| 246 | +| OS state | Generalized | |
| 247 | +| OS | Windows 10/11 Enterprise (single-session) | |
| 248 | +| OS disk | 64 GB default, no data disks | |
| 249 | +| Recovery partition | None | |
| 250 | +| Encryption | Platform-managed keys (no BitLocker) | |
| 251 | +| Sysprep options | `/generalize /oobe /mode:vm` | |
| 252 | +| Active Directory domain join or Microsoft Entra ID join | Never joined | |
| 253 | +| MDM enrollment | Never enrolled | |
| 254 | +| Gallery type | Standard (not community) | |
| 255 | + |
| 256 | +## Related content |
| 257 | + |
| 258 | +- [Configure Azure Compute Gallery for Microsoft Dev Box](how-to-configure-azure-compute-gallery.md) |
| 259 | +- [Authenticate to Microsoft Dev Box](how-to-authenticate.md) |
| 260 | +- [Microsoft Dev Box architecture and key concepts](concept-dev-box-architecture.md) |
| 261 | +- [Trusted Launch for Azure virtual machines](/azure/virtual-machines/trusted-launch) |
| 262 | +- [Sysprep Command-Line Options](/windows-hardware/manufacture/desktop/sysprep-command-line-options) |
| 263 | +- [carmada-dev/demo-images](https://github.com/carmada-dev/demo-images) |
0 commit comments