Friday, December 23, 2011

Automounting Shared Folder on Ubuntu 11.10 Oneiric Ocelot as Guest in OS X Lion VirtualBox

My Ubuntu 11.10 Oneiric Ocelot on virtual box have shared folder with host OS X Lion named 'vbox'. I used to typing command after login to mount that folder to my home directory. I mount it to falder named 'vbox' too using this command

$sudo mount -t vboxsf vbox vbox.  

However, at old time, I used to auto mount other partition that refused to automount (usually ntfs or other linux distros partition) at login by editing /etc/fstab

(using vi, press k to scrolldown and press i or a to edit the last line)

aravir@aravir-VirtualBox:~$ sudo vi /etc/fstab

# /etc/fstab: static file system information.
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=3c8759e3-314b-4e42-a39e-efe9c18a130c /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=1b64eb34-42af-4ada-8bf1-0273d572cdb6 none            swap    sw              0       0
#virtualbox shared folder
vbox    /home/aravir/vbox       vboxsf  auto    0       0

press :wq! to save and quit vi session

Restart the machine. 

After the machine is back, well, there is no sign that my tweak above worked. Curious, I want to take a peek of what kind and what are already mounted by system.

aravir@aravir-VirtualBox:~$ mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
vbox on /home/aravir/vbox type vboxsf (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
vbox on /media/sf_vbox type vboxsf (rw,gid=1001)
gvfs-fuse-daemon on /home/aravir/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=aravir)

It's like the vbox is successfully mounted TWO times, however:
  • vbox did mount on /home/aravir/vbox but it's no file at all 
  • vbox mounted on /media/sf_vbox but only root have access to it 
So the last resort is playing with rc.local

aravir@aravir-VirtualBox:~$ sudo vi /etc/rc.local 

add this line before exit 0 

mount -t vboxsf vbox /home/aravir/vbox 

so the /etc/rc.local become like this

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.
mount -t vboxsf vbox  /home/aravir/vbox
exit 0

Restart the machine and voila, its success