Jan 08

Share NFS from Windows

I recently bought a second raspberry pi, for the purpose of making it a "dumb" media center running XBMC (Raspbmc to be exact). I already have a media center PC running XBMC on Windows 7, and I wanted to connect my raspberry pi to the downloaded media, stored remotely on the Win7.

First, of course, I tried SMB (windows share). It worked… ok. But after installing a new HP Wireless printer, it seemed to disconnect a lot. I don't fully understand why, but it appears that the printer publishes itself as SMB master thus disconnecting my other SMB connections (or maybe only Linux ones)

Anyways, I have spent almost two days, understanding how to connect the Raspberry pi to Windows 7 using NFS. It was not easy, because it seems Microsoft has dropped support for it on home OS (even Win7 ultimate) since Windows XP.

I ended up doing it with Cygwin (which gives powerful Linux capabilities to windows machines).

I want to outline what I have done in order for this to work. This process could be very easy and it could be frustrating. I really hope it will help you do it yourself.

So it might do the trick as step-by-step, and you might come some obstacles on the way

The original guide I used can be found in this link, however it did not work at once and I had to tweak a bit. Also, it is referring to Windows XP.

As this is not step-by-step in full, with screenshots, it might help you on your journey. This can also help you with any windows share to be exported to linux

Here it is:

On the windows machine:

  1. Download Cygwin 32bit (not 64, even if you are running 64 bit machine)
  2. During install, make sure you install the following packages:
    1. cygrunsrv
    2. nfs server
    3. less
  3. Make sure your windows username has a password (this is important). If you don't want to type it when you log in, you can follow this guide
  4. Start Cygwin as administrator
  5. Due to a strange behavior of Cygwin, you must remount your desired drive as a different mount
mkdir -p /mnt/d

mount d:/ /mnt/d/
  1. install nfs server installation
  1. Answer that you want to run nfsd as separate account, and type in your current username and password
  2. Now, it's time to edit the exports file (the file in charge of sharing mount points)
    1. Either edit /etc/fstab in Cygwin, or c:\cygwin\etc\exports in windows
    2. Add the following line (only one example)

      /mnt/d (rw,all_squash,anonuid=1000,anongid=513)
      ** This does not limit network connections to the share

      ** This limits connections only from 192.168.0.x network

    cygrunsrv --start mountd

    cygrunsrv --start nfsd

    cygrunsrv --start portmap

  1. You will need to fix cygwin's fstab in order to preserve the mountpoint (cat /etc/mtab) and copy the new line to /etc/fstab
    If you will not do that you risk losing the mountpoint at windows reboot
  2. Add windows firewall exception for c:\cygwin\usr\sbin\rpc.nfsd.exe
  3. Add windows firewall exception for TCP,UDP 2094 and 111
  4. There will be another port to add. I'm not sure which one will it be but you will notice it later (if you get "connection timeout" – this is firewall issues)

On the raspberry pi

(This can be any other Linux box. You must have root permissions!)

  1. Create a folder to mount to
mkdir -p ~/share
  1. mount the new share to this folder
sudo mount -v -t nfs share

Note: other switches might help on some machines. Example

sudo mount -v -t nfs -o vers=2 -o nolock share
  1. Here was a big tricky part. After successful mount, I could not cd in any folder. I fixed this in two steps:
    1. On raspberry pi and on windows I performed "chmod -R 755 *" on the share (on Cygwin on /mnt/d and on linux on ~/share)
    2. On Cygwin I did chown on /mnt/d with the windows username and "none" group. For instance, if you windows username is "Sara", you should do "chown -R Sara:None /mnt/d"

      This might needs to be done as root (sudo)

  • If you got to this part, you are very lucky and can almost rest!
    1. Perform /cat/mtab and copy last line in full (this is the line containing your new mount)
    2. Edit fstab (sudo nano /etc/fstab) and paste this line at the end
    3. That's it! If you want to test it – reboot your raspberry pi/linux

This is it! Exhausting, I know. But worth it. For some reason NFS works way better than SMB. To add the share to XBMC simple add a source on the "home directory" and choose "share"

I really really hope this can come in handy to some of you. I will do my best to answer questions and I assume there is a better simpler way, but this is how I did it

EDIT: It appears cygwin sets new files with 000 permission, which will cause your remote client not to be able to do anything with the new files. To overcome this, edit the /etc/fstab on your cygwin (windows) machine, and add this line in the bottom (replacing the old one).

none /cygdrive cygdrive binary,noacl,posix=0,user 0 0

Following this, restart your cygwin and three services installed earlier. That's it (Thanks for this post)

  • Nazar

    Hi Arnon,

    Do you have any idea why I encountered the following two errors? I have followed your instructions. Also tried disabling the Win8.1 firewall and ran the services as system (initially a new account created from nfs-server-config). Googling yielded no help for me.

    nfsd: PID 88788: unable to register (nfsd, 2, udp).

    mountd: PID 34308: unable to register (mountd, 1, udp).


  • http://www.morethantechnical.com Arnon

    Hi Nazar,
    Are you running cygwin terminal as administator?
    In my opinion this appears to be the problem.
    I must add to the post above that cygwin only supports NFSv2 (which limits file size to 2GB tops which is kind of a drag)
    So if you want minimum effort, consider using haneWIN NFS Server (not free but not expensive either)

  • Nazar

    Hi Arnon,

    Thanks for replying. Yes I was running with an elevated admin account. I did more research an it appears to be a problem on recent Cygwin builds. I found an older cygwin1.dll v1.7.18 which works but for that matter, I need to downgrade Cygwin all together as newer builds daemon such as sshd won't go well with older dlls.

    I'm on haneWIN NFS Server trial and will decide later as I too just installed nfsd on Ubuntu server via VM.

  • http://kvvs.nl kvvs

    The screenshots aren't working anymore :(
    Could you provide written instructions where it's needed?

  • http://kvvs.nl kvvs

    Nevermind my previous comment, i read it incorrect!
    I got it working (barely) but was fussing around quite a lot, thanks a LOT for the tutorial, now i can finally stream big files!

  • http://zzlatev.com Zlatev

    What is the problem using 64bit cygwin?

  • http://www.morethantechnical.com Arnon

    To the moment this post was written, NFSd didn't exist on the 64 bit package
    I didn't check if this was changed since then. I hope it did :)