File sharing between Ubuntu VM and Windows 7

7,648

Solution 1

I recommend to use autofs instead of a static fstab entry. See: https://help.ubuntu.com/community/Autofs

Solution 2

1. umount -f

This is not a solution nor work around, but a procedure (an annoying one).

After VM resume, do not try to view the share drive with Nautilus or any program. Do not do ls to it. Any kind of access will trigger a 5min timeout and make the share busy. Just do the umount -f before anything.

    umount -f <localsharepath>

-f Force unmount (in case of an unreachable server).

As long as the share is not busy, this will unmount the share immediately without triggering the 5min cifs timeout.

This is definitely not ideal, but it does not require rebooting and the share can be mount again right away.

2. Change smbfs to cifs with defaults

//<remotehost>/<sharename> <localsharepath> cifs defaults,uid=1000,username=<remoteusername>,password=<remotepassword> 0 0

It is official that smbfs is not being maintained anymore

smbfs has not been maintained in the last few years. Instead, development has been focused on another implementation of the CIFS protocol in the kernel. See the CIFS VFS for more information.

Base on comment of this blog (cannot find more authoritative reference)

stintel Friday 9 May 2008 : Another nice thing about CIFS is that it should survive a network outage or even a reboot of the system you are mounting a share from

3. Disable Opportunistic Locking and Lookup Caching (No effect in reducing the 5min connection timeout)

echo '0' > /proc/fs/cifs/OplockEnabled
echo '0' > /proc/fs/cifs/LookupCacheEnabled

4. Check Open File (Not applicable base on comment)

After Ubuntu VM resume, check if any user/process is using any file/directory in share folder

lsof | grep '<localsharepath>'

If any user/process is using files/directory in < localsharepath >, you will get device busy(This is regardless of how it is mount, local or remote).

Share:
7,648

Related videos on Youtube

Desmond Hume
Author by

Desmond Hume

Updated on September 18, 2022

Comments

  • Desmond Hume
    Desmond Hume over 1 year

    I've got Ubuntu 12.04 running as Guest in a virtualized VMware Workstation 9 session on a Windows 7 host. The Windows machine shares a folder with the Ubuntu machine via CIFS and the Ubuntu machine mounts the shared folder automatically on startup thanks to this line in /etc/fstab file:

    //<remotehost>/<sharename> <localsharepath> cifs soft,uid=1000,username=<remoteusername>,password=<remotepassword> 0 0
    

    File sharing through the mount works fine until there is a need to resume the Ubuntu virtual machine after it was paused or to restore it from a snapshot. This typically happens after the Windows host machine was restarted or started after a nightly shutdown.

    After Ubuntu is resumed, the folder that contains the mount of the shared folder does not list any items. The Nautilus window just hangs for a long time completely empty with "Loading..." in its bottom right corner, despite of the fact that there are lots of other folders and files in that folder to show.

    Restarting the Ubuntu machine does help but it isn't practical: Ubuntu takes forever to shut down, it just hangs on one of those final command line screens desperately waiting for something (when the mount is accessible, there is no such problem). For now, the only option is to power off Ubuntu brutally and then power it back on in order to be able to access the mount, which, of course, is not practical either.

    My guess is that when some CIFS/Samba communication parameters get changed (after Windows is restarted) the restored image of the Ubuntu virtual machine somehow fails to catch up.

    Even with VMware Tools installed on the Ubuntu machine, the VMware's shared folder feature, which could serve as an alternative, doesn't work for Ubuntu 12 (and many other Linux distros). But even if it did, CIFS/Samba sharing would still be required for file sharing with other virtual machines.

    • Luis Alvarado
      Luis Alvarado about 11 years
      It is my believe this is more of a problem related to the Virtual software you are using and on what host you are using it. Can you add what virtualization software you are using?
    • Pavel A
      Pavel A about 11 years
      Have you tried remounting the share? Like: umount <localsharepath>; mount -a.
    • Desmond Hume
      Desmond Hume about 11 years
      @PavelA Yes. It keeps saying "device is busy".
    • John Siu
      John Siu about 11 years
      (1) Is there some daemon software (dababase, etc) using files in the share? (2) Any error message from syslog?
    • Desmond Hume
      Desmond Hume about 11 years
      @JohnSiu (1) No such daemon software whatsoever, nothing is locking any of the files in the share. (2) The only type of syslog entry I found is CIFS VFS: Server <remotehost> has not responded in 300 seconds. Reconnecting.... Anyone with access to a PC and with a trial version of VMware Workstation can easily replicate the problem. There is even no need to restart Windows in order to put it in a realistic context. Just restarting the Windows service called "Server", which is responsible for file sharing off Windows, while Ubuntu is paused will do the trick.
  • John Siu
    John Siu about 11 years
    Are you able to unmount the share with cifs?
  • Desmond Hume
    Desmond Hume about 11 years
    Same thing as with smbfs, it says "device is busy".
  • John Siu
    John Siu about 11 years
    Is that mount point being share out by samba? Stop samba before unmount.
  • Desmond Hume
    Desmond Hume about 11 years
    No, that mount point is only shared in, not out. The Ubuntu machine is never a file sharing server, only a client.
  • John Siu
    John Siu about 11 years
    Try mount with option soft. I updated the answer.
  • Desmond Hume
    Desmond Hume about 11 years
    Nope. soft didn't make any difference. And by the way, soft is a default option, every mount uses it, except if explicitly specified otherwise.
  • Desmond Hume
    Desmond Hume about 11 years
    After several tests, I have to say that the problem doesn't go away with autofs. Yes, it unmounts the share automatically after a specific time and if the Ubuntu machine gets paused or snapshot after the share gets auto-unmounted then it's all fine with the mount after the Ubuntu machine is resumed. But if Ubuntu is paused before the share gets auto-unmounted, it enters the very same collection of problems upon resuming. And if I set the number of auto-unmount seconds to some small value, say, 10 seconds, the Nautilus windows start to close spontaneously when browsing the shared files.
  • John Siu
    John Siu about 11 years
    Last try. Check (1) and (3).
  • Desmond Hume
    Desmond Hume about 11 years
    (1) It accepted echo '0' > /proc/fs/cifs/OplockEnabled command just fine when I ran it as root, but not echo '0' > /proc/fs/cifs/LookupCacheEnable command, said no such file or directory. (2) I added defaults option to fstab and rebooted Ubuntu. Alas, no positive changes. (3) When I do lsof | grep '<localsharepath>' after Ubuntu is resumed, it hangs up for a long long time and finally outputs lsof: WARNING: can't stat() cifs file system <localsharepath>. There is nothing special about that share. No program is using any of the files in the share on neither Ubuntu or Windows.
  • John Siu
    John Siu about 11 years
    Updated with umount -f which will not trigger 5min timeout, as long as procedure is followed.
  • John Siu
    John Siu about 11 years
    @DesmondHume Additionally, if any program, or a terminal session cd into the share and stay there, it is consider using the share and the share will stay "busy". This is true with any mount point.