Virtual Machine and Container are two popular virtualization technologies.
The 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. A container is a process running on a host, and multiple containers use the same host's operating system kernel. Compared with virtual machines, containers start faster and take up less resources, but their isolation and security are weaker than virtual machines.
In order to prepare 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, through which 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 that 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.
sudo apt-get install qemu-kvm libvirt-bin qemu virt-manager bridge-utils
sudo service libvirt-bin restart
(3) When configuring the virtual machine (in step 6 of this article), if you need to link the virtual machine to the network bridge, please edit the file /etc/netplan/01-network-manager-all.yaml to the following content. If you don't understand the meaning of the bridge, you can ignore it for now. In addition, the file name may be different for different operating systems.
network:
version: 2
renderer: NetworkManager
ethernets:
eno1:
addresses: []
dhcp4: true
bridges:
br0:
interfaces: [eno1]
dhcp4: no
addresses: [192.168.0.56/24]
gateway4: 192.168.0.1
nameservers:
addresses: [114.114.114.114]
(4) 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.
(5) Open the virtual machine management tool
- Open the terminal in the graphical interface, enter virt-manager, and start the virtual machine management tool;
- 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.
(6) Create a new virtual machine
- Click the menu "File -> New Virtual Machine" to open the virtual machine creation wizard;
- Select the Win10 image file downloaded earlier as the local installation medium.
- On the network settings 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.
- Follow the wizard to complete other settings and save.
(7) 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;
- Click "Add Hardware" in the lower left corner to add a CD, pointing to the downloaded virtio driver.
(8) 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;
- Select the file corresponding to the system in the NetKVM directory in the virtio drive CDROM;
- Complete the subsequent installation steps.
(9) System configuration
- 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, install and test related software;
- Enter netplwiz in the command line, and in the user account page, uncheck "User name and password must be entered to use this computer", and then enter the account and password;
- If you need to start the program and perform the corresponding operations, you can enter the directory c:\ProgramData\Microsoft\Windows\Start Menu\Programs and create a BAT file (optional).
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。