Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a command or tool that can be used to determine whether Ubuntu is running as a guest within a virtualization program such as VirtualBox or Qemu or whether it is running on the bare metal?

share|improve this question

3 Answers 3

up vote 11 down vote accepted

virt-what Install virt-what Install via the software center

is a shell script which can be used to detect if the program is running in a virtual machine.

The program prints out a list of "facts" about the virtual machine, derived from heuristics. One fact is printed per line.

If nothing is printed and the script exits with code 0 (no error), then it can mean either that the program is running on bare-metal or the program is running inside a type of virtual machine which we don't know about or cannot detect.

SUMMARY

sudo virt-what [facts]

FACTS

hyperv
    This is Microsoft Hyper-V hypervisor.

kvm This guest is running on the KVM hypervisor using hardware
    acceleration.

    Note that if the hypervisor is using software acceleration you
    should *not* see this, but should see the "qemu" fact instead.

openvz
    The guest appears to be running inside an OpenVZ or Virtuozzo
    container.

qemu
    This is QEMU hypervisor using software emulation.

    Note that for KVM (hardware accelerated) guests you should *not* see
    this.

virt
    Some sort of virtualization appears to be present, but we are not
    sure what it is. In some very rare corner cases where we know that
    virtualization is hard to detect, we will try a timing attack to see
    if certain machine instructions are running much more slowly than
    they should be, which would indicate virtualization. In this case,
    the generic fact "virt" is printed.

virtualbox
    This is a VirtualBox guest.

virtualpc
    The guest appears to be running on Microsoft VirtualPC.

vmware
    The guest appears to be running on VMware hypervisor.

Sorry but this is your GUY.... ;)

share|improve this answer

imvirt (not installed by default but available in in universe repository)

share|improve this answer

Run lspci and check for the string 'VirtualBox'.

You could run lspci | grep VirtualBox.

You could also run lsusb and check the string 'VirtualBox'. Such as lsusb | grep VirtualBox.

Also dmesg works, run dmesg | grep VirtualBox or dmesg | grep virtual.

share|improve this answer
    
At least one virtualbox message may appear on a host running virtualbox guests, so I'd drop the dmesg option. But lspci and lsusb are good. –  Joe P Oct 25 '11 at 19:58
    
I think command line solutions are better than installing packages. If you have superuser privileges on a system (to install packages) are you likely to be unsure if it's virtualised or not? –  Joe P Oct 25 '11 at 20:01
    
@JoeP You're right - except... What if you're running a script on all of your machines and it needs to know whether the host is virtualized or not? –  Mei Jun 21 '12 at 20:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.