vmware / open-vm-tools

Official repository of VMware open-vm-tools project
http://sourceforge.net/projects/open-vm-tools/
2.23k stars 425 forks source link

Shared folder disappear after vm reboot under Ubuntu 18.04.4 #440

Open natehsu opened 4 years ago

natehsu commented 4 years ago

Hi,

I already add shared folders to vm(ubuntu 18.04.4), and it works. But the shared folder disappear after I reboot vm.

My settings: Win10 1909 vmware workstation 15 pro 15.5.6 settings - options - Shared Folders - Always enabled

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic
sudo apt show open-vm-tools-desktop 
[sudo] password for ubuntu: 
Package: open-vm-tools-desktop
Version: 2:11.0.5-4ubuntu0.18.04.1
Priority: extra
Section: universe/admin
Source: open-vm-tools
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Bernd Zeimetz <bzed@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 509 kB
Depends: libatkmm-1.6-1v5 (>= 2.24.0), libc6 (>= 2.14), libcairomm-1.0-1v5 (>= 1.12.0), libdrm2 (>= 2.4.3), libgcc1 (>= 1:3.0), libglib2.0-0 (>= 2.16.0), libglibmm-2.4-1v5 (>= 2.54.0), libgtk-3-0 (>= 3.9.10), libgtkmm-3.0-1v5 (>= 3.22.0), libice6 (>= 1:1.0.0), libsigc++-2.0-0v5 (>= 2.8.0), libsm6, libstdc++6 (>= 5.2), libudev1 (>= 183), libx11-6 (>= 2:1.4.99.1), libxext6, libxi6, libxinerama1, libxrandr2 (>= 2:1.2.0), libxtst6, open-vm-tools (= 2:11.0.5-4ubuntu0.18.04.1), fuse, kmod
Recommends: xauth, xserver-xorg-input-vmmouse, xserver-xorg-video-vmware
Suggests: xdg-utils
Breaks: open-vm-tools (<< 2:10.3.5-2~)
Replaces: open-vm-tools (<< 2:10.3.5-2~)
Homepage: https://github.com/vmware/open-vm-tools
Modaliases: vmwgfx(pci:v000015ADd00000405sv*sd*bc*sc*i*)
Download-Size: 137 kB
APT-Manual-Installed: yes
APT-Sources: http://tw.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages
Description: Open VMware Tools for virtual machines hosted on VMware (GUI)
 The Open Virtual Machine Tools (open-vm-tools) project is an open source
 implementation of VMware Tools. It is a suite of virtualization utilities and
 drivers to improve the functionality, user experience and administration of
 VMware virtual machines.
 .
 This package contains the user-space programs and libraries that are essential
 for improved user experience of VMware virtual machines.

I would appreciate your help.

silverqx commented 4 years ago

This bug exists as long as I remember, I can reproduce it almost in every distro I have installed.

natehsu commented 4 years ago

@silverqx Thanks for sharing

oliverkurth commented 4 years ago

Please see https://kb.vmware.com/s/article/74650 , I hope that helps.

silverqx commented 4 years ago

Great, if I create this systemd service, it works like expected, mount points are still there after restart, if I check / uncheck some mount point, this change is immediately reflected in /mnt/hgfs folder, would be nice to have similar service in open-vm-tools by default, for System V and Initd systems too.

I'm going to try original vmware tools and look how they handle this problem.

silverqx commented 4 years ago

Ok, here is what I discovered, in original vmware tools shared folders work by default after a restart, this functionality is provided by /etc/init.d/vmware-tools service, exactly this code in main function is responsible for automount hgfs during system start:

if [ "`is_vmhgfs_needed`" = 'yes' -a "`is_ESX_running`" = 'no' ]; then
    vmware_exec 'Guest filesystem driver:' vmware_start_vmhgfs
    exitcode=$(($exitcode + $?))
    vmware_exec 'Mounting HGFS shares:' vmware_mount_vmhgfs
    # Ignore the exitcode. The mount may fail if HGFS is disabled
    # in the host, in which case requiring a rerun of the Tools
    # configurator is useless.
fi

Would be nice to have something like this in open-vm-tools.

I searched little open VM tools and try to find code, which is currently responsible for mounting hgfs, when I enable shared folders in VM settings, without success for now ☹. @oliverkurth do you have some idea where can I find this code?

silverqx commented 4 years ago

I found another issue #201 which is related to this, maybe @lousybrit can help

oliverkurth commented 4 years ago

We do have a plan to add this to open-vm-tools, but it hasn't been prioritized. So far, the kb article is the best solution.

silverqx commented 4 years ago

I created openrc service /etc/init.d/vmware-hgfs for gentoo:

#!/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"
}

You can enable it by sudo rc-update add vmware-hgfs default

Toerktumlare commented 3 years ago

so how do i resolve this if i want to mount several host folders to several different guest folders? i can see that the [Mount] property in the service script seems to mount everything to the hgfs folder What=vmhgfs-fuse and Where=/mnt/hgfs i cant find any documentation on this syntax.

lousybrit commented 3 years ago

Hi there

You can have several mounts to direct shares instead or as well as the default shared folder mount. I do this sort of thing quite often.

The syntax for the default mount is "/usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o subtype=vmhgfs-fuse,allow_other" will give you the mount Guest OS mount path "/mnt/hgfs" points to server name and share root ".host:/" and all shares are listed under the guest path "/mnt/hgfs"

