1

virtual machine (Virtual Machine) and container (Container) are two popular virtualization technologies.
virtual machine simulates the hardware of the machine, including a complete operating system and applications. Once it is turned on, all the resources pre-allocated to it will be occupied.
container is a process running on the host machine. Multiple containers use the same host machine's operating system kernel.
Compared with the virtual machine, the container starts faster and occupies less resources, but the isolation and security are weaker than the virtual machine, and there is no UI interface.

In order to prepare different test environments, testers often use software such as VMWare and VirtualBox to simulate different operating systems and browsers. This article introduces another Qemu+KVM virtualization solution. Through it, in automated testing, we can use the command line to automatically create, destroy and manage virtual test machines on demand. In addition, understanding this solution is also a foreshadowing of the subsequent automated test platform construction.

Here, Ubuntu20.04 desktop version is used as the host to build a virtualized environment.

(1) Verify whether the host supports virtualization, and there is output to indicate 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. Note that libvirt-daemon-system and libvirt-clients are replaced with libvirt-bin.

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

(3) Download system and driver

  • Download the official CD image of Microsoft Win10 from here
  • Download the virtual machine I/O device driver at 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, and start the virtual machine management tool;
    image.png
  • The QEMU/KVM shown in the figure indicates that it has successfully connected to the local service;
  • If the status is disconnected, please double-click to try to connect. If it shows that it cannot connect to the libvirtd service, restart the machine to fix it;
  • You can also click on the menu "File->Add Connection" to connect and manage the virtual machine on the remote host. The format is qemu+ssh://user@192.168.0.56:22/system?socket=/var/ run/libvirt/libvirt-sock.

(5) Create a new virtual machine

  • Click the menu "File -> New Virtual Machine" to open the virtual machine creation wizard;
    image.png
  • Select the Win10 image file downloaded earlier as the local installation medium;
    image.png
  • On the network setting page, select "Host Device", which is the host's network card, so that the virtual machine exists as a computer in the local area network;
    image.png
  • Follow the wizard to complete other settings and save.

(6) Set up the virtual machine

  • Double-click to open the virtual machine window, click "View -> Details" to enter the virtual machine properties page;
  • Click the boot tab and set the system to boot from the CD;
    image.png
  • Click "Add Hardware" in the lower left corner to add a CD, pointing to the downloaded virtio driver.
    image.png

(7) Install the virtual machine

  • After booting, the system will be installed automatically from the CD;
  • In the Windows installation wizard, choose to load the driver;
    image.png
  • Select the file corresponding to the system in the NetKVM directory in the virtio drive CDROM;
    image.png
  • Complete the subsequent installation steps.

(8) Finish the installation

  • After the installation is complete, open the virtual machine window again;
    image.png
  • Enter the CDROM tab and delete the installation CD;
  • Start the virtual machine, update the system, and install and test related software;
  • Complete the subsequent installation steps.

Thematic catalogue


陈哥聊测试
158 声望3.3k 粉丝

资深敏捷测试顾问,国内知名项目管理软件禅道团队成员。