Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reconnect synced folders from Vagrant after VirtualBox restart

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.

like image 346
Dieter Menne Avatar asked Jul 11 '14 08:07

Dieter Menne


2 Answers

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

like image 161
Dieter Menne Avatar answered Oct 20 '22 14:10

Dieter Menne


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)

like image 4
sirlark Avatar answered Oct 20 '22 16:10

sirlark