Preparing VMs

This document describes how to install a VM using virt manager. Ignore if your VM is prepared.

Installing Dependency Tools

VM installation depends on related tools. The following commands are an example for installing the dependencies and enabling the libvirtd service. (If a proxy is required, configure the proxy first.)

dnf install virt-install virt-manager libvirt-daemon-qemu edk2-aarch64.noarch virt-viewer
systemctl start libvirtd
systemctl enable libvirtd

Preparing VM Disk Files

dnf install -y qemu-img
virsh pool-define-as vmPool --type dir --target /mnt/vm/images/
virsh pool-build vmPool
virsh pool-start vmPool
virsh pool-autostart  vmPool
virsh vol-create-as --pool vmPool --name master0.img --capacity 200G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name master1.img --capacity 200G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name master2.img --capacity 200G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name node1.img --capacity 300G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name node2.img --capacity 300G --allocation 1G --format qcow2
virsh vol-create-as --pool vmPool --name node3.img --capacity 300G --allocation 1G --format qcow2

Enabling Ports on Firewall

Method 1

  1. Query a port.

    netstat -lntup | grep qemu-kvm
    
  2. Enable the port on the VNC firewall. For example, if the port numbers start from 5900, run the following command:

    firewall-cmd --zone=public --add-port=5900-6000/tcp
    

Method 2

Disable the firewall.

$ systemctl stop firewalld

Preparing the VM Configuration File

A VM configuration file is required for creating a VM. For example, if the configuration file is master.xml and the host name of the VM is k8smaster0, an example configuration is as follows:

 cat master.xml

<domain type='kvm'>
    <name>k8smaster0</name>
    <memory unit='GiB'>8</memory>
    <vcpu>8</vcpu>
    <os>
 <type arch='aarch64' machine='virt'>hvm</type>
 <loader readonly='yes' type='pflash'>/usr/share/edk2/aarch64/QEMU_EFI-pflash.raw</loader>
 <nvram>/var/lib/libvirt/qemu/nvram/k8smaster0.fd</nvram>
    </os>
    <features>
 <acpi/>
 <gic version='3'/>
    </features>
    <cpu mode='host-passthrough'>
        <topology sockets='2' cores='4' threads='1'/>
    </cpu>
    <iothreads>1</iothreads>
    <clock offset='utc'/>
    <on_poweroff>destroy</on_poweroff>
    <on_reboot>restart</on_reboot>
    <on_crash>restart</on_crash>
    <devices>
 <emulator>/usr/libexec/qemu-kvm</emulator>
 <disk type='file' device='disk'>
     <driver name='qemu' type='qcow2' iothread="1"/>
     <source file='/mnt/vm/images/master0.img'/>
     <target dev='vda' bus='virtio'/>
     <boot order='1'/>
 </disk>
 <disk type='file' device='cdrom'>
     <driver name='qemu' type='raw'/>
     <source file='/mnt/openEuler-20.03-LTS-SP3-everything-aarch64-dvd.iso'/>
     <readonly/>
     <target dev='sdb' bus='scsi'/>
     <boot order='2'/>
 </disk>
        <interface type='network'>
           <mac address='52:54:00:00:00:80'/>
           <source network='default'/>
           <model type='virtio'/>
        </interface>
 <console type='pty'/>
        <video>
           <model type='virtio'/>
        </video>
        <controller type='scsi' index='0' model='virtio-scsi'/>
 <controller type='usb' model='ehci'/>
 <input type='tablet' bus='usb'/>
 <input type='keyboard' bus='usb'/>
 <graphics type='vnc' listen='0.0.0.0'/>
    </devices>
    <seclabel type='dynamic' model='dac' relabel='yes'/>
</domain>

Some VM configurations must be unique. Therefore, you need to modify the following to ensure that the VM is unique:

  • name: host name of the VM. You are advised to use lowercase letters. In this example, the value is k8smaster0.
  • nvram: handle file path of the NVRAM, which must be globally unique. In this example, the value is /var/lib/libvirt/qemu/nvram/k8smaster0.fd.
  • source file of disk: VM disk file path. In this example, the value is /mnt/vm/images/master0.img.
  • mac address of interface: MAC address of the interface. In this example, the value is 52:54:00:00:00:80.

Installing a VM

  1. Create and start a VM.

    virsh define master.xml
    virsh start k8smaster0
    
  2. Obtain the VNC port number of the VM.

    virsh vncdisplay k8smaster0
    
  3. Use a VM connection tool, such as VNC Viewer, to remotely connect to the VM and perform configurations as prompted.

  4. Set the host name of the VM, for example, k8smaster0.

    hostnamectl set-hostname k8smaster0
    

Bug Catching

Buggy Content

Bug Description

Submit As Issue

It's a little complicated....

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Bug Type
Specifications and Common Mistakes

● Misspellings or punctuation mistakes;

● Incorrect links, empty cells, or wrong formats;

● Chinese characters in English context;

● Minor inconsistencies between the UI and descriptions;

● Low writing fluency that does not affect understanding;

● Incorrect version numbers, including software package names and version numbers on the UI.

Usability

● Incorrect or missing key steps;

● Missing prerequisites or precautions;

● Ambiguous figures, tables, or texts;

● Unclear logic, such as missing classifications, items, and steps.

Correctness

● Technical principles, function descriptions, or specifications inconsistent with those of the software;

● Incorrect schematic or architecture diagrams;

● Incorrect commands or command parameters;

● Incorrect code;

● Commands inconsistent with the functions;

● Wrong screenshots.

Risk Warnings

● Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

● Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions;

● Copyright infringement.

How satisfied are you with this document

Not satisfied at all
Very satisfied
Submit
Click to create an issue. An issue template will be automatically generated based on your feedback.