Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Post 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.


  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    This is a bit complex, as checks for multiple virtualization solutions needs to be implemented.

    It is probably outside the scope of your current task (developing an app), but there is facter,
    which is best used with the systemmanagement tools puppet

    This is an example output:
    # facter | grep virtual
    is_virtual => true
    virtual => virtualbox

    Another approach would be to call dmidecode and parse for known Manufacturer/Product Name/Family
    dmidecode -q -t 1
    System Information
        Manufacturer: innotek GmbH
        Product Name: VirtualBox
        Version: 1.2
        Serial Number: 0
        UUID: 758EC42D-EC8E-4BC6-95B7-38A94144CF8C
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Virtual Machine

    But apart from that:
    I am an OPS guy and if our devs try to make the apps smart about the environment: I tell them not to do so.
    You dont want an app to behave different, just because it moved from one machine to the other.
    This is not transparent and bughunting is much harder.

    My prime example was an app, that evaluated the machines IP and decided upon that if it was running in a dev env or prod env.
    That approach was plain wrong, because a machine can have multiple IPs or ipv6 or might be moved from one network to the other, etc,etc

    My advice is:
    Use a config file.
    I dont know the reason why your app needs to behave differently on a physical host vs VM,
    but if you need that, then implement a key in your apps config file, e.g.:
    virtual = yes/no

    Easy to implement, easy to change the value, and transparent in behaviour.
    You must always face the curtain with a bow.

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Great answer Irithori! It's really just keeping in sync with the KISS principal, I think.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open
  5. #4
    Ur reply was very helpful to us.....Thanks a lot Irithori...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts