Is there a way to find out if OS(linux) is running inside KVM guest..
Asked
Active
Viewed 2.0k times
14
-
related: https://unix.stackexchange.com/questions/89714/easy-way-to-determine-virtualization-technology – Ciro Santilli OurBigBook.com Oct 04 '18 at 14:50
5 Answers
13
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.

theomega
- 734
- 2
- 8
- 17
-
kvm-clock clocksource might be not present or disabled for stability reasons. – sendmoreinfo Oct 02 '10 at 11:57
-
2You may want to add `dmidecode` to the list of ways that might show if you are running virtualized, it works well with VMWare. – Law29 Apr 03 '16 at 06:49
-
The first worked for me but the second shows the regular intel model name – MikeKulls Feb 01 '23 at 23:10
8
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.

Ciro Santilli OurBigBook.com
- 3,838
- 1
- 30
- 19
6
Current versions of lscpu
also show if a hypervisor is detected:
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 23
Model name: Intel Core 2 Duo P9xxx (Penryn Class Core 2)
Stepping: 3
CPU MHz: 2659.936
BogoMIPS: 5319.87
Hypervisor vendor: KVM
Virtualization type: full
...

Gargravarr
- 493
- 5
- 14
2
Another possibility is dmidecode -s 'system-product-name'
[samveen@vm1 ~]$ sudo dmidecode -s 'system-product-name'
KVM

Samveen
- 1,869
- 1
- 15
- 19
-
Did not work with this Ubuntu 18.04 on Ubuntu 18.04 setup: https://askubuntu.com/revisions/1046792/15 , it just output: `Standard PC (i440FX + PIIX , 1996)`. – Ciro Santilli OurBigBook.com Oct 04 '18 at 15:05
-
2@CiroSantilli新疆改造中心六四事件法轮功 Please check the other DMI information fields as well. I dont have access to an Ubuntu based KVM host to test. In most cases, the`system-product-name` identifier gives the expected answer, even in cases like `VirtualBox` and `VMWare`. – Samveen Oct 12 '18 at 05:34