Home Linux Community Forums Linux System Administration Cloud Management Runtime identification of virtualized environment

Runtime identification of virtualized environment

Link to this post 05 Jan 12

I am a new to Linux/ Virtual Box. I am writing an application which is supposed be run on Virtualized env and also on standalone linux machines and the app is supposed to do different task based on the environment .

I would like to identify on runtime, if my app is running on virtualized env (Virtual Box with guest OS as ubuntu and host OS as windows) OR if the app is running on standalone Linux (ubuntu) machine.

Is there any env / config file within the ubuntu OS which will tell me the details required.

Initially i considered, differentiation based on VBoxGuestAddition installable can help, but guestAddition installation is not mandatory on all VBox machine.

Is there any alternate way for this identification.

I am looking for some command or some unique file which will tell that my application is running in virtual box or not.

Any help in this regard will be very helpful.


Link to this post 05 Jan 12


Interesting question.

I would think the absolute easiest way to do this would be to check for virtual devices for the solution you're using.

For example if I want to find out whether a machine is a VirtualBox VM or not I can look for the VirtualBox Graphics device:

lspci | grep VirtualBox\ Graphics | wc -l

That will return 0 if the machine is not a VBox VM and a 1 if it is.

Now obviously this will only work for VirtualBox as it's looking for a specific device. However I think you could very easily add the same detection for other virtualiztion platforms with minimal effort.

Hope that helps.

EDIT: I was talking about virtual devices not drivers, I blame a lack of coffee for the flub.


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Linux Training / Board

/** BC-056 Ameex changes to add tracking code - 2016-01-22 **/ ?>