- Introduction
- How to Install KVM on Ubuntu 22.04
- Build the Windows VM
Introduction
This guide describes how to create a Windows Server 2019 cloud image for OpenStack using a KVM server on Ubuntu 22.04.
How to Install KVM on Ubuntu 22.04
Update Ubuntu 22.04
Update the local package index and upgrade the system.
apt-get update && upgrade -y
Check KVM Compatibility
Before installing KVM, make sure that KVM is compatible with your system to prevent future issues with KVM.
egrep -c '(vmx|svm)' /proc/cpuinfo
If the output you get is greater than 0, that means KVM is compatible with the system and can be installed.
Configure the Network Brigde
Make the changes according to your network to create the brigde network. Below is an example of the Netplan configuration file.
network:
ethernets:
ens160:
dhcp4: false
bridges:
br0:
dhcp4: false
interfaces: [ens160]
addresses: [10.5.0.23/24]
routes:
- to: default
via: 10.5.0.1
nameservers:
addresses: [8.8.8.8]
parameters:
stp: false
version: 2
Install KVM
Run the command below to install KVM and additional virtualization packages on Ubuntu 22.04.
apt install -y qemu-kvm libvirt-daemon-system virtinst libvirt-clients bridge-utils
- qemu-kvm – An package that provides hardware emulation on a kvm virtualization environment.
- libvirt-daemon-system – A package that provides configuration files required to run the libvirt daemon.
- virtinst – A set of command-line utilities for provisioning and modifying virtual machines.
- libvirt-clients – A set of client-side libraries and APIs for managing and controlling virtual machines & hypervisors from the command line.
- bridge-utils – A set of tools for creating and managing bridge devices. optional:
- libosinfo-bin – A GObject based library API for managing information about operating systems, hypervisors and the (virtual) hardware devices they can support.
Enable KVM services
Once the previous packages are installed, enable and start the Libvirt daemon.
systemctl enable --now libvirtd
systemctl start libvirtd
Verify if the service is running properly.
systemctl status libvirtd
You can get more details:
apt-get install -y libosinfo-bin
osinfo-query os
Add your user to the KVM and Libvirt Group
Now add your user to KVM and libvirt group to get up KVM and avoid running into issues. The user can be added to the KVM group using this command:
sudo usermod -aG kvm $USER
sudo usermod -aG libvirt $USER
Validate KVM is ready to allocate guest VMs
kvm-ok
output:
INFO: /dev/kvm exists
KVM acceleration can be used
Build the Windows VM
To build a Windows Server image, it will be necessary to inject the virtio drivers during the setup process, as the operating system itself does not recognize the virtual storage during the installation of the operating system. KVM does not have an option to attach two iso images, in the example below the virtio-win iso is attached as a disk.
Prior to run the following script, confirm that the virtio and windows iso files are located in the following path:
ls /var/lib/libvirt/boot/
output:
server2019.iso virtio-win.iso
Create VM template in KVM
To create the template run the following command:
virt-install \
--name Server2019 \
--description "Windows Server 2019 Template" \
--os-variant=win2k19 \
--ram 8192 \
--vcpus=4 \
--disk path=/var/lib/libvirt/images/windows2019.qcow2,bus=virtio,size=40 \
--cdrom=/var/lib/libvirt/isos/server2019.iso \
--disk /var/lib/libvirt/isos/virtio-win.iso,device=cdrom,bus=ide,unit=1 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--network bridge=br0,model=virtio
output:
Starting install...
Creating domain...Domain is still running. Installation may be in progress.
To confirm the VM is running
virsh list --all
To identify which port the VM is running on, in this case in port 5900 + 0
virsh vncdisplay Server2019
output:
:0
If you do not have VNC Viewer installed on your computer, download from VNC Viewer Portal and install it. Then, when open VNC Viewer you will connect with the following port:
Install Operating System
Once you connect to the VM, you will initiate the operating system installation. Click Next.
Click Install Now.
Select the operating system with the Desktop Experience and click Next.
Accept license. Click Next.
Click Custom: Install Windows only (advanced).
Click Load driver and browse inside CD Drive (E:) virtio-win-0.1.229 to find the following folder \viostor\2k19\amd64**, then click OK**.
Note: Select the folder that correspond to the Operating System you are installing in this case is 2k19 for Windows Server 2019.
It will show the following driver viostor.inf. Click Next.
Click Next.
The installation of the operating system starts and it will automatically shut down.
Install Virtio Drivers
Open windows search, then type devmgmt.msc
. In the Device Manager window locate the hardware components do not have the latest drivers installed.
Ethernet controller
Select Ethernet Controller, then Update Driver Software.
Click Browse for drivers on your computer, browse inside CD Drive (E:) virtio-win-0.1.229 to find the following folder \NetKVM\2k19\amd64\, then click Next.
Once it finds and install the driver. Click Close.
PCI Device
Repeat the same steps for PCI Device, click Update Driver Software.
Click Browse for drivers on your computer, browse inside CD Drive (E:) virtio-win-0.1.229 to find the following folder \Balloon\2k19\amd64\, then click Next.
Once it finds and install the driver. Click Close.
Make sure all drivers are installed as shown.
Template Customization
Customize the Windows Image based on your organization needs for example:
Change Time Zone
Open Control Panel > Clock, Language and Region > Date and Time > Change the time zone to Eastern Time (US & Canada)
Install Chrome
Download and install google chrome.
Install the latest Windows Fixes
Open Server Manager > Local Server> Windows Update > Check for updates and install the fixes.
Remove operating system and virtio ISO from the VM
Shutdown the VM and type the following command:
virsh edit Server2019
Once you get into the VM's configuration, delete the Windows Server 2019 and virtio-win isos from the image. Then, save the file.
virsh edit Server2019
output
Domain 'Server2019' XML configuration edited.
Install Cloudbase-init
Open Chrome and enter Cloudbase-init Download. click Download the Installer.
Skip the registration click No, just show me the downloads. Download cloudbase-init x64 stable version
Look for the cloudbase-init downloaded file. Right click CloudbaseInitSetup_1_1_4_x64, then click Install.
Click Next.
Check the License Agreement box. Click Next.
Click Next.
Leave the default Admin user and Administrator group. Click Next.
Click Install.
Check both boxes Run Sysprep to create a generalized image and Shutdown when Sysprep terminates. Click Finish.
The Sysprep process starts
Wait until the process finishes and look when the VM is shutdown to start copying the image to the cloud.
virsh list --all
Exporting the Windows Server 2019 Image to Breqwatr Cloud
Make the image thinner with the following command:
qemu-img convert -f qcow2 -O qcow2 windows2019.qcow2 windows2019-thin.qcow2
The image file was converted from 41 GB to 11 GB.
ls -lah | grep -i windows2019
-rw------- 1 root root 41G Apr 13 15:23 windows2019.qcow2
-rw-r--r-- 1 root root 18G Apr 13 15:29 windows2019-thin.qcow2
Please follow the steps described in this document to create the Windows image within Breqwatr. How to Create and Manage Images in Arcus