共享文件夹需要手动挂载,只需要一条指令:
$ sudo mkdir /mnt/hgfs
$ sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other
但是每次重启都要手动输入一次指令,非常麻烦,下面设置每次启动自动挂载。
简单来讲,rc.local是一个系统启动脚本,会在系统启动时自动运行。把挂载命令添加到rc.local文件中就可以在每次系统启动时自动挂载。但在后来的ubuntu版本中去除了这一功能,自启动服务方面基本由 systemd 全面接管了。但可以通过 /etc/systemd/system/rc-local.service 文件指定rc.local 的启动顺序和行为,从而能够继续使用rc.local作为系统启动脚本。
1、创建 rc.local 文件
$ sudo vim /etc/rc.local
$ cat /etc/rc.local
#!/bin/bash
sudo mount -t fuse.vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other
exit 0
2、添加可执行权限
$ sudo chmod +x /etc/rc.local
3、创建 /etc/systemd/system/rc-local.service 文件
$ sudo vim /etc/systemd/system/rc-local.service
$ cat /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
4、启用 /etc/rc.local 文件
$ sudo systemctl enable rc-local.service
5、重新启动Ubuntu
这时候再查看 /mnt/hgfs,接可以看到挂载的文件夹了。