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
重启后就可以自动挂载了!