List VirtualBox VM’s shared folders
In my current job we work heavilly with kubernetes clusters, working on a minikube master. As part of out internal toolkit for managing these, I needed to get a full list of the machine’s shared folders. Unfortunately – it seems that VirtualBox does not support this in their CLI tools, so I had to improvise. At first – I thought about listing the current mounts in the machine, but found that if a shared folder has invalid path – it will not be listed.
Then, I came up with this extremely hacky, but working method. With VBoxManage – you can get info for the VM:
$ VBoxManage showvminfo {vm}
........
USB Device Filters:
<none>
Available remote USB devices:
<none>
Currently Attached USB Devices:
<none>
Bandwidth groups: <none>
Shared folders:
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
Name: '--redacted--', Host path: '--redacted--' (machine mapping), writable, auto-mount
VRDE Connection: not active
Clients so far: 0
..........
So this was close enough. All I needed was some filtering, in this case – awk
, a sprinkle of grep
, a pinch of cut
, and voila:
$ VBoxManage showvminfo {vm} |awk '/Shared/,/VRDE/' |grep 'Name' |cut -d"'" -f2
--redacted--
--redacted--
--redacted--
--redacted--
--redacted--
--redacted--
--redacted--
--redacted--
Of course – in the future the they might change the order of information – then you’ll need to replace ‘VRDE’ with whatever comes after the shared folders.
hax, hax, hax