3 # Copyright (C) 2008-2011 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # 'virt-what' tries to detect the type of virtualization being
20 # used (or none at all if we're running on bare-metal). It prints
21 # out one of more lines each being a 'fact' about the virtualization.
23 # Please see also the manual page virt-what(1).
24 # This script should be run as root.
26 # The following resources were useful in writing this script:
27 # . http://www.dmo.ca/blog/20080530151107
37 echo "virt-what [options]"
39 echo " --help Display this help"
40 echo " --version Display version and exit"
44 # Handle the command line arguments, if any.
46 TEMP=`getopt -o v --long help --long version --long test-root: -n 'virt-what' -- "$@"`
47 if [ $? != 0 ]; then exit 1; fi
54 # Deliberately undocumented: used for 'make check'.
58 -v|--version) echo $VERSION; exit 0 ;;
60 *) fail "internal error ($1)" ;;
64 # Add /sbin and /usr/sbin to the path so we can find system
65 # binaries like dmicode.
66 # Add /usr/libexec to the path so we can find the helper binary.
68 exec_prefix=@exec_prefix@
69 PATH=$root@libexecdir@:$root/sbin:$root/usr/sbin:$PATH
71 # Check we're running as root.
74 if [ "$uid" != 0 ]; then
75 fail "this script must be run as root"
78 # Many fullvirt hypervisors give an indication through CPUID. Use the
79 # helper program to get this information.
81 cpuid=`virt-what-cpuid-helper`
83 # Check for various products in the BIOS information.
84 # Note that dmidecode doesn't exist on non-PC architectures. On these,
85 # this will return an error which is ignored (error message redirected
86 # into $dmi variable).
88 dmi=`LANG=C dmidecode 2>&1`
91 # cpuid check added by Chetan Loke.
93 if [ "$cpuid" = "VMwareVMware" ]; then
95 elif echo "$dmi" | grep -q 'Manufacturer: VMware'; then
100 # http://blogs.msdn.com/b/sqlosteam/archive/2010/10/30/is-this-real-the-metaphysics-of-hardware-virtualization.aspx
101 if [ "$cpuid" = "Microsoft Hv" ]; then
105 # Check for VirtualPC.
106 # The negative check for cpuid is to distinguish this from Hyper-V
107 # which also has the same manufacturer string in the SM-BIOS data.
108 if [ "$cpuid" != "Microsoft Hv" ] &&
109 echo "$dmi" | grep -q 'Manufacturer: Microsoft Corporation'; then
113 # Check for VirtualBox.
114 # Added by Laurent Léonard.
115 if echo "$dmi" | grep -q 'Manufacturer: innotek GmbH'; then
119 # Check for OpenVZ / Virtuozzo.
120 # Added by Evgeniy Sokolov.
121 # /proc/vz - always exists if OpenVZ kernel is running (inside and outside
123 # /proc/bc - exists on node, but not inside container.
125 if [ -d $root/proc/vz -a ! -d $root/proc/bc ]; then
129 # Check for Linux-VServer
130 if cat $root/proc/self/status | grep -q "VxID: [0-9]*"; then
135 # Added by Laurent Léonard.
136 if grep -q 'UML' $root/proc/cpuinfo; then
140 # Check for IBM PowerVM Lx86 Linux/x86 emulator.
141 if grep -q '^vendor_id.*PowerVM Lx86' $root/proc/cpuinfo; then
145 # Check for Hitachi Virtualization Manager (HVM) Virtage logical partitioning.
146 if echo "$dmi" | grep -q 'Manufacturer.*HITACHI' &&
147 echo "$dmi" | grep -q 'Product.*HVM LPAR'; then
151 # Check for IBM SystemZ.
152 if grep -q '^vendor_id.*IBM/S390' $root/proc/cpuinfo; then
154 if [ -f $root/proc/sysinfo ]; then
155 if grep -q 'VM.*Control Program.*z/VM' $root/proc/sysinfo; then
157 elif grep -q '^LPAR' $root/proc/sysinfo; then
158 echo ibm_systemz-lpar
160 # This is unlikely to be correct.
161 echo ibm_systemz-direct
166 # Check for Parallels.
167 if echo "$dmi" | grep -q 'Vendor: Parallels'; then
173 if [ "$cpuid" = "XenVMMXenVMM" ]; then
174 echo xen; echo xen-hvm
176 elif [ -f $root/proc/xen/capabilities ]; then
178 if grep -q "control_d" $root/proc/xen/capabilities; then
184 elif [ -f $root/sys/hypervisor/type ] &&
185 grep -q "xen" $root/sys/hypervisor/type; then
186 # Ordinary kernel with pv_ops. There does not seem to be
187 # enough information at present to tell whether this is dom0
192 # Check for QEMU/KVM.
194 if [ ! "$is_xen" ]; then
195 # Disable this test if we know this is Xen already, because Xen
196 # uses QEMU for its device model.
198 if grep -q 'QEMU' $root/proc/cpuinfo; then
199 if [ "$cpuid" = "KVMKVMKVM" ]; then