Installing a VM
- Install the virtualization components.
- CentOS:
1yum -y install qemu* libvirt* AAVMF virt-install
- openEuler:
- Install the components.
yum -y install qemu* libvirt* virt-viewer
- Modify the Yum source.
vi /etc/yum.repos.d/openEuler.repo
Add the following information to the end of the file:
[arch_fedora_online] name=arch_fedora baseurl=https://mirrors.huaweicloud.com/fedora/releases/30/Everything/aarch64/os/ enabled=1 gpgcheck=0 priority=2
- Make the Yum source take effect.
1yum clean all
1yum makecache - Install the components.
yum -y install AAVMF virt-install
- Install the components.
- CentOS:
- Verify the environment.
- Restart the libvirt service.
1service libvirtd restart
- View the version.
1virsh version
- Restart the libvirt service.
- Start the libvirt service and set it to automatically start upon system boot.
1systemctl start libvirtd
1systemctl enable libvirtd
- Create a storage pool.
- Create a storage pool directory and configure the directory permissions.
1mkdir -p /home/kvm/images
1chown root:root /home/kvm/images
1chmod 755 /home/kvm/images
- Define a storage pool and bind it to the storage pool directory. Create a folder-based storage pool. Activate the storage pool and set it to start upon system boot.
1 2 3 4
virsh pool-define-as StoragePool --type dir --target /home/kvm/images virsh pool-build StoragePool virsh pool-start StoragePool virsh pool-autostart StoragePool
- View the storage pool information.
1virsh pool-info StoragePool
1virsh pool-list
- Create a storage pool directory and configure the directory permissions.
- Create drive space.
In the following example, the volume is named 1.img; the storage pool is StoragePool; the volume capacity is 50 GB; the initially allocated capacity is 1 GB; the recommended file format is QCOW2.
1virsh vol-create-as --pool StoragePool --name 1.img --capacity 50G --allocation 1G --format qcow2
- Create a bridge.
1brctl addbr br1
- Copy the ISO file (system image file) to a directory other than /root, for example, /opt.
- Create a VM.
Create vm1. Assign four CPUs and 8 GB memory to vm1, and use 1.img as the drive space.
- CentOS:
virt-install --name=vm1 --vcpus=4 --ram=8192 --disk path=/home/kvm/images/1.img,format=qcow2,size=50,bus=virtio --cdrom /opt/CentOS-7-aarch64-Everything-1810.iso --network bridge=br1,model=virtio --force --autostart
- openEuler: The IP address in the command is the IP address of the PC that connects to the server. Set it based on site requirements.
export DISPLAY=IP:0.0
virt-install --name=vm1 --vcpus=4 --ram=8192 --disk path=/home/kvm/images/1.img,format=qcow2,size=50,bus=virtio --cdrom /opt/openEuler-20.03-LTS-SP1-everything-aarch64-dvd.iso --network bridge=br1,model=virtio --force --autostart --graphic vnc,listen=0.0.0.0,port=5906
- If the error message "ERROR Guest name 'vm1' si already in use" is displayed, delete vm1.
virsh list --all virsh destroy vm1 virsh undefine --nvram vm1 virsh list --all
- The error message "Connection refused" may be displayed when you run the virt-install command, as shown in the following figure.

If the
SSH connection tool is MobaXterm, choose from the menu bar to address this issue.

- If the error message "ERROR Guest name 'vm1' si already in use" is displayed, delete vm1.
- CentOS:
- Install the VM OS.
- Log in to the VM OS.
- First login: Enter the account and password to log in to the system.
- Regular login: Run the following commands on the host machine to log in to the system:
virsh list --all virsh console vm1 --force
- Press Ctrl+] to exit the VM OS.
Parent topic: VMs

