Automating Windows installation with sysprep

You can use Microsoft DVD images and sysprep to automate the installation, setup, and software provisioning of Windows virtual machines.

Using a Windows DVD to create a VM disk image

Microsoft does not provide disk images for download, but you can create a disk image using a Windows DVD. This disk image can then be used to create virtual machines.

Procedure

  1. In the OKD Virtualization web console, click StoragePersistentVolumeClaimsCreate PersistentVolumeClaim With Data upload form.

  2. Select the intended project.

  3. Set the Persistent Volume Claim Name.

  4. Upload the VM disk image from the Windows DVD. The image is now available as a boot source to create a new Windows VM.

Using a disk image to install Windows

You can use a disk image to install Windows on your virtual machine.

Prerequisites

  • You must create a disk image using a Windows DVD.

  • You must create an autounattend.xml answer file. See the Microsoft documentation for details.

Procedure

  1. In the OKD console, click VirtualizationCatalog from the side menu.

  2. Select a Windows template and click Customize VirtualMachine.

  3. Select Upload (Upload a new file to a PVC) from the Disk source list and browse to the DVD image.

  4. Click Review and create VirtualMachine.

  5. Clear Clone available operating system source to this Virtual Machine.

  6. Clear Start this VirtualMachine after creation.

  7. On the Sysprep section of the Scripts tab, click Edit.

  8. Browse to the autounattend.xml answer file and click Save.

  9. Click Create VirtualMachine.

  10. On the YAML tab, replace running:false with runStrategy: RerunOnFailure and click Save.

The VM will start with the sysprep disk containing the autounattend.xml answer file.

Generalizing a Windows VM using sysprep

Generalizing an image allows that image to remove all system-specific configuration data when the image is deployed on a virtual machine (VM).

Before generalizing the VM, you must ensure the sysprep tool cannot detect an answer file after the unattended Windows installation.

Procedure

  1. In the OKD console, click VirtualizationVirtualMachines.

  2. Select a Windows VM to open the VirtualMachine details page.

  3. Click ConfigurationDisks.

  4. Click the Options menu kebab beside the sysprep disk and select Detach.

  5. Click Detach.

  6. Rename C:\Windows\Panther\unattend.xml to avoid detection by the sysprep tool.

  7. Start the sysprep program by running the following command:

    1. %WINDIR%\System32\Sysprep\sysprep.exe /generalize /shutdown /oobe /mode:vm
  8. After the sysprep tool completes, the Windows VM shuts down. The disk image of the VM is now available to use as an installation image for Windows VMs.

You can now specialize the VM.

Specializing a Windows virtual machine

Specializing a virtual machine (VM) configures the computer-specific information from a generalized Windows image onto the VM.

Prerequisites

  • You must have a generalized Windows disk image.

  • You must create an unattend.xml answer file. See the Microsoft documentation for details.

Procedure

  1. In the OKD console, click VirtualizationCatalog.

  2. Select a Windows template and click Customize VirtualMachine.

  3. Select PVC (clone PVC) from the Disk source list.

  4. Specify the Persistent Volume Claim project and Persistent Volume Claim name of the generalized Windows image.

  5. Click Review and create VirtualMachine.

  6. Click the Scripts tab.

  7. In the Sysprep section, click Edit, browse to the unattend.xml answer file, and click Save.

  8. Click Create VirtualMachine.

During the initial boot, Windows uses the unattend.xml answer file to specialize the VM. The VM is now ready to use.

Additional resources