See if your linux server is running on a virtual machine or not

Virtual machines try to trick their operating systems into thinking they are running on natural hardware. See how you can tell from the linux command line if the computer is physical or virtul.

matrix red pill blue nio

Virtual Machines and Hypervisors

A traditional computer is a physical object. It is a collection of different hardware components that are connected and screwed together so that you can load an operating system, install applications, start them, and use them.

The material is . Limiting it to one operating system per physical computer means that the cost of running multiple operating systems becomes prohibitive. The best solution would be to allow a single physical computer to run a selection of operating systems at the same time, each thinking it is running on its own, unique hardware.

A hypervisor makes this possible. A hypervisor (also called a virtual machine manager or virtual machine monitor) is software that allows you to create virtual machines. They behave as if they were individual, physical computers, even though they run on the same physical server, sharing hard disk space, memory, and CPU cores.

Of course, the host must be powerful enough to meet the requirements of all virtual machines, but given the adequacy of RAM and high processing power in the host, virtual machines can run at speeds almost as if they were on separate machines.

Since the release of kernel 2.6.20 in 2007, Linux has had direct support Virtual Machine based on Kernel. Linux has several hypervisors available, such as , GNOME Boxes και QEMU-KVM . Χρησιμοποιούν την εγγενή δυνατότητα KVM του Linux, βασιζόμενοι στη λειτουργικότητα του εγγενούς πυρήνα, και προσθέτοντας επιπλέον δυνατότητες, όπως η δυνατότητα λήψης στιγμιότυπου μιας machine.

Virtual machines bring cost savings, efficiency, simplified solutions and (with the right provision) security benefits. They also facilitate scalability. New servers can be created automatically as demand for a service increases and terminate when demand falls. This makes them extremely popular both in the cloud and in the internal infrastructure of a data center.

If you are managing a Linux server remotely you need to know if it is a virtual machine or a physical box. But also other information, such as on what type of platform it runs. Here are some ways in which you can determine if your computer is physical or virtual.

The dmidecode command

The dmidecode command supports a large number of options and switches. Interrogates Desktop Management Interface (DMI) tables and prints the information in the ssh terminal window.

You can use it with the -s switch to request it of the system product. Note that you must use sudo.

The command is configured as follows: sudo dmidecode -s system-product-name

This command in a VirtualBox VM running the 22.04 will give:
ubuntu dmidecode
The platform is correctly identified as VirtualBox.

While in a QEMU-KVM VM running Fedora 35, you will see.
fedora dmidecode
Although referred to as a standard computer, it is a standard QEMU Q35 virtual machine. Thus the platform is correctly recognized as a virtual machine.

If you run the same command on a physical computer, you will receive some information about the manufacturer.
hw dmidecode
This computer is a custom build based on the Micro-Star International Company Limited motherboard, with product code MS-7B86.

The lshw command

The lshw command lists the details of a wide range of computer hardware. We can choose for which material category we want lshw to report.

Here we will use the -class option with the system modifier. Using sudo in this command ensures that you see all the details.

The command is configured as follows: sudo lshw -class system

If you run it on a VirtualBox running Ubuntu.
ubuntu lshw

  • The "description" field has a general "computer" entry.
  • The "product" field says that this is a virtual machine running on VirtualBox.
  • The field "vendor" contains the name of the German company that created VirtualBox, Innotek GmbH. Innotek was acquired by Oracle Corporation in 2010 as part of its acquisition of Sun Microsystems, Inc.

Similarly in Fedora running on GNOME Boxes you will receive
fedora lshw

  • Again, the "description" field has a general "computer" entry.
  • The "product" field gives the same standard QEMU computer information that we saw with the dmidecode command.
  • The "vendor" field contains "QEMU", which clearly states that it is a virtual machine.

This is the result of executing the same command on our physical computer.
hw lshw 1

You can see that this is a physical computer, with a Micro-Star motherboard.

  • The hardware is identified as a desktop computer.
  • The "product" field gives the motherboard type, MS-7B86.
  • The "vendor" field contains the name of the manufacturer.

The hostnamectl command

This command has the advantage that you do not need to have sudo permissions to execute it. However, it is only available in distributions with systemd. The majority of modern distributions use systemd.

The command is configured as follows: hostnamectl

This is the answer to running the command in VirtualBox VM with Ubuntu.
ubuntu hostnamectl

  • "-Vm" has been appended to the "icon-name" field.
  • The "Chassis" field contains "vm".
  • The "Virtualization" field contains "oracle".
  • The field "Hardware Vendor" contains "innotek GmbH".
  • The "Hardware Model" field contains "VirtualBox".

The results from the Feroda's GNOME Boxes VM are similar.
fedora hostnamectl

  • The "icon-name" field displays "-vm".
  • In the field "Chassis" there is "vm".
  • The "Virtualization" field contains "kvm".
  • In the field "Hardware Vendor" there is "QEMU"
  • "Standard PC (Q35 + ICH9, 2009)" appears in the "Hardware Model" field.

If you use the hostnamectl command on a physical computer, you will see that the "Virtualization" bar does not appear in the results.
hw hostnamectl

If you do not see the "Virtualization" field, then you have a physical computer in front of you.

The systemd-detect-virt command

If you want to get as short an answer as possible, the systemd-detect-virt command is probably what you are looking for. Again this requires a distribution equipped with systemd, but does not require sudo privileges.

The command is configured as follows: systemd-detect-virt

This is the result of running the command in VirtualBox with Ubuntu.
ubuntu systemd detect virt

Respectively in the GNOME boxes running Feroda
fedora systemd detect virt

Executing the systemd-detect-virt command on the physical machine causes a "nome" to be printed on the terminal.
hw systemd detect virt

In this command you could add more switches for more search. You can see the full list of commands using the –list option.

And to make it easier to see the list provided you put in the command and the column.
systemd-detect-virt --list | column

The above command will return you:
system detect virt list

Take the red pill
These techniques let you know when a linux distribution is running on physical hardware and when it is inside a virtual machine.

Like Nio in the Matrix, you will know what is real and what is not.

iGuRu.gr The Best Technology Site in Greecefgns

every publication, directly to your inbox

Join the 2.087 registrants.
linux, virtual, machine, systemd, hostnamectl, dmidecode

Written by Dimitris

Dimitris hates on Mondays .....

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).