3 # Copyright (C) 2008-2022 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 or 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://dmo.ca/blog/detecting-virtualization-on-linux/
29 # Do not allow unset variables, and set defaults.
38 test -e "${root}/proc/cpuinfo"
42 # Lacking /proc, on some systems sysctl can be used instead.
43 OS=$(uname) || fail "failed to get operating system name"
49 echo "virt-what: $1" >&2
54 echo "virt-what [options]"
56 echo " --help Display this help"
57 echo " --version Display version and exit"
61 # Handle the command line arguments, if any.
62 while test $# -gt 0; do
66 # Deliberately undocumented: used for 'make check'.
67 root=$(echo "$1" | sed 's/.*=//')
69 test -z "$root" && fail "--test-root option requires a value"
71 -v|--version) echo "$VERSION"; exit 0 ;;
73 *) fail "unrecognized option '$1'";;
76 test $# -gt 0 && fail "extra operand '$1'"
78 # Add /sbin and /usr/sbin to the path so we can find system
79 # binaries like dmidecode.
80 # Add /usr/libexec to the path so we can find the helper binary.
82 exec_prefix=@exec_prefix@
83 PATH="${root}@libexecdir@:${root}/sbin:${root}/usr/sbin:${PATH}"
86 # Check we're running as root.
87 EFFUID=$(id -u) || fail "failed to get current user id"
89 if [ "x$root" = "x" ] && [ "$EFFUID" -ne 0 ]; then
90 fail "this script must be run as root"
93 # Try to locate the CPU-ID helper program
94 CPUID_HELPER=$(which virt-what-cpuid-helper 2>/dev/null)
95 if [ -z "$CPUID_HELPER" ] ; then
96 fail "virt-what-cpuid-helper program not found in \$PATH"
99 # Many fullvirt hypervisors give an indication through CPUID. Use the
100 # helper program to get this information.
102 cpuid=$(virt-what-cpuid-helper)
104 # Check for various products in the BIOS information.
105 # Note that dmidecode doesn't exist on all architectures. On the ones
106 # it does not, then this will return an error, which is ignored (error
107 # message redirected into the $dmi variable).
109 dmi=$(LANG=C dmidecode 2>&1)
112 # Note for the purpose of testing, we only call uname with -m option.
114 arch=$(uname -m | sed -e 's/i.86/i386/' | sed -e 's/arm.*/arm/')
116 # Check for Alibaba Cloud
117 if echo "$dmi" | grep -q 'Manufacturer: Alibaba'; then
118 # Check for Alibaba Cloud ECS Bare Metal (EBM) Instance
119 if [ "x$root" = "x" ] && ( { echo -e "GET /latest/meta-datainstance/instance-type HTTP/1.0\r\nHost: 100.100.100.200\r\n\r" >&3; grep -sq 'ebm' <&3 ; } 3<> /dev/tcp/100.100.100.200/80 ) 2>/dev/null ; then
120 echo "alibaba_cloud-ebm"
127 # cpuid check added by Chetan Loke.
129 if [ "$cpuid" = "VMwareVMware" ]; then
131 elif echo "$dmi" | grep -q 'Manufacturer: VMware'; then
136 # http://blogs.msdn.com/b/sqlosteam/archive/2010/10/30/is-this-real-the-metaphysics-of-hardware-virtualization.aspx
137 if [ "$cpuid" = "Microsoft Hv" ]; then
141 # Check for VirtualPC.
142 # The negative check for cpuid is to distinguish this from Hyper-V
143 # which also has the same manufacturer string in the SM-BIOS data.
144 if [ "$cpuid" != "Microsoft Hv" ] &&
145 echo "$dmi" | grep -q 'Manufacturer: Microsoft Corporation' &&
146 echo "$dmi" | grep -q 'Product Name: Virtual Machine'; then
150 # Check for VirtualBox.
151 # Added by Laurent Léonard.
152 if echo "$dmi" | grep -q 'Manufacturer: innotek GmbH'; then
157 if [ "$cpuid" = "bhyve bhyve " ]; then
159 elif echo "$dmi" | grep -q "Vendor: BHYVE"; then
163 # Check for OpenVZ / Virtuozzo.
164 # Added by Evgeniy Sokolov.
165 # /proc/vz - always exists if OpenVZ kernel is running (inside and outside
167 # /proc/bc - exists on node, but not inside container.
168 if [ -d "${root}/proc/vz" -a ! -d "${root}/proc/bc" ]; then
172 # Check for LXC containers
173 # http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface
174 # Added by Marc Fournier
175 if [ -e "${root}/proc/1/environ" ] &&
176 tr '\000' '\n' < "${root}/proc/1/environ" |
177 grep -Eiq '^container=lxc'; then
181 # Check for Illumos LX
182 if [ -e "${root}/proc/1/environ" ] &&
183 tr '\0' '\n' < "${root}/proc/1/environ" | grep -q '^container=zone$' &&
184 [ -e "${root}/proc/version" ] &&
185 grep -q 'BrandZ virtual linux' < "${root}/proc/version"; then
190 if [ -f "${root}/.dockerenv" ] || [ -f "${root}/.dockerinit" ] || \
191 grep -qF /docker/ "${root}/proc/self/cgroup" 2>/dev/null; then
196 if [ -e "${root}/proc/1/environ" ] &&
197 cat "${root}/proc/1/environ" | tr '\000' '\n' | grep -Eiq '^container=oci'; then
202 if [ -e "${root}/proc/1/environ" ] &&
203 cat "${root}/proc/1/environ" | tr '\000' '\n' | grep -Eiq '^container=crio'; then
208 if [ -e "${root}/proc/1/environ" ] &&
209 cat "${root}/proc/1/environ" | tr '\000' '\n' | grep -Eiq '^container=podman'; then
211 elif grep -qF /libpod- "${root}/proc/self/cgroup" 2>/dev/null; then
215 # Check for Linux-VServer
216 if test -e "${root}/proc/self/status" \
217 && cat "${root}/proc/self/status" | grep -q "VxID: [0-9]*"; then
219 if grep -q "VxID: 0$" "${root}/proc/self/status"; then
220 echo linux_vserver-host
222 echo linux_vserver-guest
227 # Added by Laurent Léonard.
228 if have_cpuinfo && grep -q 'UML' "${root}/proc/cpuinfo"; then
232 # Check for IBM PowerVM Lx86 Linux/x86 emulator.
233 if have_cpuinfo && grep -q '^vendor_id.*PowerVM Lx86' "${root}/proc/cpuinfo"
238 # Check for Hitachi Virtualization Manager (HVM) Virtage logical partitioning.
239 if echo "$dmi" | grep -q 'Manufacturer.*HITACHI' &&
240 echo "$dmi" | grep -q 'Product.* LPAR'; then
244 # Check for IBM SystemZ.
245 if have_cpuinfo && grep -q '^vendor_id.*IBM/S390' "${root}/proc/cpuinfo"; then
247 if [ -f "${root}/proc/sysinfo" ]; then
248 if grep -q 'VM.*Control Program.*KVM/Linux' "${root}/proc/sysinfo"; then
250 elif grep -q 'VM.*Control Program.*z/VM' "${root}/proc/sysinfo"; then
252 elif grep -q '^LPAR' "${root}/proc/sysinfo"; then
253 echo ibm_systemz-lpar
255 # This is unlikely to be correct.
256 echo ibm_systemz-direct
261 # Check for Parallels.
262 if echo "$dmi" | grep -q 'Vendor: Parallels'; then
267 # Check for Nutanix AHV.
268 if echo "$dmi" | grep -q 'Manufacturer: Nutanix' &&
269 echo "$dmi" | grep -q 'Product Name: AHV'; then
273 # Check for oVirt/RHEV.
274 if echo "$dmi" | grep -q 'Manufacturer: oVirt'; then
277 if echo "$dmi" | grep -q 'Product Name: RHEV Hypervisor'; then
282 if echo "$dmi" | grep -q 'Product Name: Google Compute Engine'; then
286 # Red Hat's hypervisor.
287 if echo "$dmi" | grep -q 'Manufacturer: Red Hat'; then
293 if [ "$cpuid" = "XenVMMXenVMM" ] &&
294 ! echo "$dmi" | grep -q 'No SMBIOS nor DMI entry point found, sorry'; then
295 echo xen; echo xen-hvm
297 elif [ -d "${root}/proc/xen" ]; then
299 if grep -q "control_d" "${root}/proc/xen/capabilities" 2>/dev/null; then
306 elif [ -f "${root}/sys/hypervisor/type" ] &&
307 grep -q "xen" "${root}/sys/hypervisor/type"; then
308 # Ordinary kernel with pv_ops. There does not seem to be
309 # enough information at present to tell whether this is dom0
312 elif [ "$arch" = "arm" ] || [ "$arch" = "aarch64" ]; then
313 if [ -d "${root}/proc/device-tree/hypervisor" ] &&
314 grep -q "xen" "${root}/proc/device-tree/hypervisor/compatible"; then
318 elif [ -d "${root}/proc/device-tree/hypervisor" ] &&
319 grep -q "vmware" "${root}/proc/device-tree/hypervisor/compatible"; then
323 elif [ "$arch" = "ia64" ]; then
324 if [ -d "${root}/sys/bus/xen" -a ! -d "${root}/sys/bus/xen-backend" ]; then
325 # PV-on-HVM drivers installed in a Xen guest.
329 # There is no virt leaf on IA64 HVM. This is a last-ditch
330 # attempt to detect something is virtualized by using a
332 virt-what-ia64-xen-rdtsc-test > /dev/null 2>&1
335 1) # Could be some sort of virt, or could just be a bit slow.
341 # Check for QEMU/KVM.
343 # Parallels exports KVMKVMKVM leaf, so skip this test if we've already
344 # seen that it's Parallels. Xen uses QEMU as the device model, so
345 # skip this test if we know it is Xen.
347 if ! "$skip_qemu_kvm"; then
348 if [ "$cpuid" = "KVMKVMKVM" ]; then
350 elif [ "$cpuid" = "TCGTCGTCGTCG" ]; then
353 elif echo "$dmi" | grep -q 'Product Name: KVM'; then
356 elif echo "$dmi" | grep -q 'Manufacturer: KVM'; then
359 elif echo "$dmi" | grep -q 'Manufacturer: Amazon EC2' &&
360 echo "$dmi" | grep -q 'System is a virtual machine'; then
361 # This is for AWS Graviton (Arm) systems which don't have CPUID.
364 elif echo "$dmi" | grep -q 'Manufacturer: Alibaba Cloud' &&
365 echo "$dmi" | grep -q 'System is a virtual machine'; then
366 # This is for Alibaba Arm systems which don't have CPUID.
369 elif echo "$dmi" | grep -q 'Manufacturer: QEMU'; then
370 # The test for KVM above failed, so now we know we're
371 # not using KVM acceleration.
374 elif [ "$arch" = "arm" ] || [ "$arch" = "aarch64" ]; then
375 if [ -d "${root}/proc/device-tree" ] &&
376 ls "${root}/proc/device-tree" | grep -q "fw-cfg"; then
377 # We don't have enough information to determine if we're
378 # using KVM acceleration or not.
382 elif [ -d ${root}/proc/device-tree/hypervisor ] &&
383 grep -q "linux,kvm" /proc/device-tree/hypervisor/compatible; then
384 # We are running as a spapr KVM guest on ppc64
387 elif use_sysctl; then
389 product=$(sysctl -n hw.product)
390 if echo "$product" | grep -q 'SmartDC HVM'; then
394 # This is known to fail for qemu with the explicit -cpu
395 # option, since /proc/cpuinfo will not contain the QEMU
396 # string. QEMU 2.10 added a new CPUID leaf, so this
397 # problem only triggered for older QEMU
398 if have_cpuinfo && grep -q 'QEMU' "${root}/proc/cpuinfo"; then
404 if ! "$skip_lkvm"; then
405 if [ "$cpuid" = "LKVMLKVMLKVM" ]; then
407 elif [ "$arch" = "arm" ] || [ "$arch" = "aarch64" ]; then
408 if [ -d "${root}/proc/device-tree" ] &&
409 grep -q "dummy-virt" "${root}/proc/device-tree/compatible"; then
415 # Check ppc64 lpar, kvm or powerkvm
417 # example /proc/cpuinfo line indicating 'not baremetal'
420 # example /proc/ppc64/lparcfg systemtype line
421 # system_type=IBM pSeries (emulated by qemu)
423 if [ "$arch" = "ppc64" ] || [ "$arch" = "ppc64le" ] ; then
424 if have_cpuinfo && grep -q 'platform.**pSeries' "${root}/proc/cpuinfo"; then
425 if grep -q 'model.*emulated by qemu' "${root}/proc/cpuinfo"; then
428 # Assume LPAR, now detect shared or dedicated
429 if grep -q 'shared_processor_mode=1' "${root}/proc/ppc64/lparcfg"; then
430 echo ibm_power-lpar_shared
432 echo ibm_power-lpar_dedicated
439 # Check for OpenBSD/VMM
440 if [ "$cpuid" = "OpenBSDVMM58" ]; then
445 if [ "${arch#sparc}" != "$arch" ] && [ -e "${root}/dev/mdesc" ]; then
447 if [ -d "${root}/sys/class/vlds/ctrl" ] && \
448 [ -d "${root}/sys/class/vlds/sp" ]; then
453 MDPROP="${root}/usr/lib/ldoms/mdprop.py"
454 if [ -x "${MDPROP}" ]; then
455 if [ -n "$($MDPROP -v iodevice device-type=pciex)" ]; then
458 elif [ -n "$($MDPROP -v iov-device vf-id=0)" ]; then
466 if echo "$dmi" | grep -Eq 'Version: [0-9]+\.[0-9]+\.amazon'; then
468 # AWS on baremetal or KVM.
469 elif echo "$dmi" | grep -q 'Vendor: Amazon EC2'; then
474 if echo "$dmi" | grep -q 'Manufacturer: UpCloud'; then