VirtualBoxの共有フォルダをautofsで使用する


VirtualBoxにはホストのフォルダをゲストからマウントして共有する「共有フォルダ」機能がある。スクリーンショットの様にフォルダ名「pub」で設定したホストのフォルダ「/home/public」をゲストの「/mnt」にマウントするには通常以下の様にする。


$ []sudo mount -t vboxsf -o uid=1000,gid=100 pub /mnt[]
これを毎回打つのは大変なのでゲストにautofsをインストールし「/misc/vbox」にアクセスしたら自動でそこに共有フォルダをマウントするように設定する。以下はUbuntu Intrepidでの作業ログ。

$ []sudo apt-get install autofs[]
[]...省略...[]
[]以下の特別パッケージがインストールされます:[]
[] libevent1 libgssglue1 libnfsidmap2 librpcsecgss3 nfs-common portmap[]
[]以下のパッケージが新たにインストールされます:[]
[] autofs libevent1 libgssglue1 libnfsidmap2 librpcsecgss3 nfs-common portmap[]
[]...省略...[]
$ []sudo vim /etc/auto.master /etc/auto.misc[]
/etc/auto.master:

#
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
/misc   /etc/auto.misc --timeout=60
#/smb   /etc/auto.smb
#/misc  /etc/auto.misc
#/net   /etc/auto.net

/etc/auto.misc:

#
# $Id: auto.misc,v 1.2 2003/09/29 08:22:35 raven Exp $
#
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
vbox            -fstype=vboxsf,uid=1000,gid=100 :pub
#「vbox -fstype=.... :vbox」のようにkey(第1フィールド)と
# location(第3フィールド)を同じ名前にするとマウントに失敗する。


$ []sudo /etc/init.d/autofs restart[]
[]Stopping automounter: done.[]
[]Starting automounter: done.[]
$ []ls /misc/vbox[]
[]ホストの「/home/public」の中身が表示される[]