One of my favourite tools, dmidecode, can be used to dump a computer's desktop management interface (DMI) table. In practice, this means that it can be used to find out what kind of hardware you're running in a machine.
This command requires root access, so we'll be using sudo throughout these examples.
First, we're going to list the valid types we can pass to dmidecode:
$ dmidecode --type
dmidecode: option '--type' requires an argument
Type number or keyword expected
Valid type keywords are:
bios
system
baseboard
chassis
processor
memory
cache
connector
slot
Starting at the top, we're going to use bios and see if it gives us anything useful:
$ sudo dmidecode --type bios
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.
Handle 0x0000, DMI type 0, 20 bytes
BIOS Information
Vendor: innotek GmbH
Version: VirtualBox
Release Date: 12/01/2006
Address: 0xE0000
Runtime Size: 128 kB
ROM Size: 128 kB
Characteristics:
ISA is supported
PCI is supported
Boot from CD is supported
Selectable boot is supported
8042 keyboard services are supported (int 9h)
CGA/mono video services are supported (int 10h)
ACPI is supported
Instantly, we can see VirtualBox next to Version, which is a pretty strong hint that we're dealing with a VM.
Next, we will choose something else, system:
$ sudo dmidecode --type system
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.
Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: innotek GmbH
Product Name: VirtualBox
Version: 1.2
Serial Number: 0
UUID: BDC643B8-8D4D-4288-BDA4-A72F606CD0EA
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Virtual Machine
Again, the Product Name seen here is VirtualBox, and the Family is Virtual Machine, both of which are pretty damning pieces of evidence.
Lastly, we're going to look at the Chassis Information:
$ sudo dmidecode --type chassis
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.
Handle 0x0003, DMI type 3, 13 bytes
Chassis Information
Manufacturer: Oracle Corporation
Type: Other
Lock: Not Present
Version: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: None
Oracle corporation is, again, a significant piece of information that leads us to believe we're in a virtualized environment.
If we don't want a lot of other information, we can fine-tune our search using dmidecode's -s option.
Running this option without an argument outputs a list of potential arguments we can use:
$ sudo dmidecode -s
dmidecode: option requires an argument -- 's'
String keyword expected
Valid string keywords are:
bios-vendor
bios-version
bios-release-date
system-manufacturer
system-product-name
system-version
system-serial-number
system-uuid
baseboard-manufacturer
baseboard-product-name
baseboard-version
baseboard-serial-number
baseboard-asset-tag
chassis-manufacturer
chassis-type
chassis-version
chassis-serial-number
chassis-asset-tag
processor-family
processor-manufacturer
processor-version
processor-frequency
Here, we can instantly see bios-version, and as we know from earlier, it should be VirtualBox:
$ sudo dmidecode -s bios-version
VirtualBox
These types of short-output commands are very useful for scripting, where succinctness is sometimes desirable.
dmidecode is usually installed by default, at least on Ubuntu and CentOS installations.