- 第一步:安装好vm-tools,首先可以通过指令安装,
- # 安装必要的依赖
sudo apt update
sudo apt install open-vm-tools-desktop -y
sudo apt install open-vm-tools -y
# 重启虚拟机
sudo reboot - 可通过虚拟机分辨率是否自动调节来测试是否安装成功
2. 第二步:在vm虚拟机上设置文件共享
在vm上添加主机路径文件,详情参考windows与Ubuntu实现文件互传存在两种方式_windows文件拖入ubuntu-CSDN博客
3. 第三步:通过自动化指令实现开机启动文件挂载
这步很多写的模模糊糊的,本人亲测有效的步骤如下:
步骤一:确保已安装 VMware Tools
确保你已经在虚拟机中安装了 VMware Tools,这是必需的,因为 vmhgfs-fuse
是 VMware Tools 提供的一个工具。
步骤二:创建挂载点
创建一个挂载点目录,例如 /mnt/hgfs
:
sudo mkdir -p /mnt/hgfs
步骤三:编辑 /etc/rc.local
文件
-
打开
/etc/rc.local
文件。如果文件不存在,请创建它:sudo nano /etc/rc.local
-
在文件中添加挂载命令。确保文件以
#!/bin/bash
开头,并在脚本的最后一行添加exit 0
。以下是示例内容:#!/bin/bash # 挂载 VMware 共享文件夹
/usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other exit 0 -
保存文件并退出编辑器。
-
复制代码
sudo chmod +x /etc/rc.local
步骤四:创建 rc-local.service
服务文件
由于较新的Ubuntu版本使用 systemd
,你需要创建一个 systemd
服务来运行 rc.local
。
-
创建
rc-local.service
文件:sudo nano /etc/systemd/system/rc-local.service
-
添加以下内容:
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
After=network.target vmtoolsd.service
Requires=vmtoolsd.service[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99[Install]
WantedBy=multi-user.target
-
保存文件并退出编辑器。
步骤五:启用并启动 rc-local
服务
-
重新加载
systemd
配置:sudo systemctl daemon-reload
-
启用
rc-local
服务:sudo systemctl enable rc-local
-
启动
rc-local
服务:sudo systemctl start rc-local
-
检查服务状态以确保其正常运行:
sudo systemctl status rc-local
步骤六:验证挂载
重启虚拟机,并检查共享文件夹是否正确挂载:
sudo reboot
重启后,检查挂载点 /mnt/hgfs
:
ls /mnt/hgfs