From: Michael Prokop Date: Fri, 11 May 2018 07:07:48 +0000 (+0200) Subject: Improve VM detection when running inside recent versions of VirtualBox X-Git-Tag: v0.17.2~1 X-Git-Url: https://git.grml.org/?p=grml-autoconfig.git;a=commitdiff_plain;h=5b6b38a1878586cbd91c514c037f4f84bb60fbfc 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 --- 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 # }}}