For troubleshooting or in scripts you might want to identify if you Linux is running as a Virtual Machine. If you work with puppet you might be familiar with facter which provides the facts "is_virtual" (true or false) and "virtual" (Virtualization type).
There is another handy tool called virt-what that is available in Fedora (13+), Red Hat Enterprise Linux (5.7+ and 6.1+), Debian, Ubuntu, ArchLinux and Gentoo, and it can be compiled from source on just about any Linux.
virt-what is a shell script which can be used to detect if the program is running in a virtual machine. The program prints out a list of facts
about the virtual machine, derived from heuristics. One fact is printed per line.
Example 1: Ubuntu 12.04.5 LTS, running on ESXi 5.5:
root@mail01:~# virt-what vmware
In that case, the system is running on a VMware based Hypervisor (ESXi/Workstation/Fusion)
If there is no output and the script exits with code 0 the systen is either running on bare-metal or the hypervizor cannot be detected.
Example 2: Raspbian GNU/Linux 7 running on Raspberry Pi:
root@raspberrypi:~# virt-what root@raspberrypi:~# echo $? 0
In scripts virt-what can also be handy when you want a functions to be only executed when the system is running as a virtual machine. This little snippet can be used to run your code only when the virtual machine is running on a VMware based hypervisor:
/usr/sbin/virt-what | grep 'vmware' &> /dev/null if [ $? == 0 ]; then echo "VMware detected" #do something fi
The script can detect the following hypervisor types:
- hyperv: Microsoft Hyper-V
- ibm_systemz: IBM SystemZ
- ibm_systemz-zvm: z/VM guest in a LPAR on an IBM SystemZ
- linux_vserver: Linux VServer container
- kvm: KVM hypervisor
- openvz: OpenVZ/Virtuozzo
- parallels: Parallels Desktop/Parallels Server
- powervm_lx86: IBM PowerVM Lx86 Linux/x86 emulator
- qemu: QEMU software emulation
- uml: User-Mode Linux (UML) guest
- virtage: Hitachi Virtualization Manager (HVM)
- virtualbox: VirtualBox guest.
- virtualpc: Microsoft VirtualPC
- vmware: VMware ESXi/Workstation/Fusion
- xen: Xen hypervisor
- xen-dom0: Xen privileged domain
- xen-domU: Xen paravirtualized guest domain
- xen-hvm: Xen guest fully virtualized (HVM)
- virt: Unspecified Virtualization
for those that do not know,
sudo apt-get install virt-what
or
sudo yum intall virt-what
Pingback: How to hide a Virtual Machine | Virten.net