how to find out if running inside KVM guest

Solution 1:

Grep dmesg, there should be at least one line containing kvm. On my machines:

[    0.000000] kvm-clock: cpu 0, msr 0:5dd801, boot clock
[    0.000000] kvm-clock: cpu 0, msr 0:1023801, primary cpu clock

Alternativly check /proc/cpuinfo, it contains a line:

model name : QEMU Virtual CPU version 0.9.1

But, the problem is: You can't be sure you are an KVM guest (on top of QEMU) or only a QEMU-Guest.

Solution 2:

You can check if imvirt or virt-what which are available for several Linux distros, including Ubuntu, can help you.

Solution 3:

systemd-detect-virt

returns on this Ubuntu 18.04 KVM setup:

kvm

and on my host:

none

See also: https://unix.stackexchange.com/questions/89714/easy-way-to-determine-virtualization-technology

Tested on an Ubuntu 18.04 host.