Results 1 to 4 of 4
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 ...
- 01-05-2012 #1Just Joined!
- Join Date
- Jan 2012
- Posts
- 2
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.
Thanks,
- 01-05-2012 #2
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:
Code:# facter | grep virtual is_virtual => true virtual => virtualbox
Another approach would be to call dmidecode and parse for known Manufacturer/Product Name/Family
Code: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.
- 01-07-2012 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,977
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!
- 01-09-2012 #4Just Joined!
- Join Date
- Jan 2012
- Posts
- 2
Ur reply was very helpful to us.....Thanks a lot Irithori...


1Likes
Reply With Quote