vmware安装linux共享文件夹重启失效的原因是open-vm-tools[-desktop]只有设置变化时自动挂载共享文件夹的功能,没有系统启动时自动挂载共享文件夹的功能

 open-vm-tools未来可能修复这个问题:

 在官方修复之前,有以下解决方法:

 【官方解决方案1】在/etc/fstab加上自动挂载项(需fuse3 version 3.2.2+)(推荐)

首先确认安装了fuse3 version 3.2.2+,确认系统安装了fuse3 version 3.2.2+可以使用下面的方法:

fusermount -V

此处应该显示:fusermount3 version: 3.2.2(或以上版本)

如果显示fusermount version: 2.9.9或者更老版本,可以使用包管理器尝试安装fuse3:

sudo apt install fuse3 # Debian/Ubuntu/...
sudo pacman -S fuse3 # Arch/...
sudo yum install fuse3 # RHEL(CentOS/Rocky/...)/Fedora/...
# ...

安装完成后再次使用fusermount -V确认版本号

如果显示版本号小于3.2.2,或者包管理器中根本没有fuse3,请使用其它解决方案,因为传统的fuse并不支持nofail,有导致系统锁死的危险

使用sudo nano /etc/fstab编辑fstab, 在文件中加入下面的内容,Ctrl-X y保存关闭,重启生效:

.host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other,nofail 0 0

参考资料:

【官方解决方案2】添加systemd挂载项(或init系统服务)

当前主流发行版init系统都是systemd,特征是有systemctl命令,主流发行版都适合使用此方法;除此之外,gentoo等比较小众的发行版中比较流行的另一个init系统是openrc

(systemd的方法)

1、使用sudo nano命令,以root创建/etc/systemd/system/mnt-hgfs.mount文件,内容如下:

[Unit]
Description=VMware mount for hgfs
DefaultDependencies=no
Before=umount.target
ConditionVirtualization=vmware
After=sys-fs-fuse-connections.mount

[Mount]
What=vmhgfs-fuse
Where=/mnt/hgfs
Type=fuse
Options=default_permissions,allow_other

[Install]
WantedBy=multi-user.target

2、使用sudo nano命令,以root创建/etc/modules-load.d/open-vm-tools.conf,内容如下:

fuse

3、使用下面的命令启用mnt-hgfs.mount系统服务:

sudo systemctl enable mnt-hgfs.mount

4、使用下面的命令加载fuse内核模块:

sudo modprobe -v fuse

5、启用共享文件夹,/mnt/hgfs应该已经挂载了共享文件夹,如果仍然为空,重启或使用下面的命令手动启动mnt-hgfs.mount系统服务:

sudo systemctl start mnt-hgfs.mount

(systemd安装脚本)

将以下内容保存为文本文件,假设为vmhgfs-automount-install.sh,使用chmod +x vmhgfs-automount-install.sh加上可执行权限,最后用sudo ./vmhgfs-automount-install.sh运行:

#!/bin/bash
# This file enables the persistent mounting of HGFS VMware shares.

if [[ $EUID -ne 0 ]]; then
    echo "This script must be run as root" 
    exit 1
fi

cat <<EOF >/etc/systemd/system/mnt-hgfs.mount
[Unit]
Description=VMware mount for hgfs
DefaultDependencies=no
Before=umount.target
ConditionVirtualization=vmware
After=sys-fs-fuse-connections.mount

[Mount]
What=vmhgfs-fuse
Where=/mnt/hgfs
Type=fuse
Options=default_permissions,allow_other

[Install]
WantedBy=multi-user.target
EOF

echo "fuse" >/etc/modules-load.d/open-vm-tools.conf

modprobe -v fuse
systemctl enable mnt-hgfs.mount
systemctl start mnt-hgfs.mount

(openrc的方法)

1、使用sudo nano命令,以root创建/etc/init.d/vmware-hgfs文件,内容如下:

#!/sbin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

description="vmware shared directory mounter"

vmhgfsfuse_command="/usr/bin/vmhgfs-fuse"
vmhgfsfuse_pidfile="/run/vmhgfs-fuse.pid"

depend() {
    need fuse
    after vmware-tools
}

start_pre() {
    checkpath -d -m 0755 -o root:root /mnt
}

start() {
    ebegin "Starting vmhgfs-fuse"
    start-stop-daemon --background --make-pidfile --pidfile "${vmhgfsfuse_pidfile}" --start "${vmhgfsfuse_command}" -- /mnt/hgfs -orw,default_permissions,allow_other,dev,suid -f
    eend $? "Failed to start vmghfs-fuse"
}

stop() {
    ebegin "Stoping vmhgfs-fuse"
    start-stop-daemon --stop --pidfile "${vmhgfsfuse_pidfile}"
    eend $? "Failed to stop vmhgfs-fuse"
}

2、使用下面的命令启用vmware-hgfs系统服务:

sudo chmod +x /etc/init.d/vmware-hgfs
sudo rc-update add vmware-hgfs default

3、重启或使用下面的命令手动启动vmware-hgfs系统服务:

sudo rc-service vmware-hgfs start

(对于使用sysvinit或upstart的老版本发行版,可以直接用自带的vmware tools解决) 

(open-vm-tools和自带的vmware tools实际上只兼容sysvinit/upstart/systemd这些主流发行版使用的init系统,小众init系统如openrc/runit/bsdinit需要手动编写init脚本适配,实际上即使是gentoo的openrc脚本也是gentoo方面编写并以patch形式分发的)

参考资料:

【其他解决方案1】卸载open-vm-tools[-desktop],并安装vmware自带的vmware tools(过时,不推荐)

不推荐:与当前主流版本linux有兼容性问题,比如复制粘贴拖放会失效,因为vmware自带版本只适用于非常老的linux版本,vmware官方推荐新版linux使用open-vm-tools[-desktop]

# 彻底卸载open-vm-tools[-desktop],一定要用--purge
sudo apt autoremove --purge open-vm-tools open-vm-tools-desktop
# 这里最好重启一下
# 换成vmtools的光盘linux.iso,安装vmware自带的vmware tools
cp /mnt/cdrom0/VMwareTools-*.tar.gz
tar xvf VMwareTools-*.tar.gz
cd vmware-tools-distrib
sudo ./vmware-install.pl -d -f

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