From 12005ab922c2620a0a92cc15ccdf516f6fc0d650 Mon Sep 17 00:00:00 2001 From: litong Date: Mon, 6 May 2019 07:18:49 +0800 Subject: [PATCH] use /proc/bus/pci/devices to idenetify a kvm guest --- host/host_linux.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/host/host_linux.go b/host/host_linux.go index 03b3407..857085e 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -566,6 +566,17 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) { } } + filename = common.HostProc("bus/pci/devices") + if common.PathExists(filename) { + contents, err := common.ReadLines(filename) + if err == nil { + if common.StringsContains(contents, "virtio-pci") { + system = "kvm" + role = "guest" + } + } + } + filename = common.HostProc() if common.PathExists(filepath.Join(filename, "bc", "0")) { system = "openvz"