Skip to content

Enable Virtualization Capabilities in a VM (KVM)

Juan Caviedes edited this page Sep 29, 2021 · 1 revision

As I said before it is not so good practice to add several layers of virtualization to a virtual machine that is going to be used for some purpose. However, here are the steps to do it. First, identify the VM that you want to enable the virtualization capabilities.

capri@caprivm:~$ sudo virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     amcop-vm-01                    shut off
 -     edge_k8s                       shut off

Next, let's suppose that I want to change the amcop-vm-01 machine default configuration. For this, change the <cpu mode='custom' match='exact' check='partial'> line for <cpu mode='host-model' match='exact' check='partial'>.

capri@caprivm:~$ sudo virsh edit amcop-vm-01
<domain type='kvm'>
  <name>amcop-vm-01</name>
  <uuid>78a11f72-60c0-4f55-b020-023e02cd071d</uuid>
  <memory unit='KiB'>16777216</memory>
  <currentMemory unit='KiB'>16777216</currentMemory>
  <vcpu placement='static'>8</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-model' match='exact' check='partial'>
    <model fallback='allow'>Skylake-Server-IBRS</model>
    <feature policy='require' name='ibpb'/>
    <feature policy='require' name='md-clear'/>
    <feature policy='require' name='spec-ctrl'/>
    <feature policy='require' name='ssbd'/>
  </cpu>
...

The change can be performed as in a VI editor. If you want validate if the configuration was applied, execute sudo virsh dumpxml amcop-vm-01. Now, shutdown and start the VM.

sudo virsh shutdown amcop-vm-01
sudo virsh start amcop-vm-01

For finish, you can access to the machine and execute lscpu command. For this, get the IP and access via SSH.

capri@caprivm:~$ sudo virsh domifaddr amcop-vm-01
 Name       MAC address          Protocol     Address
-------------------------------------------------------------------------------
 vnet0      52:54:00:d5:66:a3    ipv4         192.168.122.247/24

capri@caprivm:~$ ssh ubuntu@192.168.122.247
capri@amcopvm:~$ lscpu
Clone this wiki locally