Virtual machines and containers are two popular virtualization technologies.

The virtual machine emulates the hardware of the machine, including the complete operating system and applications. Once it is started, all the resources allocated to it will be occupied. A container is a process running on a host. Multiple containers use the operating system kernel of the same host. Containers start faster and consume fewer resources than VMS, but they are less isolated and secure than VMS.

To prepare for different test environments, testers often use visual VMWare and VirtualBox software to simulate different operating systems and browsers. This article introduces another Qemu+KVM virtualization solution that allows you to automatically create, destroy, and manage virtual test machines on demand using the command line during automated testing. In addition, understanding this scheme, but also a follow-up automated test platform to build a bedding.

Here, the Ubuntu20.04 desktop edition is used as the host to set up the virtualization environment.

(1) Verify that the host supports virtualization.

root@pve:~# egrep -o "(vmx|svm)" /proc/cpuinfo vmx
vmx
vmx

(2) Install virtualization software

sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients qemu virt-manager bridge-utils sudo service libvirtd  restart

For older Ubuntu systems, please replace with the following command.

sudo apt-get install qemu-kvm libvirt-bin qemu virt-manager bridge-utils
sudo service libvirt-bin restart

(3) Download the system and driver

Microsoft Win10 英 文 版 下载 here; Download the virtual MACHINE I/O device driver here. I chose the stable version virtio-WIN-0.1.185.iso.

(4) Open the VM management tool

  • On the GUI, open the terminal and enter virt-manager to start the VM management tool.
  • If QEMU/KVM is displayed in the figure, the local service is successfully connected.
  • If the libvirtd service is disconnected, double-click to connect to it. If you cannot connect to the libvirtd service, restart the machine.
  • You can also connect and manage the virtual machine on the remote host by clicking file -> Add Connection.

(5) Create a VM

  • Choose File > New VM to open the VM creation wizard.
  • Select the Win10 image file downloaded earlier as the local installation media.
  • On the network Settings page, select “Host Device”, which is the network card of the host machine, so that the virtual machine will exist as a computer in the LAN.
  • Follow the wizard to complete other Settings and save the Settings.

(6) Configure the VM

  • Double-click the VM window, and choose View > Details. The VM attributes page is displayed.
  • Click the Boot TAB and set the system to boot from the CD;
  • Click “Add Hardware” in the lower left corner to add a CD and point to the downloaded Virtio driver.

(7) Install the VM

  • After startup, the system is automatically installed from the CD;
  • In the Windows Installation Wizard, select Load driver.
  • Select the system file in the NetKVM directory of the virtio driver CDROM.
  • Complete the following installation steps.

(8) The installation is complete

  • After the installation is complete, open the VM window again.
  • Go to the CDROM TAB and delete the installation CD.
  • Start the VM, update the system, and install the test software.