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 -n 'virt-what' -- "$@"`
47 if [ $? != 0 ]; then exit 1; fi
53 -v|--version) echo $VERSION; exit 0 ;;
55 *) fail "internal error" ;;
59 # Check we're running as root.
62 if [ "$uid" != 0 ]; then
63 fail "this script must be run as root"
66 # Add /sbin and /usr/sbin to the path so we can find system
67 # binaries like dmicode.
68 # Add /usr/libexec to the path so we can find the helper binary.
70 exec_prefix=@exec_prefix@
71 PATH=@libexecdir@:/sbin:/usr/sbin:$PATH
73 # Many fullvirt hypervisors give an indication through CPUID. Use the
74 # helper program to get this information.
76 cpuid=`virt-what-cpuid-helper`
78 # Check for various products in the BIOS information.
83 # cpuid check added by Chetan Loke.
85 if [ "$cpuid" = "VMwareVMware" ]; then
87 elif echo "$dmi" | grep -q 'Manufacturer: VMware'; then
92 # http://blogs.msdn.com/b/sqlosteam/archive/2010/10/30/is-this-real-the-metaphysics-of-hardware-virtualization.aspx
93 if [ "$cpuid" = "Microsoft Hv" ]; then
97 # Check for VirtualPC.
99 if echo "$dmi" | grep -q 'Manufacturer: Microsoft Corporation'; then
103 # Check for VirtualBox.
104 # Added by Laurent Léonard.
105 if echo "$dmi" | grep -q 'Manufacturer: innotek GmbH'; then
109 # Check for OpenVZ / Virtuozzo.
110 # Added by Evgeniy Sokolov.
111 # /proc/vz - always exists if OpenVZ kernel is running (inside and outside
113 # /proc/bc - exists on node, but not inside container.
115 if [ -d /proc/vz -a ! -d /proc/bc ]; then
120 # Added by Laurent Léonard.
121 if grep -q 'UML' /proc/cpuinfo; then
125 # Check for IBM PowerVM Lx86 Linux/x86 emulator.
126 if grep -q '^vendor_id.*PowerVM Lx86' /proc/cpuinfo; then
130 # Check for Hitachi Virtualization Manager (HVM) Virtage logical partitioning.
131 if echo "$dmi" | grep -q 'Manufacturer.*HITACHI' &&
132 echo "$dmi" | grep -q 'Product.*HVM LPAR'; then
138 if [ "$cpuid" = "XenVMMXenVMM" ]; then
139 echo xen; echo xen-hvm
141 elif [ -f /proc/xen/capabilities ]; then
143 if grep -q "control_d" /proc/xen/capabilities; then
149 elif [ -d /proc/xen ]; then
150 # This directory can be present when Xen paravirt drivers are
151 # installed, even on baremetal. Don't confuse people by
156 # Check for QEMU/KVM.
158 if [ ! "$is_xen" ]; then
159 # Disable this test if we know this is Xen already, because Xen
160 # uses QEMU for its device model.
162 if grep -q 'QEMU' /proc/cpuinfo; then
163 if [ "$cpuid" = "KVMKVMKVM" ]; then