By: +David Herron; Date: Sun Feb 08 2009 16:00:00 GMT-0800 (Pacific Standard Time)
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
Replace sharename with the share name speciﬁed 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 ﬁrst if it does not exist yet.
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.
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.
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 ﬁlesystem.
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.
uid=value and gid=value: Set the owner and group of the files in the file system (default: uid=gid=0).
Hence the following works perfectly well, resulting on the files appearing from the guest machine to be owned by my unprivileged guest user ID.
[root@fedora10 ~]# mount -t vboxsf -o uid=500,gid=500 LaCie /Volumes/LaCie/ [root@fedora10 ~]# df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup00-LogVol00 6837776 4015012 2753380 60% / /dev/sda1 194442 28178 156225 16% /boot tmpfs 190448 76 190372 1% /dev/shm LaCie 732574184 218840916 513733268 30% /Volumes/LaCie/ [root@fedora10 ~]# mount /dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw) /proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/sda1 on /boot type ext3 (rw) tmpfs on /dev/shm type tmpfs (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) gvfs-fuse-daemon on /home/david/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=david) LaCie on /Volumes/LaCie/ type vboxsf (uid=500,gid=500,rw) [root@fedora10 ~]#
There is a remaining file ownership problem in that files created from the guest appear to have incorrect ownership on the host.
[root@fedora10 ~]# cd /Volumes/LaCie/ [root@fedora10 LaCie]# touch guest-root [root@fedora10 LaCie]# ls -l guest-root -rw------- 1 david david 0 2009-02-09 09:36 guest-root [root@fedora10 LaCie]#
bash-3.2# ls -l /Volumes/LaCie/guest-root -rw------- 1 _unknown _unknown 0 Feb 9 09:36 /Volumes/LaCie/guest-root
[david@fedora10 ~]$ touch /Volumes/LaCie/guest-david [david@fedora10 ~]$ ls -l /Volumes/LaCie/guest-david -rw------- 1 david david 0 2009-02-09 09:36 /Volumes/LaCie/guest-david
bash-3.2# ls -l /Volumes/LaCie/guest-david -rw------- 1 _unknown _unknown 0 Feb 9 09:36 /Volumes/LaCie/guest-david
This may be relatively easy to work around.