これ↓の vboxsf 版(VirtualBox の共有フォルダ)なのですが、妙なところでハマったのでメモ。
結論
Vagrant で /vagrant
にマウントしている場合、VirtualBox には vagrant
という名前で共有フォルダが作成されています。
autofs で設定するときはこの名前の先頭に /
を付けて指定します。例えば :/vagrant
です(:vagrant
ではなく)。
/etc/auto.oreore
/opt/sandbox -fstype=vboxsf,uid=vagrant,gid=vagrant,rw :/vagrant \
/vendor -bind :/var/opt/sandbox/vendor \
/node_modules -bind :/var/opt/sandbox/node_modules
これで、
-
/opt/sandbox
- ホストを vboxsf でマウントしたもの
/opt/sandbox/vendor
-
/opt/sandbox/node_modules
- 仮想環境のローカル
となります。
もし Vagrant で /opt/aaa/bbb/ccc
などというパスにマウントするように設定したなら、VirtualBox には opt_aaa_bbb_ccc
という名前で共有フォルダが作成されています。
先頭に /
を付けて :/opt_aaa_bbb_ccc
をソースに指定します。
/opt/sandbox -fstype=vboxsf,uid=vagrant,gid=vagrant,rw :/opt_aaa_bbb_ccc \
/vendor -bind :/var/opt/sandbox/vendor \
/node_modules -bind :/var/opt/sandbox/node_modules
試行錯誤の跡
VirtualBox の共有フォルダの名前が vagrant
であれば、次のようにマウントすることができる。
sudo mount.vboxsf vagrant /mnt
一方 /vagrant
という名前を指定すると失敗する。VirtualBox の共有フォルダの名前は vagrant
なので当然。
sudo mount.vboxsf /vagrant /mnt
# mount.vboxsf: mounting failed with the error: Protocol error
autofs をインストールする。
sudo yum -y install autofs
auto.master
を設定する。
sudo tee <<'EOS' /etc/auto.master.d/oreore.autofs
/- /etc/auto.oreore
EOS
autofs で次のように :vagrant
を指定すると成功する。
sudo tee <<'EOS' /etc/auto.oreore
/opt/sandbox -fstype=vboxsf :vagrant
EOS
がしかし、「autofs で cifs マウントした中のディレクトリを mount --bind する」と同じように Multiple Mounts すると失敗する。
sudo tee <<'EOS' /etc/auto.oreore
/opt/sandbox -fstype=vboxsf :vagrant \
/vendor -bind :/var/opt/sandbox/vendor
EOS
ll -d /opt/sandbox
# drwxr-xr-x. 2 root root 0 Mar 29 11:21 /opt/sandbox
ll /opt/sandbox
# ls: cannot open directory /opt/sandbox: No such file or directory
マウントのソースを :/vagrant
にするとなぜか大丈夫。
sudo tee <<'EOS' /etc/auto.oreore
/opt/sandbox -fstype=vboxsf :/vagrant \
/vendor -bind :/var/opt/sandbox/vendor
EOS