5

I have created a puppet/vagrant/VirtualBox generated installation of Ubuntu running on a Windows host; see https://bitbucket.org/dmenne/rstudio-shiny-server-on-ubuntu for details. This allows users to run RStudio and Shiny server on Windows. In Vagrantfile, I have

config.vm.synced_folder "shiny-server", "/srv/shiny-server", create:true

to create a shared folder. When I start the VM with vagrant up or vagrant reload, everything works ok.

One customer does not want to install vagrant etc, and asks for a standalone VM to be started/stopped with the VirtualBox Manager on Windows. However, after I shutdown a enter image description herevagrant-booted VM Box, my synced folders do not connect/mount again on VM restart, even if they turn up correctly in the shared folders dialog of the VirtualBox Manager.

How can I shrink-wrap a Vagrant-generated VM so it can be started/stopped without Vagrant?

EDIT March 2015:

I still could not resolve this. When I force automount, on restore media/sf_<folder> is synced, not the required folder. How can I force VirtualBox to use sync-template from Vagrantfile after a restart?

And how do I force automount in vagrant without doing it manually.

Dieter Menne
  • 10,076
  • 44
  • 67

2 Answers2

7

After some further debugging and the lack of response to a similar query on the google/vagrant forum:

  • When you use synced folders in puppet, you must restart VirtualBox with vagrant up or vagrant reload
  • If you use the VirtualBox GUI to stop/restart, automount restores the synced folders incorrectly, i.e. to /media/sf_; this cannot be corrected without using a vagrant reload,
  • The only alternative without vagrant is to save the state in VirtualBox (CTRL-V). After a restart, the synced folders are restored correctly. However, it is probably impossible to force end-users to always manually save the state.

To use persistent synced folders, you must use upstart or similar methods; it cannot be done with Vagrantfile only.

See also Alvaro's response: https://groups.google.com/forum/#!topic/vagrant-up/oBU0kqPLzYk

Dieter Menne
  • 10,076
  • 44
  • 67
4

There are two parts to getting this to work. First, we need to get the synced folders automatically mounting from the host, which is the case of a Linux guest is a bit of a misnomer, because it's more "being automatically made available for mounting", or "automatically shared". For each shared folder (gemainsame ordner) you must turn on auto mount (automatische einbinden)

To do this, click on the edit shared folder icon for each share

The edit shared folder icon

And check auto mount (automatische einbinden)

Check the auto mount option

At the end you should see "Ja" under "automatische Einbinden" for all the shares to should auto-sync

enter image description here

If the guest system is Ubuntu (or any Linux system), then having done this, all the synced folders should now be visible within to the guest, but the guest won't automatically mount them. You will need to put an entry into your /etc/fstab for each folder you want automatically mounted in the guest.

Since you are using VirtualBox, Vagrant will presumably choose to implement the synced folders using VirutalBox's shared folder provisioning method. To the guest system in Linux, depending on your version of Guest Additions, this looks like either an smb/cifs share with the name (by default) of //vboxsrv/, or a file system of type "vboxsf".

The vboxsf is from more recent version of guest additions (4.1.18 onwards at least), and automount option 'just works'. On booting a Linux guest VM with an automount set share called 'bob', the system should mount Bob automatically (without an fstab entry) at /media/sf_Bob. The full output of the relevant line from mount is

none on media/sf_Bob type vboxsf (rw,nodev,relatime)

If this isn't working, check that you can see a samba network share from within your guest system, using smbclient or smbtree. It should look like //vboxsrv/Bob. In your fstab then, you would add a line like this

#share name         #mount point in guest   #fstype   #options   #dump/pass
//vboxsrv/Bob       /mnt/Bob                cifs      auto,rw    0 0

You may wish to read the manual page for mount.cifs to tune the options for each mount, especially with regards to file ownership and permissions (relevant options to investigate are forceuid, uid, forcegid, gid, file_mode, and dir_mode)

sirlark
  • 2,187
  • 2
  • 18
  • 28
  • 1
    Thanks, @sirlark; I forgot to mention that I had tried this before and it does not reconnect. As an aside: I do not know how to set automount from puppet/vagrant, but that would be a separate question. Marked as +1, but not the answer. – Dieter Menne Jul 19 '14 at 09:40
  • Right, I've edited my answer accordingly. There's guest side configuration also required here. – sirlark Jul 20 '14 at 11:23
  • 1
    Also, in future, this kind of question (system administration) would probably get a quicker response on serverfault or superuser; I've flagged it for migration. – sirlark Jul 20 '14 at 11:25
  • Alternatively, have you read through these other questions very similar to yours, they might be better solutions... [vagrant-error-failed-to-mount-folders-in-linux-guest](http://stackoverflow/questions/22717428/vagrant-error-failed-to-mount-folders-in-linux-guest?rq=1) and – sirlark Jul 20 '14 at 11:31
  • Thanks for the automount idea; it's good to have, but did not change the problem at first sight; I will check more carefully tomorrow. The link you mentioned relates to VMBox 4.3.10, it had helped me before; on the bitbucket page I have mentioned this as a version to avoid. – Dieter Menne Jul 20 '14 at 14:15
  • I've edited my answer a bit. I noticed that with newer versions of Guest Additions the shared folders work differently. I was doing this from memory before, so now I went and checked quickly. What is the output of `mount` on right after boot, in the guest? – sirlark Jul 21 '14 at 10:08