How do I automatically mount my shared folder?

Discussions about using Linux guests in VirtualBox.
JohnSnyder
Posts: 13
Joined: 18. Feb 2008, 03:50

How do I automatically mount my shared folder?

Post by JohnSnyder »

I type the following command to mount my shared folder: "sudo mount -t vboxsf D_DRIVE /home/john/HostData".

I would like this command to run automatically at startup. What do I need to do to make this command an automatic at startup?
Vadi
Posts: 39
Joined: 28. Aug 2007, 15:11
Location: Toronto, Canada

Post by Vadi »

I think you'd add a proper line to the fstab file. I think it's in /etc.

(don't know much about it, just heard it's responsible for automounting things)
Erik_FL
Posts: 55
Joined: 8. Feb 2008, 06:46

Post by Erik_FL »

Edit the file "/etc/fstab" file and add a line like this.

Code: Select all

D_DRIVE          /home/john/HostData  vboxsf    defaults         0   0
The file has the following on each line.

filesystem-device mount-point filesystem-type options dump fschk

The "dump" flag indicates if the filesystem should be backed up (0=no 1=yes). You have to run the appropriate utlity that checks the "dump" flags if you want filesystems to be backed up.

The "fsck" number indicates if the filesystem should be checked on boot (0=no) and the order in which the filesystems should be checked (1=first,2=second, etc.).

There are a lot of other possible options that you can use in place of "defaults" including one called "noauto" that prevents automatically mounting the filesystem at startup. Using "noauto" allows you to set the default mount options and use a mount command that just refers either to the mount point or the device.

mount D_DRIVE

or

mount /home/john/HostData

If you use "defaults" then the filesystem will be automatically mounted on boot.
aj59
Posts: 11
Joined: 21. Feb 2008, 18:03

Post by aj59 »

I don't understand the first command that was shown to mount the shared folder?

I want to designate a shared folder on c:/linux_share. I already added in the gui, I just don't know how to mount it.

Thanks.

*******************

Edit: Aha. Found the other thread and got it to work.
Telcontar2k8
Posts: 6
Joined: 24. Feb 2008, 00:03

This I think is how you mount

Post by Telcontar2k8 »

Edit March, 26th 2008: Ok, I've just installed a fresh Ubuntu 8.04 on my Virtualbox 1.5.6 with a Windows Vista Home Premium Host. I followed my own tutorial really step by step, and my shared folder are mounting on start-up.
Be aware that this tutorial is only working for Ubuntu, since other Linux distribution have different ways of loading modules and even dealing with fstab.
Maybe other users could write the files, which needed to be modified within other distributions, below.
I will now add some remarks with red in the text below to point out possible errors.
________________________________________________
Attention: As of March 30th 2008 this HowTo has to be seen as "Maybe working" since some users reported that after following this tutorial the shared folders still didn't work.
If you can figure out where the error is please give me a hint, so I can change this.
________________________________________________
Hey, I recently had a similar problem. I knew the right code lines, but they didn't seem to work. A friend of mine helped me then in finetuning everything. But before I start my how to, some general facts: I used this commands on a Windows Vista Home Premium Host and a Ubuntu 7.10 Guest. Maybe there are some little differences to other guests.
So here is my little how to include a shared folder in fstab:

This tutorial is about, how to mount windows-Folder into a Linux Folder of your current home directory, NOT about mounting a windows partition into a linux folder or mounting a windows partition into a new linux partition (as a new devise) within your guest.

1st step: Include the virtualbox Guest Additions as described in the Virtualbox Manual
2nd step: Shut down the virtual machine
3rd step: Create a Permanent Shared Folder
(In a deactivated machine go to Edit -> Shared Folder) --> make sure they are permanent (tick the checkbox), otherwise the guest won't find them after a reboot.
4th step: Start the virtual machine
5th step: Open a terminal
6th step: Check wether Guest Additions were installed successfully. After you have typed in the command "lsmod | grep vb" you should see the modules vboxvfs and vboxadd approximately like that:
vboxvfs 42048 0
vboxadd 25128 11 vboxvfs

