Page 1 of 1

How to retrieve VirtualBox VM machine directory?

Posted: 21. Jan 2018, 19:42
by _nobody_
Hello To VirtualBox forum,

I have very interesting question (no doubt many have asked this before): How to retrieve VirtualBox VM machine directory?

The one of the solutions is the following: to retrieve VirtualBox VM machine directory from ~/.config/VirtualBox/VirtualBox.xml (using not so nice formatted bash script):

Code: Select all

#!/bin/bash
cd $HOME/.config/VirtualBox
VBOX_IMG_DIR=`cat VirtualBox.xml | grep defaultMachineFolder | grep -o -P '(?<=").*(?=" default)'`
echo $VBOX_IMG_DIR
exit
But I would like to do it the following CLI way: https://www.virtualbox.org/manual/ch08.html
Something like this: https://www.virtualbox.org/manual/ch08. ... showvminfo

The closest command I was able to google is the following:
[vuser@localhost debian9]$ vboxmanage list hdds
UUID: eb7dfcf7-25dc-4dfc-8f0b-5d0197d85715
Parent UUID: base
State: created
Type: normal (base)
Location: /home/vuser/projects2/vagrant/VMs/stretch64_default_1516453554349_65841/stretch.vmdk
Storage format: VMDK
Capacity: 10140 MBytes
Encryption: disabled

[vuser@localhost debian9]$
I am not able to find the exact CLI command, I am sure it is somewhere there. :mrgreen:

Thank you,
_nobody_

Re: How to retrieve VirtualBox VM machine directory?

Posted: 21. Jan 2018, 20:47
by socratis
You should have mentioned your host, but since you mentioned 'bash', try:

Code: Select all

VBoxManage list systemproperties | grep "Default machine folder" | cut -b 34-

Re: How to retrieve VirtualBox VM machine directory?

Posted: 22. Jan 2018, 17:45
by _nobody_
> You should have mentioned your host...

I will (did not feel it is so important). It is Fedora 27, and here is the kernel I am using: 4.14.13-300.fc27.x86_64

And here is small script I wrote, in order to maintain relations between Vagrant and Virtual Box. Please, do note that Vagrant is very aware of Virtual Box (it is an abstraction layer for creating with the generic commands VM, using different underlying VMMs - in this case Virtual Box), and Virtual Box has no "any" idea that some entity above is scavenging its config files and abstracting the commands, making them generic. :roll:

Code: Select all

## Print out all the relevant data for the vagrant machine and underlying Virtual Box
## Find Virtual Box VM machine directory
VBOX_IMG_DIR=`vboxmanage list systemproperties | grep "Default machine folder" | cut -b 34-`
echo "Virtual Box VM machine directory: $VBOX_IMG_DIR"

if [ ! -d ".vagrant" ]; then
    echo "vagrant machine not created"
    exit 1
fi

## Find the UUID of the currently used Virtual Box machine
vbox_uuid=`cat .vagrant/machines/default/virtualbox/id`
echo "The UUID of the currently used Virtual Box machine $vbox_uuid"

## Find the UUID of the currently used vagrant machine
vagrant_uuid=`cat .vagrant/machines/default/virtualbox/index_uuid`
echo "The UUID of the currently used vagrant machine $vagrant_uuid"

echo "What vagrant machines are active in the system?"
vagrant box list

echo "What Virtual Box machines are active in the system?"
vboxmanage list vms
And the results on my host (Fedora 27) from executing the script above:
[vuser@localhost fedora27]$ ./info_vm.sh
Virtual Box VM machine directory: /home/vuser/projects2/vagrant/VMs
The UUID of the currently used Virtual Box machine d8a47d82-5808-4089-94dd-1e6cf2a2db89
The UUID of the currently used vagrant machine ed3ef76bfa2a45c1973870825e685138
What vagrant machines are active in the system?
debian/stretch64 (virtualbox, 9.3.0)
generic/fedora27 (virtualbox, 1.3.40)
What Virtual Box machines are active in the system?
"cip-b_at_d-generic_default_1516618400501_81341" {a84e36bd-d2f1-448b-8932-7eff467fccc7}
"fedora27_default_1516632277842_3407" {d8a47d82-5808-4089-94dd-1e6cf2a2db89}
[vuser@localhost fedora27]$
If anybody needs any advice in these relations [Vagrant -> VBox], I can answer here... Lot of experience last two weeks playing with Vagrant and VBox! :mrgreen:

_nobody_

Re: How to retrieve VirtualBox VM machine directory?

Posted: 22. Jan 2018, 19:34
by socratis
_nobody_ wrote:I will (did not feel it is so important).
If it's not *nix based (i.e. Windows), the script won't work. At least not with a lot of work... ;)
_nobody_ wrote:If anybody needs any advice in these relations [Vagrant -> VBox], I can answer here
No, please don't, I will be forced to lock the topic. Vagrant is a program that relies on VirtualBox but modifies its configuration files in unknown ways to us. It is not supported on these VirtualBox user forums, they have their own Vagrant support channels. If anyone has a problem with a standalone version of VirtualBox, then we can continue this discussion here, if it's Vagrant related, to the Vagrant sites.

Re: How to retrieve VirtualBox VM machine directory?

Posted: 23. Jan 2018, 05:59
by _nobody_
> Vagrant is a program that relies on VirtualBox but modifies its configuration files in unknown ways to us.

Vagrant (Vagabond, with other English word) supposed to be generic agent, siting on top of "any" different VMM (KVM, Virtual Box, VMWare...). It does, but indeed, it does modify something (I have notice this). And this is... The Crap. I must admit, it behaves from time to time unpredictable, and I have a lot of trouble to stabilize this bounty application on the top of Virtual Box. The real problem is that Vagrant, if used, MUST completely control VBox, so VBox itself (except vboxmanage commands for info purposes, as example my script invented for the cause) should not be used. I'll take further action with Vagrant people. :mrgreen:

> No, please don't, I will be forced to lock the topic.

Consider that the deal is done. I certainly will return back, since I'll need (I think) some help with bare Virtual Box itself. :idea:

_nobody_