1. Overview

Usually, 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, VirtualBoxLinux KVM, and so on.

In this tutorial, we’ll discuss how to determine virtualization technology using Linux commands.

2. Using the dmidecode Command

The dmidecode command can report the information about our system BIOS according to the SMBIOS/DMI standard.

Since the dmidecode command attempts to read hardware and firmware information, we need root access to execute the command.

When we are working with a non-virtualized system, we will get the motherboard information by querying the key system-product-name:

$ sudo dmidecode -s system-product-name
H87-D3H

The output above shows that the system is running on a machine with a (Gigabyte) H87-D3H motherboard.

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
VirtualBox

It reports the correct virtualization environment.

Next, let’s try the command on KVM and VMware virtual machines:

$ sudo dmidecode -s system-product-name
KVM
$ sudo dmidecode -s system-product-name
VMware Virtual Platform

If we have root access, using the dmidecode command is a pretty straightforward way to get the virtualization information.

3. Using the lshw Command

The lshw command is a convenient tool for listing detailed information on hardware configurations.

We can use this tool and query the system class to get information about the virtualization.

We should notice that root access 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_password=disabled boot=normal ...

Similar to dmidecode, the lshw command 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: family=Virtual Machine uuid=......

The product field 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: family=Virtual Machine uuid=......
$ 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: family=Virtual Machine uuid=......

The lshw command is a convenient option for us to solve the problem if we have root access.

4. Using the systemd-detect-virt Command

Most modern Linux systems use systemd as the system and service manager. The systemd package ships with the systemd-detect-virt utility, which we can use to detect a virtualization technology.

It’s worth mentioning that we don’t need root access 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
none

As 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
oracle

It lists “oracle” instead of something like “VirtualBox”. This is because the systemd-detect-virt command shows only the ID of virtualization technology.

In the man page, there is a table listing the detailed ID and product information. For example, the product information of IDoracle” is:

 oracle                 Oracle VM VirtualBox   
                        (historically marketed 
                        by innotek and Sun    
                        Microsystems), for     
                        legacy and KVM         
                        hypervisor

Now, let’s run the command on virtual machines of KVM and VMware:

$ systemd-detect-virt
kvm
$ systemd-detect-virt
vmware

As we’ve seen above, the systemd-detect-virt command 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 –list option:

$ systemd-detect-virt --list
none
kvm
qemu
bochs
xen
uml
vmware
oracle
microsoft
...

5. Using the hostnamectl Command

In addition to the handy systemd-detect-virt command, the systemd package provides the hostnamectl command. This utility allows us to query and change the system hostname and related settings.

We can use the hostnamectl command to detect virtualization technology as well.

Same as the systemd-detect-virt command, root access is not required if we want to query information using the hostnamectl command.

Firstly, let’s have a look at what hostnamectl tells 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-64

The 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-64

In the output above, the Icon name and the Chassis are 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’s oracle (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-64
$ 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-64

6. Conclusion

In 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 require root access, and some don’t. We can choose the tool that’s most suitable for our needs.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments