Reconnect synced folders from vagrant after Virtualbox restart

2,507 views
Skip to first unread message

Dieter Menne

unread,
Mar 19, 2015, 3:58:28 AM3/19/15
to vagra...@googlegroups.com
This is a repost of

http://stackoverflow.com/questions/24693503/reconnect-synced-folders-from-puppet-after-virtualbox-restart

from July 2014. I could not get the solution by Sirlark to work.

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 puppet etc, and asks for a standalone VM to be started/stopped with the VirtualBox Manager on Windows. However, after I shutdown a vagrant-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. I have also tried to manually set "Automount" without success.

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

Dieter Menne

Dieter Menne

unread,
Mar 19, 2015, 6:32:24 AM3/19/15
to vagra...@googlegroups.com
Added information:

when started with vagrant, the mount is

vagrant on /vagrant type vboxsf (uid=1000, gid=1000,rw)


This works.

With automount, after a reboot:

vagrant on /media/sf_vagrant type vboxsf (gid=999, rw)


This is wrong. Where does the /media/sf_ come from?

Dieter

Alvaro Miranda Aguilera

unread,
Mar 19, 2015, 6:11:11 PM3/19/15
to vagra...@googlegroups.com
sf_ is how virtualbox create by defauult the shared folders

you should be using vagrant reload

that will take care of shared folders

Alvaro.
> --
> You received this message because you are subscribed to the Google Groups
> "Vagrant" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vagrant-up+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dieter Menne

unread,
Mar 20, 2015, 3:20:18 AM3/20/15
to vagra...@googlegroups.com
Please check my original post:

-- I need a solution that does not require the installation of vagrant.
-- I know that sf_ is how virtualbox creates the default shared folders
-- When I "save the state" when closing virtualbox, I can restart the system; however, I cannot guarantee that users will follow this procedure, and once the virtualbox has been shut down without closing, all is lost.

So to clarify the question:

-- How can I create a standalone virtual machine (i.e. without vagrant) that restores the vagrant-generated settings after a shutdown.

Dieter

Alvaro Miranda Aguilera

unread,
Mar 20, 2015, 5:50:40 AM3/20/15
to vagra...@googlegroups.com
Hello

Without entering into much detail, I think you can check and try
something inside the guest like this:

http://razius.com/articles/launching-services-after-vagrant-mount/

of course you need to adapt the script to umount / mount what/where you need

Alvaro.

Dieter Menne

unread,
Mar 20, 2015, 6:04:10 AM3/20/15
to vagra...@googlegroups.com
Thanks for the pointer, I had see that before. It is applicable to cases where the vagrant folder is required for some operation, which is not the case in my example.

For my example, it is ok to remount later because the the synced folders are not required for startup. One way out is to totally omit synced folders from Vagrantfile, and to do everthing explicitly in rc.local or similar.

I just could not believe that there is no mechanism that makes the shared folders persistent. After restart, everything is shared in the wrong folders, i.e. /media/....

Dieter

Alvaro Miranda Aguilera

unread,
Mar 20, 2015, 5:34:31 PM3/20/15
to vagra...@googlegroups.com
Hello,

the trick on udev run an script.. so you can do

umount /media/sf_vagrant
mount -t vboxsf -o "options_here" vagrant /vagrant

second, vagrant on start (up/reload) clear all the shared folders and
create the ones defined on vagrantfile

so, vagrant doesn't suffer this problem, and is done as I see it to
remove any shared folder that may have been left in the vm (not sure
if possible at all), and to process changes you may have done .

as I see your problem, you have a VM you want to distribute to 2
different end users.. Vagrant, and non-vagrant

if you look at packer,io you can use that with virtualbox-ovf and
start with a pre-existing vm, and use the output/post-processor to
create 2 vms.. one OVA for double click, gui, on.. experience and one
BOX for vagrant

perhaps that will help you to control more the distribution of the VMs

Alvaro.

Dieter Menne

unread,
Mar 21, 2015, 4:49:41 AM3/21/15
to vagra...@googlegroups.com
Thanks, Alvaro, for the pointer to packer. After first reading, this looks like the method to go.

Dieter

Alvaro Miranda Aguilera

unread,
Mar 21, 2015, 5:48:31 AM3/21/15
to vagra...@googlegroups.com
Hi Dieter,

There is a mailing list also for packer.

I also look there, so feel free to send any request you may have.

Alvaro.
Reply all
Reply to author
Forward
0 new messages