Friday, April 13, 2012

How to know if the machine you are working on are a VM

There are a few ways you can detect if the machine you are working on is a VM. Below are commands to use and the output if your machine is a VM:

  1. Use dmidecode command, dmidecode is a tool for dumping a computer DMI (some say SMBIOS) table contents in a human-readable format. So if your machine is a vm, you should not get any output:
    [somebody@theserver ~]$ sudo dmidecode
    # dmidecode 2.10
    /dev/mem: mmap: Bad address
  2. Try check on /proc/scsi/scsi, if it is a vm, you would not get any attached device:
    [somebody@theserver ~]$ cat /proc/scsi/scsi 
    Attached devices:

  3. Use lspci and see if there is any virtual related devices:
    [somebody@theserver ~]$ /sbin/lspci 
    00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
    00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
    00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
    00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
    00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
    00:02.0 VGA compatible controller: Cirrus Logic GD 5446
    00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
    00:04.0 Ethernet controller: Red Hat, Inc Virtio network device
    00:05.0 SCSI storage controller: Red Hat, Inc Virtio block device
    00:06.0 RAM memory: Red Hat, Inc Virtio memory balloon
    00:07.0 SCSI storage controller: Red Hat, Inc Virtio block device
  4. Check on your network interface:
    [somebody@theserver ~]$ /sbin/ethtool -i eth0
    driver: virtio_net
    version:
    firmware-version:
    bus-info: virtio0
  5. Use dmesg and search for word virt, KVM, vmware, xen:
    [somebody@theserver ~]$ dmesg | grep -i vir
    Booting paravirtualized kernel on KVM
    CPU0: Intel QEMU Virtual CPU version (cpu64-rhel6) stepping 03
    input: Macintosh mouse button emulation as /devices/virtual/input/input1
    virtio-pci 0000:00:03.0: PCI INT A -> Link[LNKC] -> GSI 10 (level, high) -> IRQ 10
    virtio-pci 0000:00:04.0: PCI INT A -> Link[LNKD] -> GSI 11 (level, high) -> IRQ 11
    virtio-pci 0000:00:05.0: PCI INT A -> Link[LNKA] -> GSI 10 (level, high) -> IRQ
    [somebody@theserver2:~]$ dmesg | grep -i -e virt
    [ 0.000000] Booting paravirtualized kernel on Xen
    [ 0.102602] input: Macintosh mouse button emulation as /devices/virtual/input/input0
    [ 3.577404] Initialising Xen virtual ethernet driver