New version, new tarball. Extended support and tests for vm id to include better BSD

handling, and legacy linux. VM id will remain a work in progress, and will probably
require a few fixes for fringe cases. Nice to have would be things like OpenBSD's
vm which is difficult to detect. However, I believe this should handle roughly 99% of
realworld vm id cases, except for some commercial stuff that will require more data.
This commit is contained in:
Harald Hope 2016-10-25 12:20:16 -07:00
parent 344af561f1
commit 1f5a06471e
2 changed files with 61 additions and 19 deletions

34
inxi
View file

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
######################################################################## ########################################################################
#### Script Name: inxi #### Script Name: inxi
#### Version: 2.3.2 #### Version: 2.3.3
#### Date: 2016-10-23 #### Date: 2016-10-25
#### Patch Number: 00 #### Patch Number: 00
######################################################################## ########################################################################
#### SPECIAL THANKS #### SPECIAL THANKS
@ -5457,12 +5457,15 @@ get_device_vm()
local vm='other-vm?' vm_data='' vm_test='' local vm='other-vm?' vm_data='' vm_test=''
# https://www.freedesktop.org/software/systemd/man/systemd-detect-virt.html # https://www.freedesktop.org/software/systemd/man/systemd-detect-virt.html
# note: unknown is how reliable this tool is
if type -p systemd-detect-virt &>/dev/null;then if type -p systemd-detect-virt &>/dev/null;then
vm_test=$(systemd-detect-virt 2>/dev/null) vm_test=$(systemd-detect-virt 2>/dev/null | sed 's/none//' )
if [[ -n $vm_test && $vm_test != 'none' ]];then if [[ -n $vm_test && $vm_test != 'none' ]];then
vm=$vm_test vm=$vm_test
fi fi
else fi
# some simple to detect linux vm id's
if [[ $vm == 'other-vm?' ]];then
if [[ -e /proc/vz ]];then if [[ -e /proc/vz ]];then
vm='openvz' vm='openvz'
elif [[ -e /proc/xen ]];then elif [[ -e /proc/xen ]];then
@ -5470,6 +5473,8 @@ get_device_vm()
elif [[ -e /dev/vzfs ]];then elif [[ -e /dev/vzfs ]];then
vm='virtuozzo' vm='virtuozzo'
fi fi
fi
# this will catch many Linux systems and some BSDs
if [[ $vm == 'other-vm?' ]];then if [[ $vm == 'other-vm?' ]];then
vm_data=$vm_data$Lspci_v_Data vm_data=$vm_data$Lspci_v_Data
vm_data=$vm_data$Sysctl_a_Data vm_data=$vm_data$Sysctl_a_Data
@ -5483,12 +5488,33 @@ get_device_vm()
vm='vmware' vm='vmware'
elif [[ -n $( grep -is 'qemu' <<< $vm_data ) ]];then elif [[ -n $( grep -is 'qemu' <<< $vm_data ) ]];then
vm='qemu-or-kvm' vm='qemu-or-kvm'
elif [[ -n $( grep -s 'Virtual HD' <<< $vm_data ) ]];then
vm='hyper-v'
elif [[ -e /proc/cpuinfo && -n $( grep -is '^flags.*hypervisor' /proc/cpuinfo ) ]];then elif [[ -e /proc/cpuinfo && -n $( grep -is '^flags.*hypervisor' /proc/cpuinfo ) ]];then
vm='virtual-machine' vm='virtual-machine'
elif [[ -e /dev/vda || -e /dev/vdb || -e /dev/xvda || -e /dev/xvdb ]];then elif [[ -e /dev/vda || -e /dev/vdb || -e /dev/xvda || -e /dev/xvdb ]];then
vm='virtual-machine' vm='virtual-machine'
fi fi
fi fi
# this may catch some BSD and fringe Linux cases
if [[ $vm == 'other-vm?' && $B_ROOT == 'true' ]];then
if [[ -n $DMIDECODE_DATA && $DMIDECODE_DATA != 'dmidecode-error-'* ]];then
product_name=$(dmidecode -s system-product-name 2>/dev/null )
system_manufacturer=$( dmidecode -s system-manufacturer 2>/dev/null )
if [[ $product_name == 'VMware'* ]];then
vm='vmware'
elif [[ $product_name == 'VirtualBox'* ]];then
vm='virtualbox'
elif [[ $product_name == 'KVM'* ]];then
vm='kvm'
elif [[ $product_name == 'Bochs'* ]];then
vm='qemu'
elif [[ $system_manufacturer == 'Xen' ]];then
vm='xen'
elif [[ -n $( grep -i 'hypervisor' <<< "$DMIDECODE_DATA" ) ]];then
vm='virtual-machine'
fi
fi
fi fi
echo $vm echo $vm

View file

@ -1,3 +1,19 @@
=====================================================================================
Version: 2.3.3
Patch Version: 00
Script Date: 2016-10-25
-----------------------------------
Changes:
-----------------------------------
New version, new tarball. Extended support and tests for vm id to include better BSD
handling, and legacy linux. VM id will remain a work in progress, and will probably
require a few fixes for fringe cases. Nice to have would be things like OpenBSD's
vm which is difficult to detect. However, I believe this should handle roughly 99% of
realworld vm id cases, except for some commercial stuff that will require more data.
-----------------------------------
-- Harald Hope - Tue, 25 Oct 2016 12:17:46 -0700
===================================================================================== =====================================================================================
Version: 2.3.2 Version: 2.3.2
Patch Version: 00 Patch Version: 00