vmware安装linux共享文件夹重启失效的解决办法

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

  • 22
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值