How to retrieve env value from VBoxManage startvm putenv

This is for discussing general topics about how to use VirtualBox.
Post Reply
Nelem
Posts: 3
Joined: 27. Sep 2018, 21:57

How to retrieve env value from VBoxManage startvm putenv

Post by Nelem »

Code: Select all

# VBoxManage startvm          <uuid|vmname>...
#                            [--type gui|sdl|headless|separate]
#                            [-E|--putenv <NAME>[=<VALUE>]]


I am presuming that putenv sets an environment variable inside the VM. How can I retrieve the environment variable?

I am hoping to start multiple instances of the same VM (on different hosts) and set some different configuration on each instance. Can it be done this way?

VirtualBox 5.2.18; Ubuntu 16.04 guest on Windows10 host

Cheers
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: VBoxManage startvm putenv

Post by socratis »

Nelem wrote:I am presuming that putenv sets an environment variable inside the VM.
You should have a searchable PDF included with your installation (C:\Program Files\Oracle\VirtualBox\doc). Take advantage of that fact, and use it to search the PDF for the terms that interest you. "putenv" in your example.

Although in this case, something is not right, you might have discovered an omission (or two). Because although the "startvm" from the command line mentions the "[-E|--putenv <NAME>[=<VALUE>]]" option, in the section 8.12 VBoxManage startvm there's not a single mention of that option or what it does.

On the other hand, if you look at section 8.34 VBoxManage guestcontrol, you see the exact same "[-E|--putenv <NAME>[=<VALUE>]]" option, only this time it explains that this option will modify the environment of the guest, prior to running a command inside the guest.
Nelem wrote:How can I retrieve the environment variable?
How you retrieve the variable depends on the guest. For an Ubuntu guest for example, getting the searchable path is a matter of doing:
  • echo $PATH
Nelem wrote:I am hoping to start multiple instances of the same VM (on different hosts) and set some different configuration on each instance. Can it be done this way?
I'm not sure what you have in mind, or how you envision things getting implemented, or what "configuration" you're thinking of changing. But there's also the "guestproperty" option that you could look at. Ch. 8.33 VBoxManage guestproperty for the details.
 Edit: On an Ubuntu 16.04-32bit, I couldn't get the variable that I passed with the startvm option. 
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Nelem
Posts: 3
Joined: 27. Sep 2018, 21:57

Re: How to retrieve env value from VBoxManage startvm putenv

Post by Nelem »

socratis wrote:Although in this case, something is not right, you might have discovered an omission (or two). Because although the "startvm" from the command line mentions the "[-E|--putenv <NAME>[=<VALUE>]]" option, in the section 8.12 VBoxManage startvm there's not a single mention of that option or what it does.
That's about where I got to. I was really hoping to set config for startup.
socratis wrote:On the other hand, if you look at section 8.34 VBoxManage guestcontrol, you see the exact same "[-E|--putenv <NAME>[=<VALUE>]]" option, only this time it explains that this option will modify the environment of the guest, prior to running a command inside the guest.
I'll check this out along with guestproperty.
socratis wrote:I'm not sure what you have in mind, or how you envision things getting implemented, or what "configuration" you're thinking of changing. But there's also the "guestproperty" option that you could look at.
It's network configuration of a manually-constructed tunnel IP address so ideally done at startup. It seems the guestproperty has a wait option which I'll look at now.

I've seen elsewhere in the forum that some have access to the source code. It would be great to know if startvm putenv works or is a documentation error.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How to retrieve env value from VBoxManage startvm putenv

Post by socratis »

Nelem wrote:I've seen elsewhere in the forum that some have access to the source code
Everybody has access to the source code! It's an open-source project. Here it is: https://www.virtualbox.org/browser/trunk

In the meantime, I'll try to figure out what's going on with the 'putenv' option...
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Nelem
Posts: 3
Joined: 27. Sep 2018, 21:57

Re: How to retrieve env value from VBoxManage startvm putenv

Post by Nelem »

socratis wrote:Everybody has access to the source code! It's an open-source project.
Oops. :oops: The UI is plastered with Oracle copyright notices.

I had a hell of a job making guestproperty work. I have VirtualBox 5.2.18 and Ubuntu 16.04 package 16.04 installs 5.1.38. An issue on github https://github.com/NixOS/nixops/issues/ ... -387275731 (Sorry not allowed a U R L) helped by removing all traces of previous installations inside the VM, installing the Extension_Pack for the same version and then install the LinuxExtenions inside the VM using VBoxLinuxAdditions.run.

Now it's running, I can see the IP address of the interface from VBoxManage guestproperty. If I set a new value, I can see it inside the VM using VBoxControl guestproperty. I guess I have to use VBoxManage to run a script to actually set the IP address on the interface.

After years of simply using VirtualBox from the GUI, a whole new world of possibilities is opening up.

@socratis Thanks for your help with this.
Last edited by socratis on 28. Sep 2018, 20:29, edited 1 time in total.
Reason: Fixed obfuscated URLs.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: How to retrieve env value from VBoxManage startvm putenv

Post by socratis »

Nelem wrote:The UI is plastered with Oracle copyright notices.
Open source doesn't mean no copyright... ;)
Nelem wrote:I had a hell of a job making guestproperty work.
The article you linked to on Github talks about DKMS. VirtualBox hasn't used DKMS since 5.0.x. What most probably happened is that the users there had a mix of the forked VirtualBox (the ones that comes from the distro "store") with the official VirtualBox from https://www.virtualbox.org/wiki/Linux_Downloads. What needs to be done is to completely delete/purge/nuke any traces of VirtualBox and install the official one only.
Nelem wrote:then install the LinuxExtenions inside the VM using VBoxLinuxAdditions.run.
You mean the Guest Additions.
Nelem wrote:After years of simply using VirtualBox from the GUI, a whole new world of possibilities is opening up.
Imagine if you go to the API and start programming VirtualBox directly... ;)
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Post Reply