If you want to find out whether the Linux OS is running inside a virtualized environment or on a real hardware computer, there are various heuristics you can try, depending on the type of hypervisor/container used underneath. Different hypervisors and container technologies may introduce different fingerprints within their instances (e.g., processor manufacturer, special file in /proc, virtualized NIC driver name). Also the boot sequence shown by dmesg can reveal some clues whether the OS is virtualized.
Fortunately, there are several command-line tools that make it far easier for end users to detect the type of virtualization technology used underneath Linux OS.
Method One: dmidecode
One way to detect the type of underlying virtualization is via dmidecode command, which is originally designed to show information about system's BIOS and hardware components. In particular, use the following command to detect virtualization:
If you are running this command on a physical server, the output will be the actual name of the hardware manufacturer (e.g., "Dell Inc."). On the other hand, if you run the command on a virtual machine, it will show the name of virtualization technology (e.g., "QEMU", "Xen", "VirtualBox", "VMware, Inc.").
Note that the dmidecode command does not work within containers as container-based virtualization does not create device node entries in the container's /dev directory which is used by dmidecode.
Method Two: systemd
If you use systemd on your Linux system, you can use a command-line tool called systemd-detect-virt which comes with systemd. This command can detect both hypervisor-based (e.g., KVM, QEMU, VMware, Xen, Oracle VM, VirtualBox, UML) and container-based (e.g., LXC, Docker, OpenVZ) virtualization.
On a physical server, the output of systemd-detect-virt will be "none". When run inside a virtual machine or a container, systemd-detect-virt will show the name of the virtualization technology used (e.g., "lxc", "kvm").
Method Three: virt-what
Another way to detect a virtualized environment within a terminal is by using virt-what. This command is actually a shell-script that uses various heuristics to identify the type of a virtualized environment you are in. It can detect QEMU/KVM, VMware, Hyper-V, VirtualBox, OpenVZ/Virtuozzo, Xen, LXC, IBM PowerVM, Parallels, etc.
To install virt-what on Debian-based system:
To install virt-what on Red Hat-based system:
To determine whether you are on a physical server or a virtual server, run the command with root privilege:
If you are on a physical server, the command will print nothing. If you are on a virtual machine or a container, it will print the type of virtualization.
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!