Page 1 of 2
How is the VirtualBox.xml file created?
Posted: 30. Jan 2017, 18:12
by Mers101
I'm trying to dynamically add and delete machines from the users VirtualBox.xml file. This is so I can package the VM's and make them available to users using some custom software we have at the University.
The VirtualBox.xml file which lives in C:\Users\<user>\.VirtualBox seems to be built by default with certain nodes/elements. Even if I already have a default VirtualBox.xml file in the user profile certain elements are added. The one which is causing me problems is the <MachineRegistry /> node, to confuse things further it sometimes shows up as <MachineRegistry/> (no space after forward slash).
If I manually edit the VirtualBox.xml file after VirtualBox has opened/closed and delete the <MachineRegistry /> node then this node doesn't show up again (unless you add a machine and remove so no machines are available in VirtualBox GUI).
Does anybody know how these elements are built and how I can stop the empty node <MachineRegistry /> from being created?
EDIT: I know I could use vboxmanage commands but this takes too long and there would be student complaints.
Re: How is the VirtualBox.xml file created?
Posted: 30. Jan 2017, 18:16
by scottgus1
Virtualbox.xml is made on-the-fly by Virtualbox - you should not edit it. Your edits can and will be deleted. See the warning at the top of the file.
Use Vboxmanage to edit the guests available. See the manual, section 8.
The best way to supply guests if you are still going to use them in Virtualbox is with a guest folder copy. See this tutorial
Moving a VM and re-interpret it as "Copying a VM". Also good for "Backing Up a VM". Then teach your students to register the guests or write a script using Vboxmanage commands to delete & register guests.
Re: How is the VirtualBox.xml file created?
Posted: 30. Jan 2017, 18:22
by Mers101
I know I can use VBOXManage.exe but it takes too long to complete. Students are quick to complain when things take too long.
I'm not editing the .xml file while VirtualBox is open, so my changes aren't going to be overwritten. My script works fine as long as this empty <MachineRegistry /> node isn't present.
Re: How is the VirtualBox.xml file created?
Posted: 30. Jan 2017, 18:25
by scottgus1
Then you'll have to make your script more robust.
FWIW, you can register a new guest by double-clicking the .vbox file, instead of using Vboxmanage. Or you can use Vboxmanage in a batch file and provide a shortcut to the script. Or even a shortcut to the .vbox file.
Re: How is the VirtualBox.xml file created?
Posted: 30. Jan 2017, 18:27
by scottgus1
Mers101 wrote:Students are quick to complain when things take too long.
That's life; sometimes things take a long time. Isn't that the point of teaching them?
On the other hand, someone - I don't remember who to credit - on Stack Exchange said this:
If you can't figure out how to solve the problem, redefine the problem.
Re: How is the VirtualBox.xml file created?
Posted: 30. Jan 2017, 18:31
by socratis
Mers101 wrote:I'm trying to dynamically add and delete machines from the users VirtualBox.xml file.
Don't. Not manually. Create a "template" user and modify that one. If you do want to add/delete to that user from the CLI, use VBoxManage. If any VirtualBox process is running, that file is in memory and any edit will be ignored. Once you're satisfied with your changes, lock the template.
<MachineRegistry /> (with a space) should not appear. It's invalid XML. It should
not exist in an XML file. No closing tag has a space before it because it's not permitted. Here's a virgin VirtualBox.xml for comparison:
Code: Select all
<?xml version="1.0"?>
<!--
** DO NOT EDIT THIS FILE.
** If you make changes to this file while any VirtualBox related application
** is running, your changes will be overwritten later, without taking effect.
** Use VBoxManage or the VirtualBox Manager GUI to make changes.
-->
<VirtualBox xmlns="http://www.virtualbox.org/" version="1.12-macosx">
<Global>
<ExtraData>
<ExtraDataItem name="GUI/DetailsPageBoxes" value="general,system,preview,display,storage,audio,network,usb,sharedFolders,description"/>
<ExtraDataItem name="GUI/LastWindowPosition" value="575,292,770,550"/>
<ExtraDataItem name="GUI/SplitterSizes" value="254,509"/>
<ExtraDataItem name="GUI/UpdateCheckCount" value="2"/>
<ExtraDataItem name="GUI/UpdateDate" value="1 d, 2017-01-31, stable, 5.1.14"/>
</ExtraData>
<MachineRegistry/>
<NetserviceRegistry>
<DHCPServers>
<DHCPServer networkName="HostInterfaceNetworking-vboxnet0" IPAddress="192.168.56.100" networkMask="255.255.255.0" lowerIP="192.168.56.101" upperIP="192.168.56.254" enabled="1"/>
</DHCPServers>
</NetserviceRegistry>
<SystemProperties defaultMachineFolder="/Users/Guest/VirtualBox VMs" defaultHardDiskFormat="VDI" VRDEAuthLibrary="VBoxAuth" webServiceAuthLibrary="VBoxAuth" LogHistoryCount="3" exclusiveHwVirt="false"/>
<USBDeviceFilters/>
</Global>
</VirtualBox>
Re: How is the VirtualBox.xml file created?
Posted: 31. Jan 2017, 10:34
by Mers101
socratis: Create a "template" user and modify that one.
How do I create the template user and modify? Part of my script checks to make sure VirtualBox isn't running before making modifications, any changes I make don't get overwritten.
<MachineRegistry /> with space is definitely appearing in my VirtualBox.xml file. All I'm doing is opening VirtualBox, closing it down then it appears. It sometimes does appear without the space as well!
Re: How is the VirtualBox.xml file created?
Posted: 31. Jan 2017, 12:39
by socratis
Attach (not copy/paste) an instance where there is a space in the <MachineRegistry /> VirtualBox.xml file please. And describe exactly the conditions that it was created.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 13:22
by Mers101
I can't recreate it every time, seems to be random. Next time it happens I'll upload the file.
The <MachineRegistry/> or <MachineRegistry /> (no machines attached in VirtualBox) node are definitely being recreated in the .xml file after I programmatically remove it from the file. If I manually delete the node from the VirtualBox.xml file, open and close VirtualBox that node is not recreated.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 15:43
by Perryg
Weird things happen when you manually edit that file as evidenced in the preamble of the file itself. You must be certain that the VBoxsvc process is completely stopped which does not happen right away.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 16:30
by Mers101
Manually editing the file isn't the problem. If I manually remove the <MachineRegistry/> node and save it then it doesn't come back (until a machine has been added/removed so no more remain in VirtualBox).
My problem is that when I edit the file using a PowerShell script, which I've checked is fine after editing, that it just reverts back to a previous state as soon as VirtualBox is opened.
If I explain my problem in a little more detail. I'm using some packaging software to deliver applications to machines. One package I have created is VirtualBox. There is the potential for there to be 11 VM's to be made available to the students. My approach is to package the VM's so the necessary disk and vbox files live in a certain location C:\VirtualBox\VMs (vbox files & snapshots) C:\VirtualBox\Vdisk (vdisk files). Under each of these folders will be another folder for each OS.
Applications are delivered to students, when they launch the application via the web portal it then becomes available to them. So a student would select VirtualBox from the list of available apps, which then installs. Then whichever VM they want. They can have any combination of the 11 VM's then installed. Which is why I'm trying to dynamically add/remove machine entries from the xml file.
The idea behind this software is that we can then make the applications available to students in many more labs/locations. So a student could go over to the library for instance, log in and VirtualBox and all VM's would be available. They get pulled down to the machines as and when needed. I can't guarantee, nor do I want to, that 80-90Gb of data (11 VMs) is installed on every single machine where this app delivery method is available.
Hope this makes sense.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 16:33
by scottgus1
Mers101 wrote:My problem is that when I edit the file using a PowerShell script, which I've checked is fine after editing, that it just reverts back to a previous state as soon as VirtualBox is opened.
Perryg wrote:You must be certain that the VBoxsvc process is completely stopped which does not happen right away.
socratis wrote:Mers101 wrote:I'm trying to dynamically add and delete machines from the users VirtualBox.xml file.
Don't. Not manually... If any VirtualBox process is running, that file is in memory and any edit will be ignored.
scottgus1 wrote:Your edits can and will be deleted. See the warning at the top of the file.
Mers101 wrote:Hope this makes sense.
See the gist of how things are going? You're barking up the wrong tree so far that you've run out of tree. You are going about this the wrong way.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 16:41
by scottgus1
Mers101 wrote: My approach is to package the VM's so the necessary disk and vbox files live in a certain location C:\VirtualBox\VMs (vbox files & snapshots) C:\VirtualBox\Vdisk (vdisk files).
This is not the recommended folder structure. The disk for each guest should be in the guest folder along with the guest .vbox file and Snapshots folder. Your setup will be really hard for your students to back up and restore. The best way to backup is a simple folder-copy of the guest folder after the guest is shut down. See this tutorial
Moving a VM and re-interpret it as "Backing Up a VM". The best way to allow this kind of best backup is to have all the guest files including the disk in one folder.
Mers101 wrote:They can have any combination of the 11 VM's then installed. Which is why I'm trying to dynamically add/remove machine entries from the xml file.
You can put Vboxmanage commands in your script instead of the custom tweak-the-XML parts, and have perfect results every time without any overwrites of your script-generated edits. And you can make the Vboxmanage scripts per machine instead of global for the entire eleven guests, so there is still customization of which guests to download available.
None of what you're attempting to do requires script-generated Virtualbox.xml edits and are all completely doable with script-launched Vboxmanage commands.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 17:14
by Mers101
scottgus1
Thanks for your input and suggestions. I really appreciate it.
My initial approach was to use a vboxmanage command
Code: Select all
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "Centos Desktop.ova" --vsys 0 --unit 11 --disk "C:\VirtualBox\vdisks\Centos Desktop\Centos Desktop-disk1.vmdk"
This took way too long for some reason, students always complain if something doesn't happened quickly enough! Which led me down this path I'm on now.
Re: How is the VirtualBox.xml file created?
Posted: 1. Feb 2017, 17:23
by Perryg
My problem is that when I edit the file using a PowerShell script, which I've checked is fine after editing, that it just reverts back to a previous state as soon as VirtualBox is opened.
I don't want to beat a dead horse but what you just described is what I posted would happen. You must be sure that all VBox processes are stopped. From what you post it appears they are not.
I will back out now since this is all I had to offer.