2

I have a situation where I would like to add shared folders to a running Vagrant box (Ubuntu guest) provided by VirtualBox.

According to the docs, these "Synced Folders" should be defined in the configuration file like so:

config.vm.synced_folder "/mnt/plugdrive15", "/synced/plugdrive15"

But what if I need to share directories that are new on my host? I have this often and I cannot predict their names, so I cannot pre-write them beforehand in the configuration file. I want to automate this.

Using VBoxManage sharedfolder add doesn't work, because as soon as you do vagrant up, only the shares specified in the configuration file (and the default vagrant one) are left.

If all else fails (no better solutions), can Vagrantfile parse a configuration file (in which I specify shares right before vagrant up?

Redsandro
  • 11,060
  • 13
  • 76
  • 106

1 Answers1

1

You can using virtual box interface, you have a shared folder option in the VM setting and you can add a new folder while the VM is running

[edit] there is ofc a command line tool associated : http://www.virtualbox.org/manual/ch04.html#sharedfolders

[edit 2] Setting the vm name is a provider specific operation, so VBoxManage tool will consider it as well.

config.vm.provider :virtualbox do |vb|
  vb.name = "barhost"
end

If you don't specify a name vagrant will generated one, see How to change Vagrant 'default' machine name? for precisions.

Community
  • 1
  • 1
Gab
  • 7,869
  • 4
  • 37
  • 68
  • I know I can add one in the interface for the VM provider itself, but I'm looking for a Vagrant specific method, or otherwise platform independent command line trick. – Redsandro Apr 04 '14 at 18:00
  • Thanks, your edit is relevant to my question. I will try it out when I am back at the office. But how do I know the VM name when a client or script just does `vagrant up`? Is it a random name? Is it even managable by `VBoxManage` when it's set up by Vagrant? – Redsandro Apr 05 '14 at 13:07
  • This is not working. `Vagrant up` will remove any manually specified shares. – Redsandro Apr 07 '14 at 19:41
  • @edit2: I know, it's not the problem. Open the GUI. Add shared folders using `VBoxManage`. You see the shared folder counter in the GUI increase. Do `vagrant up`. You'll see the shared folder counter in the `GUI` reset to the number of shares specified in `Vagrantfile`. They won't stick. – Redsandro Apr 07 '14 at 19:57