ubuntu19 VMware自动挂载本地文件

linux核心版本自2012.10开始放弃使用inited管理系统,改用systemd 从而导致自动挂载本地磁盘无法使用。本文记录我在使用过程中总结的一些命令,以备下次使用。

安装vm-tools不在赘述网上有很多教程,本文主要记录怎么实现自动挂载。

vm-tools安装之后如果在/mnt目录看到hgfs文件夹,这就说明安装成功。

使用命令:

sudo vmhgfs-fuse .host:/share /home/wwwroot/share -o subtype=vmhgfs-fuse,allow_other,nonempty

可以将本地目录挂载到你想要的挂载点上。但是不可能每次开机都执行一次挂载命令。

如果使用的是老版本(例如centos 6.5)可以通过修改/etc/fstab文件实现自动挂载。

如果是centos7.* 或 ubuntu 16.* (之后版本应该通用)可以使用开机自动执行挂载命令来实现自动挂载。

 

systemd有一个rc-local.service文件,可以通过此文件实现自动加载;

修改rc-local.service文件

sudo vim /etc/systemd/system/rc-local.service

末尾加上:

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

编辑rc.local文件:

sudo vi /etc/rc.local

写入以下内容:

#!/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.

sudo vmhgfs-fuse .host:/share /home/wwwroot/share -o subtype=vmhgfs-fuse,allow_other,nonempty
exit 0

添加权限:

sudo chmod +x /etc/rc.local

启用服务:

sudo systemctl enable rc-local

检测是否成功:

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

重启后就可以自动挂载了!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值