If you don't see those modules you have to check your installation of the guest additions and restart with step 4. --> with Ubuntu 8.04 only Virtualbox 1.5.6 works so far
7th step: Create a folder within your virtual machine to which you want to mount your exchange folder. --> pay attention to the rights of this folder. You need to have read,write and execute rights. See the chmod manpage for further details about granting rights. If given everybody every right just to make sure it works
8th step: Go to the folder /etc
9th step: Use your favorite editor to open the file "modules" of this folder. Be sure you have root rights, otherwise you could maybe not be able to save it. You could for example use the command "sudo gedit modules".
10th step: After the last line you write now vboxvfs and in the next line vboxadd. Then save save and close this file.
11th step: Now open the file fstab which is contained in the same folder. Again open it with root-rights, so you are able to save your changes.
12th step: After the last line you write now:
NameOfTheSharedFolderInVirtualbox NameOfYourMountFolderInLinux vboxsf defaults 0 0
in my file it looks approximately like this:
exchange /home/someuser/someos vboxsf defaults 0 0

Instead of defaults you can use every kind of rights for your mount point as described in the man pages of mount (man mount)-->someuser is my own username, someos is the folder created in step 7, where the windows folder will be into. If this folder is empty in your host it will be empty in your guest, so I recommend to put an empty testfile in the host folder just to see whether the mount was successful

When now starting the virtual machine, the folder should me mounted automatically (it does in mine)


Btw: If you want to mount a shared folder manually, I usually used the command
mount -t vboxsf exchange /home/someuser/someos
till I got this working

Hope I could help
Last edited by Telcontar2k8 on 26. Apr 2008, 12:35, edited 4 times in total.
aj59
Posts: 11
Joined: 21. Feb 2008, 18:03

Post by aj59 »

Thanks for going to the trouble to make such detailed instructions.

I see you are running Unutu 7.10 as a Guest. I am currently trying for the third time to install it. This time I updated VB to 1.5.6 and also correctly set the OS to Linux 2.6 this time.
Telcontar2k8
Posts: 6
Joined: 24. Feb 2008, 00:03

Post by Telcontar2k8 »

