Rate This Document
Findability
Accuracy
Completeness
Readability

Installing a VM

For details about how to deploy and install a virtual machine (VM), see KVM Installation Guide.

  1. Install the virtualization components.
    • CentOS:
      1
      yum -y install qemu* libvirt* AAVMF virt-install
      
    • openEuler:
      1. Install the components.
        yum -y install qemu* libvirt* virt-viewer
      2. 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
      3. Make the Yum source take effect.
        1
        yum clean all
        
        1
        yum makecache
        
      4. Install the components.
        yum -y install AAVMF virt-install
  2. Verify the environment.
    1. Restart the libvirt service.
      1
      service libvirtd restart
      
    2. View the version.
      1
      virsh version
      
  3. Start the libvirt service and set it to automatically start upon system boot.
    1
    systemctl start libvirtd
    
    1
    systemctl enable libvirtd
    
  4. Create a storage pool.
    1. Create a storage pool directory and configure the directory permissions.
      1
      mkdir -p /home/kvm/images
      
      1
      chown root:root /home/kvm/images
      
      1
      chmod 755 /home/kvm/images
      
    2. 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
      
    3. View the storage pool information.
      1
      virsh pool-info StoragePool
      
      1
      virsh pool-list
      
  5. 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.

    1
    virsh vol-create-as --pool StoragePool --name 1.img --capacity 50G --allocation 1G --format qcow2
    
  6. Create a bridge.
    1
    brctl addbr br1
    
  7. Copy the ISO file (system image file) to a directory other than /root, for example, /opt.
  8. 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 Settings > Configuration > X11 > Automatically start X server at MobaXterm start up from the menu bar to address this issue.

  9. Install the VM OS.
    • CentOS:

      Configure all items that contain the exclamation marks (!). Enter the serial numbers corresponding to the items and configure them as prompted. Then, press B to start the installation. After the installation is complete, press Enter.

    • openEuler:

      Install the operating system based on the GUI that is displayed.

  10. 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
  11. Press Ctrl+] to exit the VM OS.