Implementing virtualbox shared folders between a Mac OS X host and Fedora guest

Date: Wed Sep 20 2017 Fedora »»»» VirtualBox

Earlier I set up a Fedora VirtualBox guest system on my Mac and initially had some performance problems. Those are solved and now I want to set up folder sharing. This turns out to be nearly trivial.

I tried several things before using the "duh that's so obvious" method. In Fedora there are some facilities in the desktop to initiate connections to network storage, such as the "Connect to Server" choice in the desktop menus. Those tended to work properly e.g. using SSH to connect to an SSH account opened a Nautilis window showing the remote file system. Likewise on the Mac enabling Windows file sharing, and then using the "Windows Share" choice in the Fedora desktop, a Nautilis window opened. However I could not find where those were mounted in the Linux file system.

IIRC Gnome has some kind of virtual file system and apparently the Gnome VFS does not map to actual Linux level filesystem mounts. The problem with this is using remote files from regular tools, like 'make'. If the remote files do not show up in the regular Linux file system then regular tools cannot access them. Maybe there's a trick to make them appear in the Linux file system that I don't know.

However in the VirtualBox Guest Additions is a folder sharing feature. In the past I hadn't got it to work for a Linux guest, only a Windows guest. But giving it a try now results in a quickly working thing but with a slight small gotcha.

The Virtualbox shared folders feature solves one issue with other file sharing protocols. It's most likely your preferred shared folder will be on the hard disk of the host system. If you use SMB or CIFS to mount the host system it's required to give an IP address for the host system and if the host system has a DHCP assigned IP address that IP address can change from day to day or even minute to minute (e.g. using a laptop and walk from Starbucks back to the office and have a different wifi connection?). As soon as the IP address changes the shared folder connection will break and you have to reconfigure it. With the VirtualBox shared folders the connection doesn't require the host IP address and hence does not require reconfiguring the shared folder connection.

To set it up start in the VirtualBox user interface. There is a Shared Folders choice in the menus, select that. It lets you select host machine folders to make available to the guest virtual system. The dialog is straightforward. The important factoid to carry from the dialog is the name of the shared folder.

The next step is, on the Linux guest, to mount the share using the vboxsf filesystem. This is documented in the VirtualBox user guide.

mount -t vboxsf [-o OPTIONS] sharename mountpoint
</span><p></p><p>Replace sharename with the share name specified with VBoxManage, and mountpoint with the path where you want the share to be mounted (e.g. /mnt/share). The usual mount rules apply, that is, create this directory first if it does not exist yet.<br></p></blockquote><p></p><p>For example:</p><p></p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;">[root@fedora10 ~]# mount -t vboxsf LaCie /Volumes/LaCie/</pre></div><p></p><p>This works.  A little side note is I'm using the same pathname in the guest system as the file system has in the host system.  This way if I write a shell script that's used on both systems it has the same pathnames. </p><p>However that has a little problem that wasn't obvious from the user guide.  The files in /Volumes/LaCie end up being owned by root regardless of their ownership on the host machine.  A problem is that the host (Mac OS X) has its own idea of file ownership that differs from the file ownership on the guest system.  Since I want to work on the files as my unprivileged user ID on the guest system there has to be a way to map file ownership.  The VirtualBox user manual has this cryptic suggestion.</p><p></p><blockquote><div class="quote_start"><div></div></div><div class="quote_end"><div></div></div><br>The generic mount options (documented in the mount manual page) apply also. Especially useful are the options uid, gid and mode, as they allow access by normal users (in read/write mode, depending on the settings) even if root has mounted the filesystem.<br></blockquote><p></p><p>What this means is the Linux mount command has mount options you can specify with the "-o" option, and that those are valid on vboxsf mounts.  </p><p></p><blockquote><div class="quote_start"><div></div></div><div class="quote_end"><div></div></div><br>uid=value and gid=value: Set  the owner and group of the files in the file system (default: uid=gid=0).<br></blockquote><p></p><p>Hence the following works perfectly well, resulting on the files appearing from the guest machine to be owned by my unprivileged guest user ID.</p><p></p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;">[root@fedora10 ~]# mount -t vboxsf -o uid=500,gid=500 LaCie /Volumes/LaCie/<br>[root@fedora10 ~]# df -k<br>Filesystem           1K-blocks      Used Available Use% Mounted on<br>/dev/mapper/VolGroup00-LogVol00<br>                       6837776   4015012   2753380  60% /<br>/dev/sda1               194442     28178    156225  16% /boot<br>tmpfs                   190448        76    190372   1% /dev/shm<br>LaCie                732574184 218840916 513733268  30% /Volumes/LaCie/<br>[root@fedora10 ~]# mount<br>/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)<br>/proc on /proc type proc (rw)<br>sysfs on /sys type sysfs (rw)<br>devpts on /dev/pts type devpts (rw,gid=5,mode=620)<br>/dev/sda1 on /boot type ext3 (rw)<br>tmpfs on /dev/shm type tmpfs (rw)<br>none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)<br>sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)<br>gvfs-fuse-daemon on /home/david/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=david)<br>LaCie on /Volumes/LaCie/ type vboxsf (uid=500,gid=500,rw)<br>[root@fedora10 ~]# </pre></div><p></p><p>There is a remaining file ownership problem in that files created from the guest appear to have incorrect ownership on the host.</p><p></p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;">[root@fedora10 ~]# cd /Volumes/LaCie/<br>[root@fedora10 LaCie]# touch guest-root<br>[root@fedora10 LaCie]# ls -l guest-root <br>-rw------- 1 david david 0 2009-02-09 09:36 guest-root<br>[root@fedora10 LaCie]# </pre></div><p></p><p></p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;">bash-3.2# ls -l /Volumes/LaCie/guest-root <br>-rw-------  1 _unknown  _unknown  0 Feb  9 09:36 /Volumes/LaCie/guest-root</pre></div><p></p><p></p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;">[david@fedora10 ~]$ touch /Volumes/LaCie/guest-david<br>[david@fedora10 ~]$ ls -l /Volumes/LaCie/guest-david<br>-rw------- 1 david david 0 2009-02-09 09:36 /Volumes/LaCie/guest-david</pre></div><p></p><p></p><div class="geshifilter"><pre class="text geshifilter-text" style="font-family:monospace;">bash-3.2# ls -l /Volumes/LaCie/guest-david <br>-rw-------  1 _unknown  _unknown  0 Feb  9 09:36 /Volumes/LaCie/guest-david</pre></div><p></p><p>This may be relatively easy to work around.</p><p></p><!-- google_ad_section_end --><div class="sexybookmarks-default-1219"></div></body></html>