Page 1 of 1

How to tell when running virtualized? SOLVED

Posted: 25. Nov 2009, 02:00
by alterkacker
I have Ubuntu installed natively on my hard drive, and would like to run it either natively or hosted in VBox under Windows using a raw hard disk. I have it working mostly just fine, but would like to find a way for the the Ubuntu guest to be able to determine whether it's running hosted or natively at boot time. I've seen the 'guestproperty' settings but that's only available once the VM is running. I know I could use two different sections in the Grub menu.lst file and pass some keyword on the boot line, but I'd like it to be automatic. Ideas?

Thanks!

BTW, I just switched to VirtualBox from VMWare and love it! It's amazing that software of this quality is available for free.

Re: How to tell when running virtualized?

Posted: 25. Nov 2009, 02:55
by MarkCranness
You might find the source for dmidecode (assuming it is open source) and see how they query the DMI BIOS settings. Then check the returned value for a VirtualBox specific string. Or pipe the output of dmidecode into some sort of shell search (grep?)

Re: How to tell when running virtualized?

Posted: 25. Nov 2009, 03:22
by alterkacker
Perfect, Mark!

When running native:
dmidecode -s bios-vendor > Dell Inc.

When running under VBox:
dmidecode -s bios-vendor > innotek GmbH

So a simple grep will tell me what I want. Thanks, I don't know if I ever would have thought of that.