Creating Windows Golden Image on KVM host¶
Reuirements¶
- Windows ISO file
- VirtIO Drivers
- KVM host
- virtual machine
Get Windows ISO File¶
Download Windows Server or 10/11 from microsoft official website
Note
Path for windows ISO file /var/lib/libvirt/images
Download virtio drivers¶
Download Virtio Drivers Download Now
Or run the command
wget -P /var/lib/libvirt/images/ "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.285-1/virtio-win.iso"
KVM host¶
Check if host is capable of 1. Connecting to KVM host 2. Checking if virtualiztion is enabled 3. Check if kvm or libvirt packages are installed
Deploy a VM¶
Set VM Name
Set Memory size
Set nCPU
Set Disk Size
Set Windows Path
Set virtio driver path
Run the command¶
virt-install \
--name ${vm_name}$ \
--ram ${vm_mem} \
--vcpus ${vm_vcpu} \
--cpu host-passthrough \
--machine q35 \
--os-variant win2k22 \
--disk path=/var/lib/libvirt/images/${vm_name}$.qcow2,bus=virtio,size=${vm_disk_size},cache=writeback \
--cdrom ${win_img_path} \
--disk path=${virtio_driver_path},device=cdrom \
--network bridge=virbr0,model=virtio \
--graphics vnc \
--boot uefi \
--features smm.state=on,hyperv_vapic=on,hyperv_relaxed=on,hyperv_spinlocks=on,kvm_hidden=on
Go through the installation process¶
Complete the initial setup of the windows OS If disk is not detected, install virtio drivers for AMD64(CPU arch) and NetKVM
Install virtio drivers
Install/Remove application or packages that are required/not required
Enable RDP
Generalizing Windows OS using sysprep¶
Launch CMD as Administrator
Run
Info
Sysprep will generalize the system and shutsdown the VM
Note
The qcow2 file of the vm can become be used as windows machine template
Errors and Troubleshooting for windows generalizing¶
For below error
Error
Fix
Run the below commmand in powershell admin
Preparing template from windows.qcow2 file¶
Note
As a best practice we can make the windows template to be ReadOnly