I'm actually only using Vbox 1.5.4 . Maybe if you still have problems, you could describe them a bit more. For example, when I tried to install Ubuntu the first time on a different machine (by far not as strong as the one I'm currently using), I set the settings for RAM and Graphic Memory too low, so the whole virtual system froze when coming to the boot-screen. I solved the problem by giving the virtual machine at least 128MB Ram and I think 32 MB of Graphic Memory(could also have been more, it's been a while since I set up that system). Afterwards I still got some little artifacts on the boot screen but the whole system booted corectly in the end.
Maybe you have a similar problem.
vale25
Posts: 3
Joined: 17. Apr 2008, 14:00

SHared folder with guest openSUSE 10.3 ?

Post by vale25 »

Guest VISTA
Host openSUSE 10.3 with Guest Additions successfully run

I cannot paste from the host window, nor save yet to my host, so I rewrite the output here:

lsmod|grep vb gives:

vboxvfs 41896 0
vboxadd 25512 7 vboxvfs

The problem is that openSUSE does NOT have /etc/modules, as nicely explained in the thread above by Telcontar2k8. Anyone knows where should they be added on the linux filesystem?

VirtualBox/Shared Folder contains entry btmp linked to B:\tmp

The command line:

mount -t vboxvfs btmp /home/vale25/btmp

fails with:

mount: unknown filesystem type 'vboxvfs'

I added the suggested line in /etc/fstab, but this is to be investigated after I can mount manually

Note: I succesfully did this with guest Ubuntu 7.10, so I expect that VirtualBox configurations are Ok, and what is missing here is openSUSE special configuration. The btmp should be seen by linux in order to mount it.

Thanks in advance
vale25
Posts: 3
Joined: 17. Apr 2008, 14:00

Post by vale25 »

Guest Vista
Host openSUSE 10.3
VirtualBox 1.5.6
Shared Folder on host with name btmp and path B:/tmp
Linux folder /home/vale25/btmp

I suceeded to mount as root on openSUSE with:

/sbin/mount.vboxsf -rw btmp /home/vale25/btmp


Suggested command above does not work:

vasuse:/home/vale25 # mount -t vboxvfs btmp /home/vale25/btmp
mount: unknown filesystem type 'vboxvfs'


Could anyone tell please where to insert aforementioned command for being executed on startup as root and regardless of which user is logging?
Vallverdu
Posts: 19
Joined: 12. Dec 2007, 14:40
Location: Paris (Orsay)

Post by Vallverdu »

Hi

It doesn't work for me too. I have a windowsXP host with a fedora guest (scientific linux 5.0).

If I do (with root id) :

Code: Select all

mount -t vboxsf test /home/Ger/common
It is fine and work correctly.

But if i put that in my /etc/fstab file :

Code: Select all

 test /home/Ger/common/ vboxsf defaults 0 0
It does not mount the directory common. With fedora i don't have a file "modules" in /etc. I created it and I had the two lines you suggest but this doesn't do anything.

In my lab I have an automount for device on the network. Their automount are in the /etc/auto.users file with this kind of line :

Code: Select all

u -rw,rsize=8192,wsize=8192,soft lcp.lcp.u-psud.fr:/u
Thank you for your help
JackH
Posts: 1
Joined: 24. Apr 2008, 05:16

Post by JackH »

I ran into the same problem with Slackware 12 -- a share will mount via the command line, but not in fstab.

I overcame this by placing the mount command in the rc.local file. This is where the VirtualBox installer placed its commands also, which I suppose is why mounting via fstab doesn't work -- the rc.local script has not been executed when fstab does its thing.
Aylwin
Posts: 10
Joined: 27. Apr 2008, 16:55

Re: This I think is how you mount

Post by Aylwin »

Telcontar2k8 wrote:8th step: Go to the folder /etc
9th step: Use your favorite editor to open the file "modules" of this folder. Be sure you have root rights, otherwise you could maybe not be able to save it. You could for example use the command "sudo gedit modules".
10th step: After the last line you write now vboxvfs and in the next line vboxadd. Then save save and close this file.
11th step: Now open the file fstab which is contained in the same folder. Again open it with root-rights, so you are able to save your changes.
12th step: After the last line you write now:
NameOfTheSharedFolderInVirtualbox NameOfYourMountFolderInLinux vboxsf defaults 0 0
in my file it looks approximately like this:
exchange /home/someuser/someos vboxsf defaults 0 0
Thanks for the tuorial! This is all I needed to know and it worked perfectly! :)

Host: Vista Ultimate
Guest: Ubuntu 8.04
VirtualBox 1.5.6
derekJAB
Posts: 2
Joined: 13. May 2008, 14:23

Post by derekJAB »

JackH wrote:I ran into the same problem with Slackware 12 -- a share will mount via the command line, but not in fstab.

I overcame this by placing the mount command in the rc.local file. This is where the VirtualBox installer placed its commands also, which I suppose is why mounting via fstab doesn't work -- the rc.local script has not been executed when fstab does its thing.
Sorry to bump this thread, but just wanted pass on my thanks.

I was struggling with the fstab file until I saw your solution. Now my shared folder auto mounts perfectly (Ubuntu guesting on Mac OS X)
Clod!
Posts: 2
Joined: 26. May 2008, 16:21

Post by Clod! »

Thanks mate,
it works: the shared directory is now mounted automatically on boot... but unfortunately is read only (only root can write). :(

Is there any solution for making it writable for "normal" user?

Thanks.
Clod!

My system:
Host: Win XP Pro
Guest: Ubuntu 8.04
VirtualBox: 1.6.0
lot
Posts: 10
Joined: 7. May 2008, 14:49

Post by lot »

Clod! wrote:Thanks mate,
it works: the shared directory is now mounted automatically on boot... but unfortunately is read only (only root can write). :(

Is there any solution for making it writable for "normal" user?

Thanks.
Clod!

My system:
Host: Win XP Pro
Guest: Ubuntu 8.04
VirtualBox: 1.6.0
The usual options uid and gid work. change "defaults" in the fstab line to
uid=<uid of user>,gid=<gid of user>

<uid of user> and <gid of user> are the numerical IDs you find in /etc/passwd. Alphabetical IDs (i.e., username and group name) may work as well.

Regards, T.
Post Reply