Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

11 Answers 11

up vote 6 down vote accepted
cat /proc/scsi/scsi

or

ethtool -i eth0

or

dmidecode | grep -i vmware
share|improve this answer
3  
Can you explain what these commands do, instead of only providing vague commands? –  Stefan Lasiewski Jun 4 at 19:33

There is a handy app that might help called virt-what. I haven't used it with VMWare, but it did work nicely with Qemu.

share|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

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.

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

indicates that it’s a VM. If it returned “physical” then the opposite is true (not a VM), eg:

facter virtual
Physical
share|improve this answer
    
However, this is a non-standard special package....but I like it. –  mdpc Jan 22 '13 at 19:36
1  
@mdpc It should be present on any system using puppet. –  Michael Hampton Jul 22 '13 at 6:59

You might be able to get and idea by looking around under /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 returns this on my system:

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
share|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

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 :)

share|improve this answer

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.

share|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
2  
Won't be reliable. In many cases the mac can be set to an arbitrary value. This to enable cloning the mac of the original machine when converting it to VM. Some software ties its license to the mac and often it is impossible to get a new license (vendor went bust or costs is prohibitive). –  Tonny Jan 22 '13 at 20:24

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
share|improve this answer

I didn't like any of these solutions, as there's usually a VMware CDROM driver or memory driver installed so dmesg confirms or denies 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
share|improve this answer
3  
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
    
This is what I usually do too, that is grepping dmesg –  hyphen this Aug 18 at 13:53

For Linux you type dmesg |grep DMI:

VIRTUAL HOST OUTPUT

[root@myhost ~]# dmesg |grep DMI
DMI 2.3 present.
DMI: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS 090006  05/23/2012

[root@myhost ~]# dmesg |grep -i virtual
DMI: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS 090006  05/23/2012
Booting paravirtualized kernel on bare hardware
input: Macintosh mouse button emulation as /devices/virtual/input/input1
scsi 0:0:0:0: Direct-Access     Msft     Virtual Disk     1.0  PQ: 0 ANSI: 4
input: Microsoft Vmbus HID-compliant Mouse as /devices/virtual/input/input4

FOR PHYSICAL HOST EXAMPLE

[root@backdev1 ~]# dmesg |grep DMI
DMI 2.5 present.
DMI: IBM System x3650 M3 -[7945AC1]-/90Y4784, BIOS -[D6E153AUS-1.12]- 06/30/2011
share|improve this answer
1  
a major problem with your solution is that dmesg reads out the kernel buffer and it is of limited size. If there are a lot of messages or a bit of time since the system has been rebooted, then this information will not be available. –  mdpc Apr 10 at 20:05

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

rpm -qa | grep -i vmware
share|improve this answer

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.