完美解决VMware共享文件夹在Ubuntu中看不到的问题

共享文件夹需要手动挂载,只需要一条指令:

$ 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,接可以看到挂载的文件夹了。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值