Welcome to the Linux Foundation Forum!

Runtime identification of virtualized environment

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.



  • LegacyUserLegacyUser Posts: 0
    edited January 2012

    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.

Sign In or Register to comment.