An interesting question. I have logged into a Linux (most likely SuSE) host. Is there some way that I can tell programmatically that I am a VM host or not?

Also assume that the vmtools are not installed.

link|improve this question

50% accept rate
feedback

9 Answers

Some virtual environments name some of their virtual devices with names that are a bit tell-tale, for example, VirtualBox presenting a graphics card that calls itself "VirtualBox Display Adapter". But looking for those ties you to a particular VM and possibly a narrow range of versions.

It might be possible for your code to see what sort of virtualisation it could set up. If that fails entirely, you might be in a VM. But you just as might easily be on a box that doesn't have any VM capable hardware.

link|improve this answer
Your first answer was the right one. Check device driver names. – Izzy Sep 15 '09 at 23:47
feedback

There is a handy app that might help called virt-what and it can be downloaded here http://et.redhat.com/~rjones/virt-what/. I haven't used it with VMWare, but it did work nicely with Qemu.

link|improve this answer
1  
Unfortunately the binary RPM has two dependancies dmidecode and util-linux-ng when tried on SuSE commercial. – mdpc Sep 16 '09 at 17:49
feedback

You might be able to get and idea by looking around in /sys/. For example /sys/class/dmi/id/sys_vendor has a value of 'VMware, Inc.'

If it is installed you can use lshw. The command lshw -class system on my system returns this.

server1
    description: Computer
    product: VMware Virtual Platform
    vendor: VMware, Inc.
    version: None
    serial: VMware-...
    width: 64 bits
    capabilities: smbios-2.4 dmi-2.4 vsyscall64 vsyscall32
link|improve this answer
On the SuSE instances that I have access to lshw does not exist. Further, the /sys/class/dmi/... does not exist. – mdpc Sep 15 '09 at 23:53
feedback

You could also search the first part of your mac address here and see if it's listed as assigned to any of the virtualization companies.

link|improve this answer
Interesting idea....I think that works (as long as a network device is included in the VM ;-)) – mdpc Sep 16 '09 at 18:18
feedback

There's lots of code out there to detect if you're in a VM or not. Start with red pill and search from there. This paper at Offensive Computing is also a good read.

That's if none of those easy ones above work :)

link|improve this answer
feedback

Virtual devices will also be revealed by lspci and/or disk device info in /proc:

lspci | grep -i vmware

grep -i vmware /proc/scsi/scsi /proc/ide/*/model
link|improve this answer
feedback

IF the VMwareTools package has been installed, you can do:

rpm -qa | grep -i vmware
link|improve this answer
feedback

I didn't like any of these solutions, there's usually a VMware CDROM driver or memory driver installed so dmesg confirms or deny's it for me quickly.

[server@user ~]$ dmesg |grep VMware

hda: VMware Virtual IDE CDROM Drive, ATAPI CD/DVD-ROM drive

Vendor: VMware Model: Virtual disk Rev: 1.0

Vendor: VMware Model: Virtual disk Rev: 1.0

Vendor: VMware Model: Virtual disk Rev: 1.0

Vendor: VMware Model: Virtual disk Rev: 1.0

Vendor: VMware Model: Virtual disk Rev: 1.0

Vendor: VMware Model: Virtual disk Rev: 1.0

Vendor: VMware Model: Virtual disk Rev: 1.0

VMware memory control driver initialized

link|improve this answer
This will work at startup, but later you can't guarantee that dmesg hasn't been cleared or overflowed. – mattdm Feb 3 '11 at 14:57
feedback
cat /proc/scsi/scsi

or

ethtool -i eth0

or

dmidecode | grep -i vmware
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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