If you have VMware Tools Shared Folders called: Foo Bar Fred which all point to different locations on the host you can mount them directly in the guest. For example: sudo mkdir /mnt/Foo sudo mkdir /mnt/Bar sudo mkdir /mnt/Fred /usr/bin/vmhgfs-fuse .host:/Foo /mnt/Foo -o subtype=vmhgfs-fuse,allow_other /usr/bin/vmhgfs-fuse .host:/Bar /mnt/Bar-o subtype=vmhgfs-fuse,allow_other /usr/bin/vmhgfs-fuse .host:/Fred /mnt/Fred -o subtype=vmhgfs-fuse,allow_other

Now using df or other file IO operations you should see the same host files under /mnt/Foo and /mnt/hgfs/Foo Similarly for the other 2 examples.

Hope this helps explain the syntax. Thanks Steve

silverqx commented 3 years ago

The problem that folders are not mounted after restart still persists though.

lousybrit commented 3 years ago

An option that works for me is to add entries to the ./etc/fstab Using the above example: .host:/Foo /mnt/Foo fuse.vmhgfs-fuse defaults,allow_other 0 0 .host:/Bar /mnt/Bar fuse.vmhgfs-fuse defaults,allow_other 0 0 .host:/Fred /mnt/Fred fuse.vmhgfs-fuse defaults,allow_other 0 0

or the general share case .host:/ /mnt/hgfs fuse.vmhgfs-fuse defaults,allow_other 0 0

Toerktumlare commented 3 years ago

manually editing the ./etc/fstab is a pretty ugly solution especially as im trying to setup mounts using ansible and manually editing files does not work well will automated solutions.

i managed to eventually find the .host:\ syntax but like in most cases, vmwares own documentation leaves a lot to the imagination.

Right now im trying to get the mounting to work using systemd which is a more automated-friendly way. I still find this overly complex just to mount a folder.

lousybrit commented 3 years ago

Yes it is not the long-term solution but as Oliver indicated earlier in this thread an improved solution is in the plans. Other priorities have prevented this work from being scheduled recently.

We can also do an improved job with documenting some behaviors for sure. If you feel there are pieces like this that require more details and has been overlooked, please do report them on these forums. Thaniks

ghost commented 2 years ago

I created a script which auto-mounts the HGFS shared folders after reboot under, id 1000, the non-root user. Here's the gist. :)

Make sure the shared folder option is enabled but no folders are shared. Reboot after running the commands or script for it to take effect.

#!/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 <<EOT > /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,uid=1000,gid=1000

[Install]
WantedBy=multi-user.target
EOT

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

modprobe -v fuse
systemctl enable mnt-hgfs.mount
systemctl start mnt-hgfs.mount
dabockster commented 1 year ago

Please see https://kb.vmware.com/s/article/74650 , I hope that helps.

I just ran into this issue on a Fedora 37 vm. Based on what I'm reading, it's up to the distro to include the mount file needed for hgfs? I never had to add it in Ubuntu based OSes before.

nartamonov commented 2 months ago

Dear developers, this bug is really annoying. Shared folders is the basic functionality, one of the most popular. With the installation of the operating system (in my case Debian 12) and enabling shared folders, everything works. But after the reboot, the shared folders just disappear, without any warnings or logs except the following:

$ sudo journalctl --system | grep hgfs
Jul 01 13:26:54 dev systemd[1]: Unmounting mnt-hgfs.mount - /mnt/hgfs...
Jul 01 13:26:54 dev systemd[1]: mnt-hgfs.mount: Deactivated successfully.
Jul 01 13:26:54 dev systemd[1]: Unmounted mnt-hgfs.mount - /mnt/hgfs.

You have to spend time reading the forums, and understand why this happens. Then create manually configurations according to the article in KB.

This bug should be prioritized and corrected as soon as possible. Four years to fix it is a mockery of end users. Really, guys.

silverqx commented 2 months ago

They don't provide these services for every Linux distribution, they could but rather the idea here is that every distribution should handle it itself, as you can see, so it's up to you or it's up to the distribution how this will be solved.

They of course could create a systemd service that should solve this problem, or init.d script for distros that don't have systemd, but they won't solve this problem this way.

Also, there is nobody who would solve this issue, maybe in the far future this will be solved.

lousybrit commented 2 months ago

Dear developers, this bug is really annoying. Shared folders is the basic functionality, one of the most popular. With the installation of the operating system (in my case Debian 12) and enabling shared folders, everything works. But after the reboot, the shared folders just disappear, without any warnings or logs except the following:

For automatic mount on boot, you can add an entry to fstab. I have the following: vmhgfs-fuse /mnt/hgfs fuse defaults,allow_other 0 0

Or for a details :

Here is the text from the other thread about fstab and shared folder mounts: There are 2 ways to specify the Shared Folders mounts persistently in /etc/fstab Below there are both samples /etc/fstab line to mount a FUSE vmhgfs export.

Method 1: Specifying the file system

Replace with vmhgfs-fuse. Replace with the local file system on which the exported directory is mounted, which default replacement is to use /mnt/hgfs Replace with fuse. e.g. vmhgfs-fuse /mnt/hgfs fuse defaults,allow_other 0 0

Method 2: Specifying the remote server and share

:</remote/export> </local/directory> Replace with the hostname .host the shared folders name of the host server exporting the hosts file system. Replace </remote/export> with the path to the exported directory which defaults to/or you can use the /share-name-you-created. Replace </local/directory> with the local file system on which the exported directory is mounted, which defaults to /mnt/hgfs. Replace with fuse.vmhgfs-fuse. Eg. .host:/ /mnt/hgfs fuse.vmhgfs-fuse defaults,allow_other 0 0