Easy Ways to Determine Virtualization Technology
1. OverviewUsually, when we work with a virtual Linux system, it doesn’t feel much different from a conventional system. However, sometimes, we still want to know if a system is a virtual system.Moreover, we’ll probably want to know which virtualization technology the virtual system is using, such as VMware, VirtualBox, Linux KVM, and so on.In this tutorial, we’ll discuss how to determine virtualization technology using Linux commands.2. Using thedmidecodeCommandThe dmidecode command can report the information about our system BIOS according to the SMBIOS/DMI standard.Since thedmidecodecommand attempts to read hardware and firmware information, we needrootaccess to execute the command.When we are working with a non-virtualized system, we will get the motherboard information by querying the keysystem-product-name:$ sudo dmidecode -s system-product-name H87-D3HCopyThe output above shows that the system is running on a machine with a (Gigabyte)H87-D3Hmotherboard.However, if a system is running in a virtual machine, the same command will print the name of the virtualization product.Let’s test this command with some common virtualization technologies and see what it reports.Firstly, let’s execute the command on a virtual system in VirtualBox:$ sudo dmidecode -s system-product-name VirtualBoxCopyIt reports the correct virtualization environment.Next, let’s try the command on KVM and VMware virtual machines:$ sudo dmidecode -s system-product-name KVMCopy$ sudo dmidecode -s system-product-name VMware Virtual PlatformCopyIf we haverootaccess, using thedmidecodecommand is a pretty straightforward way to get the virtualization information.3. Using thelshwCommandThe lshw command is a convenient tool for listing detailed information on hardware configurations.We can use this tool and query thesystemclassto get information about the virtualization.We should notice thatrootaccess is required to get the virtualization technology data.Let’s start by executing the command on a non-virtualized system and see what it prints:$ sudo lshw -class system yk-arch description: Desktop Computer product: H87-D3H (To be filled by O.E.M.) vendor: Gigabyte Technology Co., Ltd. version: To be filled by O.E.M. serial: To be filled by O.E.M. width: 64 bits capabilities: smbios-2.7 dmi-2.7 smp vsyscall32 configuration: administrator_passworddisabled bootnormal ...CopySimilar todmidecode, thelshwcommand prints the motherboard information in the “product” field.Next, let’s see what it will report on various virtual systems.Firstly, let’s run it in a virtual machine of VirtualBox:$ sudo lshw -class system myVbox.test description: Computer product: VirtualBox vendor: Oracle version: 1.2 serial: 0 width: 64 bits capabilities: smbios-2.5 dmi-2.5 smp vsyscall32 configuration: familyVirtual Machine uuid......CopyTheproductfield is now filled by the expected virtualization technology information.Let’s try the same command with systems on KVM and VMware:$ sudo lshw -class system myKvm.test description: Computer product: KVM vendor: Red Hat version: 1.2 serial: 0 width: 64 bits capabilities: smbios-2.4 dmi-2.4 smp vsyscall32 configuration: familyVirtual Machine uuid......Copy$ sudo lshw -class system myVmware.test description: Computer product: VMware Virtual Platform vendor: VMware, Inc. version: 1.2 serial: 0 width: 64 bits capabilities: smbios-2.4 dmi-2.4 smp vsyscall32 configuration: familyVirtual Machine uuid......CopyThelshwcommand is a convenient option for us to solve the problem if we haverootaccess.4. Using thesystemd-detect-virtCommandMost modern Linux systems usesystemdas the system and service manager. Thesystemdpackage ships with the systemd-detect-virt utility, which we can use to detect a virtualization technology.It’s worth mentioning thatwe don’t needrootaccess to execute this command.As usual, let’s see what it reports if we execute the command on a non-virtualized system:$ systemd-detect-virt noneCopyAs the output shows,if the system isn’t running in a virtual machine, we’ll get “none” as the result.Next, let’s check the output we get when we run it on a virtual machine in VirtualBox:$ systemd-detect-virt oracleCopyIt lists “oracle” instead of something like “VirtualBox”. This is because thesystemd-detect-virtcommand shows only theIDof virtualization technology.In the man page, there is a table listing the detailedIDand product information. For example, the product information ofID“oracle” is:oracle Oracle VM VirtualBox (historically marketed by innotek and Sun Microsystems), for legacy and KVM hypervisorCopyNow, let’s run the command on virtual machines of KVM and VMware:$ systemd-detect-virt kvmCopy$ systemd-detect-virt vmwareCopyAs we’ve seen above, thesystemd-detect-virtcommand is pretty handy to get the information of the virtualization technology.We can get the full list of detectable containers and VM environments using the–listoption:$ systemd-detect-virt --list none kvm qemu bochs xen uml vmware oracle microsoft ...Copy5. Using thehostnamectlCommandIn addition to the handysystemd-detect-virtcommand, thesystemdpackage provides the hostnamectl command. This utility allows us to query and change the system hostname and related settings.We can use thehostnamectlcommand to detect virtualization technology as well.Same as thesystemd-detect-virtcommand,rootaccess is not required if we want to query information using thehostnamectlcommand.Firstly, let’s have a look at whathostnamectltells us if we execute it on a non-virtualized system:$ hostnamectl Static hostname: YK-Arch Icon name: computer-desktop Chassis: desktop Machine ID: d0fdfacb84184cee9507e0e1ac518e73 Boot ID: 9f88561ec0864abfa51575e8ec74732f Operating System: Arch Linux Kernel: Linux 5.7.9-arch1-1 Architecture: x86-64CopyThe output above shows the detailed distribution name, operating system, and kernel information.Further, we’ll execute the same command on a VirtualBox guest system again. Let’s check if it reports different information:$ hostnamectl Static hostname: myVbox.test Icon name: computer-vm Chassis: vm Machine ID: b4998efc50ae499881b024c258934223 Boot ID: f885614223a240b3b3b04cef3a934f18 Virtualization: oracle Operating System: CentOS Linux 7 (Core) Kernel: Linux 3.10.0-514.10.2.el7.x86_64 Architecture: x86-64CopyIn the output above, theIcon nameand theChassisare telling us it is a “vm” (virtual machine).Moreover, we can see a new field —Virtualization. This field tells us which virtualization technology our system is running in. In this case, it’soracle(VirtualBox).Let’s see what the command will report on KVM and VMware virtual machines:$ hostnamectl Static hostname: myKvm.test Icon name: computer-vm Chassis: vm Machine ID: 55296cb0566a4aaca10b8e3a4b28b432 Boot ID: 1bb259b0eb064d9eb8a22d112211b334 Virtualization: kvm Operating System: Ubuntu 19.10 Kernel: Linux 5.3.0-59-generic Architecture: x86-64Copy$ hostnamectl Static hostname: myVmware.test Icon name: computer-vm Chassis: vm Machine ID: 18a0752e1ccbeef09da51ad17fab1f1b Boot ID: beefdc99969e4a4a8525ff842b383c62 Virtualization: vmware Operating System: Ubuntu 19.10 Kernel: Linux 5.3.0-59-generic Architecture: x86-64Copy6. ConclusionIn this article, we addressed different Linux command utilities to detect various virtualization technologies.All those utilities are pretty straightforward to use. However, some of them requirerootaccess, and some don’t. We can choose the tool that’s most suitable for our needs.