[Solved] How to determine if this script is running under VM
[Solved] How to determine if this script is running under VM
I have a script which needs to do A depending if its invoked inside a VM and do B otherwise.
Is there a way to do this using virtualbox scripts/binaries? vmware has vmware-checkvm which does this.
Is there a way to do this using virtualbox scripts/binaries? vmware has vmware-checkvm which does this.
-
Sasquatch
- Volunteer
- Posts: 17798
- Joined: 17. Mar 2008, 13:41
- Primary OS: Debian other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Windows XP, Windows 7, Linux
- Location: /dev/random
Could you give more information about this feature? If you want to run a script, and depending if it runs on your VM or your Guest it executes a certain command, you might want to do a certain hardware check or other check that you put on the Guest and Host and run it through an if statement.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org
Retired from this Forum since OSSO introduction.
There is a script which I run during init of linux. This script can run during normal native boot or run inside the VM using vritualbox. I just want to do different things in this script depending upon whether I am running inside VM or running native.
For example, xorg.conf is different for a native boot and a boot inside VM. I just want to be able to flip the xorg.conf to virtualbox specific xorg.conf if its inside VM.
For example, xorg.conf is different for a native boot and a boot inside VM. I just want to be able to flip the xorg.conf to virtualbox specific xorg.conf if its inside VM.
-
TerryE
- Volunteer
- Posts: 3572
- Joined: 28. May 2008, 08:40
- Primary OS: Ubuntu other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
- Contact:
The VM has some is a different machine to the physical one so it is quite easy to detect variations in configuration. A good example is if you have GA installed then you can do an existence check on /dev/vboxadd, but even if you don't want to rely on GA being installed you can still probe /proc for things like grep /proc/cpuinfo pae or one of the flags that VBox always turns off (see the Vbox.log).
Anyway that's my suggestion for two cents.
Anyway that's my suggestion for two cents.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
Google your Q site:VirtualBox.org or search for the answer before posting.
-
greenpossum
- Volunteer
- Posts: 98
- Joined: 11. Jul 2008, 08:10
How to determine if this script is running under VM
You could check the model of the hard disk, if your config has one, for example
givescat /sys/block/sda/device/model
VBOX HARDDISK
-
TerryE
- Volunteer
- Posts: 3572
- Joined: 28. May 2008, 08:40
- Primary OS: Ubuntu other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
- Contact:
Nice one, though that will fail if sda is not connected. You might want to do a test based on grepping sd*
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
Google your Q site:VirtualBox.org or search for the answer before posting.
based upon ideas from here, I think best check is probably for 'lspci|grep -i vga|grep -i virtualbox'
Can someone please tell me why does copy-paste with mouse not work from guest-to-host and vice versa? I just realized this when I was trying to copy paste that lspci command from guest to this text box....
GA 1.6.4. is running in the guest.
Can someone please tell me why does copy-paste with mouse not work from guest-to-host and vice versa? I just realized this when I was trying to copy paste that lspci command from guest to this text box....
GA 1.6.4. is running in the guest.
-
TerryE
- Volunteer
- Posts: 3572
- Joined: 28. May 2008, 08:40
- Primary OS: Ubuntu other
- VBox Version: VirtualBox+Oracle ExtPack
- Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
- Contact:
I think that your suggestion of using the output of the lspci enumerator is a good one, and I would just search for "VirtualBox Graphics Adapter" giving a test:
As to your supplementary see Forum Posting Guide: one topic one Q. Has a scan: a common Q. 
Code: Select all
if [ `lspci | grep -c "VirtualBox Graphics Adapter"` -eq "1" ]; then ...Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
Google your Q site:VirtualBox.org or search for the answer before posting.
those muscles are going to ache...ease up a little, will ya....TerryE wrote:I think that your suggestion of using the output of the lspci enumerator is a good one, and I would just search for "VirtualBox Graphics Adapter" giving a test:As to your supplementary see Forum Posting Guide: one topic one Q. Has a scan: a common Q.Code: Select all
if [ `lspci | grep -c "VirtualBox Graphics Adapter"` -eq "1" ]; then ...
yeah, I will search. But if I was you and I knew the answer, I would write it anyway. We are all here to help each other and reduce pain, right?