Virtual machines and containers are two popular virtualization technologies. The virtual machine simulates the hardware of the machine, including the complete operating system and applications. Once it is opened, all the resources allocated to it will be occupied. A container is a process running on a host that uses the same host’s operating system kernel between containers. Containers start faster and consume fewer resources than virtual machines, but are less isolated and secure than virtual machines, and have no UI.
To prepare for different test environments, testers often use software such as VMware and VirtualBox to simulate different operating systems and browsers. This article describes another QEMU +KVM virtualization solution that allows you to automatically create, destroy, and manage virtual test machines on demand, using the command line, in your test automation. In addition, the understanding of this scheme, is also a follow-up automated test platform to build a cushion.
Ubuntu20.04 Desktop Edition is used as the host to build the virtual environment.
(1) First, verify that the host supports virtualization and has output indicating support.
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 the old Ubuntu system, please replace it 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
- Download Microsoft Win10 official CD image from here;
- Download the virtual machine I/O device driver here. I chose the stable version of virtio-win-0.1.185.iso.
(4) Open the virtual machine management tool
Open the terminal in the graphical interface, enter virt-manager to start the virtual machine management tool;
- The QEMU/KVM shown in the figure indicates a successful connection to the local service;
- If the status is disconnected, please double-click to try to connect. If it shows that you cannot connect to libvirtd service, you can restart the machine to repair;
- You can also connect and manage virtual machines on remote hosts by clicking the menu “File-> Add Connection” in the form of QEMU + SSH ://[email protected]:22/ System? Socket = / var/run/libvirt/libvirt – the sock.
(5) Create a virtual machine
- Click the menu “File-> New Virtual Machine” to open the virtual machine creation wizard;
- Select the Win10 image file downloaded in front as the local installation medium.
- On the network Settings page, select the “host device”, which is the network card of the host, so that the virtual machine exists as a computer on the LAN.
- Press the wizard to complete the other Settings and save.
(6) Set the virtual machine
- Double-click to open the virtual machine window and click “View -> Details” to enter the virtual machine properties page.
- Click the Boot TAB to set the system to boot from the CD;
- Click “Add Hardware” in the lower left corner, add a CD, and point to the downloaded Virtio driver.
(7) Install the virtual machine
- Automatically install the system from CD-ROM after startup;
- Windows Setup Wizard, select the load driver;
- Select virtio drive CDROM, NetKVM directory under the corresponding system file.
- Complete the following installation steps.
(8) End installation
- After the installation is complete, open the virtual machine window again;
- Enter the CDROM TAB and delete the installation CD.
- Start the virtual machine, update the system, and install test related software;
- Complete the following installation steps.
Project directory