From 5b6b38a1878586cbd91c514c037f4f84bb60fbfc Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 11 May 2018 09:07:48 +0200 Subject: [PATCH] Improve VM detection when running inside recent versions of VirtualBox When running e.g. inside VirtualBox 5.2.6 + 5.2.10 on Windows virt-what and imvirt report different results than expected, as in: | # virt-what | virtualbox | kvm | | # imvirt | KVM Explicitely check for VMware, KVM + VirtualBox and don't stop at first hit. Check for expected VM technology within its output instead of relying on a single string comparison. Thanks: Martin Besser for the bugreport and providing the relevant output --- autoconfig.functions | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/autoconfig.functions b/autoconfig.functions index 90bc6bd..4ddf086 100755 --- a/autoconfig.functions +++ b/autoconfig.functions @@ -188,11 +188,15 @@ VMWARE=false if vmware-detect &>/dev/null; then VIRTUAL=true; VMWARE=true; VIRTUAL_ENV='VMware' -elif [ "$(virt-what 2>/dev/null)" = "kvm" ] || \ - [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then +fi + +if virt-what 2>/dev/null | grep -q 'kvm' || \ + [ "$(imvirt 2>/dev/null)" = "KVM" ] ; then VIRTUAL=true; KVM=true; VIRTUAL_ENV='KVM' -elif [ "$(virt-what 2>/dev/null)" = "virtualbox" ] || \ - [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then +fi + +if virt-what 2>/dev/null | grep -q 'virtualbox' || \ + [ "$(imvirt 2>/dev/null)" = "VirtualBox" ] ; then VIRTUAL=true; VIRTUALBOX=true; VIRTUAL_ENV='VirtualBox' fi # }}} -- 2.1.4