Hi, everyone!
Today, I will share with you the case: How to install VMs on CentOS 7.6.
The process for installing the VM
1. Install the host machine system
Install CentOS 7.6 and configure the proxy to ensure that you can access the yum source.
2. Install virtualization components
yum install qemu* libvirt* AAVMF virt-install
Creating a QEMU-KVM Soft Link
ln -sv /usr/libexec/qemu-kvm /usr/bin/
Upgrading the QEMU
yum -y install glib2-devel zlib-devel pixman-devel
3. Define a VM
a. Create the os and vm directories in the /home directory of the host machine.
Upload the OS image to the /home/os directory.
VM XML files and VM hard disk files are uploaded and created in /home/vm.
b. Modify the XML file and create the VM hard disk file.
Modify the VM XML file to ensure that the OS and hard disk paths are correct. In addition, ensure that the VM MAC address does not conflict.
Creating a VM Hard Disk File
qemu-img create -f qcow2 -o size=200G win10.qcow2 Creating a 200 GB VM Hard Disk File qemu-img create –f qcow2 win10.img 100G
c. Host machine bridge operation
brctl addbr br0 ifconfig enp2s0f0 0.0.0.0/0 up brctl addif br0 enp2s0f0 ifconfig br0 xx.xx.xx.xx/xx up route add default gw xx.xx.xx.xx
d. Define virtual machines
virsh define win10.xml virsh list --all # Run the following command to check whether the VM is successfully defined: virsh edit win10 #Modify the information about the XML file of the Windows 10 VM. virsh start win10 #Start the Windows 10 VM. virsh destroy win10 #Stop the Windows 10 VM. netstat -tunlp #Check the VNC port number of the VM.
Before using VNC to connect to VMs, disable the firewall of the system.
sysemctl stop firewalld.service #Disable the firewall. firewall-cmd --state #Check the status of the firewall. systemctl disable firewalld.service # Disable the firewall from being started.
e. Clone a VM
virt-clone -o win10 -n win20 -f /home/vm/win20.qcow2
Attach the XML definition file.
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> <name>win10</name> <memory>16777216</memory> <currentMemory>16777216</currentMemory> <vcpu>4</vcpu> <os> <type arch='x86_64'>hvm</type> <boot dev='hd'/> <boot dev='cdrom'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'> <timer name='rtc' tickpolicy='catchup' track='guest'/> <timer name='hpet' present='no'/> <timer name='pit' tickpolicy='delay'/> </clock> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none' io='native'/> <source file='/home/vm/win10.qcow2'/> <target dev='hda' bus='ide'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw' cache='none' io='native'/> <source file='/home/os/cn_windows_10_technical_preview_x86_dvd_5552506.iso'/> <target dev='hdc' bus='ide'/> <readonly/> </disk> <interface type='bridge'> <mac address='00:21:10:11:20:1a'/> <source bridge='br0'/> </interface> <input type='tablet' bus='usb'/> <input type='mouse' bus='ps2'/> <console type='pty'> <target port='0'/> </console> <graphics type='vnc' autoport='no' listen='xx.xx.xx.xx' port='59210'> <listen type='address' address='xx.xx.xx.xx'/> </graphics> <video> <model type='cirrus' vram='9216' heads='1'/> </video> <memballoon model='none'/> </devices> </domain>
Thank you for reading!



