Improve VM detection when running inside recent versions of VirtualBox
authorMichael Prokop <mika@grml.org>
Fri, 11 May 2018 07:07:48 +0000 (09:07 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 11 May 2018 07:12:22 +0000 (09:12 +0200)
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

index 90bc6bd..4ddf086 100755 (executable)
@@ -188,11 +188,15 @@ VMWARE=false
 
 if vmware-detect &>/dev/null; then
   VIRTUAL=true; VMWARE=true; VIRTUAL_ENV='VMware'
 
 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'
   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
 # }}}
   VIRTUAL=true; VIRTUALBOX=true; VIRTUAL_ENV='VirtualBox'
 fi
 # }}}