Mr Lazy

November 18, 2009

Auto remount of WDTV network shares on NAS startup

Filed under: NFS,WD TV — Mr Lazy @ 17:08
Tags: , , , , , , , ,

You don’t always want a NAS to be on 24×7 – some NASs have a scheduled power-off/on feature.  Unfortunately when I enabled this feature on my Synology DiskStation I discovered that the WD TV would produce a ‘Folder is empty’ message for the NFS shares after the NAS had restarted.  Playing around with the NFS mount parameters did not produce a solution.  Here’s my workaround…

The below procedure will install OpenSSH* on the WDTV via optware, set up SSH between the Synology DiskStation and the WDTV and run a script on the NAS to connect to the WDTV and re-mount the NFS shares.  A basic knowledge of Linux (ie. navigation via CLI, editing text files etc.) is required.  Although written for the DiskStation, it should work with any NAS that runs an embedded Linux and supports NFS and SSH.  I’ve tested it on ext3-boot, and hopefully it will work on WDLXTV with perhaps a little tweaking of file locations necessary.

1. first you need to ensure you have optware installed on your WDTV.  Available from: http://b-rad.cc/optware-for-wdtv

2. install OpenSSH:

# /opt/bin/ipkg update # /opt/bin/ipkg install openssh

3. now we need to set up SSH.  On the NAS, log in as root:

DiskStation> ssh-keygen Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is: c5:49:8a:39:a2:06:19:c4:26:2c:f7:a4:1a:81:ce:a5 root@DiskStation
The key's randomart image is:
+--[ RSA 2048]----+
|*.        .      |
|=*...  o + .     |
|Ooo+. + . +      |
|.E.... . .       |
| oo     S        |
|..               |
|                 |
|                 |
|                 |
+-----------------+

Obviously your fingerprint and randomart image will be different, but you can ignore these anyway.

4. on the WDTV log in as root.  Unless you’ve changed it, the home directory of the root user on ext3-boot will be ‘/’, so that’s what I’ll assume here.  Create a hidden directory called .ssh below ‘/’, set the necessary permissions and change to the new directory:

# cd
# mkdir .ssh
# chmod og= .ssh # cd .ssh

5. now you need to get the public key that was generated on the NAS over to the WDTV.  The public key was stored in the file /root/.ssh/id_rsa.pub on the NAS.  On the WDTV the public key needs to be stored in the file ‘authorized_keys’ in the .ssh directory.  There are several ways of doing this.  The most reliable is to copy the file to a network share that the WDTV has access to, then use the following command:

# mv /pathtoshare/id_rsa.pub /root/.ssh/authorized_keys

Alternatively a crude but simple method is just to use the Windows clipboard.  On the NAS type:

DiskStation> cat /root/.ssh/id_rsa.pub

and select the output (from the first ‘s’ of ‘ssh-rsa’ to the last character ie. the ‘n’ of ‘DiskStation’, but not beyond) with your mouse to copy it to the Windows clipboard.  Back on the WDTV, type echo, then space, then paste (right-click) followed by a ‘>’ followed by ‘authorized_keys’.  So the full command should look something like this:

# echo ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0rPE8n6R/rslffzIPZL3KNmIXL7Hn3176hJkL[SNIP]+wGOQ== root@DiskStation > authorized_keys

your public key will be a lot longer than this, I’ve shortened it for the sake of clarity.  I’ve also added spaces either side of the ‘>’ but this is not necessary.

6. now we need to set the correct permissions on the authorized_keys file:

# chmod og= authorized_keys

7. you should now be able to connect from the NAS to the WDTV without entering a username and password.  Try it by typing:

DiskStation> ssh root@wdtv.lan

8. now we need to set up some scripts on the WDTV to do some unmounting and mounting.  Type mount -t nfs.  Here are some of my NFS mounts:

192.168.1.7:/volume1/OurMusic on /tmp/media/usb/USB1/OurMusic type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=192.168.1.7)
192.168.1.7:/volume1/OurMusic on /tmp/media/usb/OurMusic type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=192.168.1.7)
192.168.1.7:/volume1/OurMusic on /tmp/media/usb/USB1/8AA6-71D0/OurMusic type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=192.168.1.7)
192.168.1.7:/volume1/DVD on /tmp/media/usb/USB1/DVD type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=192.168.1.7)
192.168.1.7:/volume1/DVD on /tmp/media/usb/DVD type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=192.168.1.7)
192.168.1.7:/volume1/DVD on /tmp/media/usb/USB1/8AA6-71D0/dvd type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=192.168.1.7)

the items in bold are the mount points and these are what will need to be unmounted by our script.  So, I created a file called ‘unmount’ in /usr/bin that looks like this:

#!/bin/sh
umount /tmp/media/usb/USB1/DVD
umount /tmp/media/usb/DVD
umount /tmp/media/usb/USB1/8AA6-71D0/DVD
umount /tmp/media/usb/USB1/OurMusic
umount /tmp/media/usb/OurMusic
umount /tmp/media/usb/USB1/8AA6-71D0/OurMusic

notice the ‘#!/bin/sh’ at the top.  In very basic terms, this tells Linux that it’s a shell script.  The umount command does accept wildcards, but I found that this was unreliable as a) it tried to unmount files that were on my USB stick and b) if it tried to un-mount a sub-directory it would give a ‘resource busy’ error.  Of course, there will be a way to automate this, but for the sake of typing a few lines and using copy/paste I don’t see the point.

9. there’s no point creating a new script to mount the NFS shares again, because we already have one – it’s called net.mounts.  Turn the file into a script by adding ‘#!/bin/sh’ as the first line.

10. I created a script called ‘remount’ in the /usr/bin directory which looks like this:

#!/bin/sh
/usr/bin/unmount
/boot/net.mounts

of course, I could have just put the umount commands in this script, but I thought it would be useful to be able to unmount all the NFS shares at any time without necessarily wanting to mount them again.

11. set the necessary permissions on the scripts:

# chmod 755 remount unmount
# chmod 755 /boot/net.mounts
# ls -l remount unmount
-rwxr-xr-x    1 root     root           73 Nov 17 21:19 remount
-rwxr-xr-x    1 root     root          450 Oct 14 15:58 unmount
# ls -l /boot/net.mounts
-rwxr-xr-x    1 root     root         1050 Nov  9 20:57 /boot/net.mounts

12. as always, test that the scripts work by running them. For example, you should be able to just type ‘remount’ regardless of which directory you are currently in

13. if all is well, now test things from the NAS.  Type:

DiskStation> ssh root@wdtv.lan /usr/bin/remount

and check from the WDTV to watch your shares disappear from ‘mount -t nfs’ and reappear.

14. now we need to add a script to the startup of the NAS.  Go to /usr/syno/etc/rc.d and choose an appropriate name for your script.  I started mine ‘S99…’ as I figured it needed to start after most of the others services (ie. NFS, SSH) had started.  Don’t forget to add a ‘.sh’ suffix otherwise it won’t get started by the DiskStation boot process.  Just two lines:

#!/bin/sh
ssh root@wdtv.lan /usr/bin/remount

15. remember to set the correct permissions:

DiskStation> chmod 755 S99myscript.sh
DiskStation> ls -l S99myscript.sh
-rwxr-xr-x    1 root     root          105 Nov 17 16:53 S99myscript.sh

16. and that’s it!  Test that it works by going into DSM and selecting Shutdown -> Restart.

If any WDLXTV users try this please drop me a note to let me know what you had to change, many thanks.

Now all I need is for Synology to allow users to disable the annoying startup beep 🙂

*You could try using the dropbear SSH server if you want – this is pre-installed with ext3-boot or you can download the app.bin for WDLXTV.  I couldn’t get it to work, it wouldn’t recognise the correct permissions on root’s home directory even when I moved it to one level below ‘/’, but I’m now wondering if I needed to generate new host keys – I didn’t bother trying again.  The only advantage of using dropbear is if you’re running loads of apps as it takes up less space than OpenSSH.  The advantage of OpenSSH is that it’s the same as what’s running on the Synology so no worries about compatibility plus the commands are the same on both systems.

August 4, 2009

Auto-mount of NFS shares on PC startup

Filed under: NFS,WD TV — Mr Lazy @ 15:06
Tags: , , , ,

I’m saving up for a “proper” NAS, so at the moment I’m running my NFS shares off my main PC.  I don’t keep the PC on 24×7 but the WD TV does tend to stay on and I got tired of either rebooting the WD TV or manually re-mounting the shares if the PC had been re-started for whatever reason.  So, being the lazy type, I automated it, so that whenever the PC starts up it connects to the WD TV and runs the necessary xmount commands.

For this I used a program call ‘plink’ which comes as part of PuTTY http://www.chiark.greenend.org.uk/~sgtatham/putty/

I created a text file containing all my xmount commands and called this wdtv_commands.txt.  I saved it in the PuTTY directory which is probably not logical but it could go anywhere.

I then created a Windows Command Script (.cmd) file on the desktop containing the following two lines:

cd C:\Program Files (x86)\PuTTY
plink.exe wdtv-ssh -pw "" -batch -m wdtv_commands.txt

wdtv-ssh is the name of a PuTTY saved session which simply creates a SSH connection to the WD TV and uses the username of ‘root’

-pw “” tells plink to use a blank password

-batch tells plink to disable interactive prompts

-m tells plink to read commands from a file

I then set up a task in Task Scheduler to run the command script at Windows Startup.  A condition is also set to ensure the PC’s Ethernet is up, and the task is also delayed by one minute to be safe.

Obviously the advantage of putting the script on the desktop is that I can easily run it at any time.

Of course I still have the xmounts on the WD TV, and this way whether my PC restarts or my WD TV restarts, the NFS shares are mounted.  There can be times when the mounts are duplicated on the WD TV, but this does not seem to cause a problem.

On a related subject I created a desktop shortcut to run the ‘showmount’ command that comes with Truegrid NFS.  Again it’s a command script (.cmd) that contains the following line:

CMD /K "C:\Program Files (x86)\Truegrid\showmount.exe"

The ‘/K’ parameter stops the window from closing once the command has completed.

How to setup NFS shares on WD TV using haneWIN

Filed under: NFS,WD TV — Mr Lazy @ 13:16
Tags: , , , , , ,

Purpose: describe how to set up NFS shares on a Windows Vista PC using haneWIN NFS Server and mount them from your WD TV.  This how-to assumes you are already running one of the community firmwares, have a working USB LAN adaptor and have set up networking (ie. your WD TV has an IP address and you can see it from your PC).  I’ve only tested it with ext3-boot, but it should work with WDLXTV (plus the NFS app pack of course).

UPDATE 27Aug09: after having tried again with haneWIN, I have finally settled on TrueGrid.  The day after I started using haneWIN again, the NFS service would not start for no obvious reason, even after I’d deleted and re-created the exports file (something which had previously fixed this problem).  Another time, the service simply refused to stop.  I can’t recall ever having had problems with TrueGrid.  The way I see it, the only reason to use haneWIN over TrueGrid is if you have files larger than 2.2GB (I’ve yet to try Labtam ProNFS other than just a brief test).

Note: although the program states that there is a 30-day evaluation period, in my experience the program keeps on working.

1.  Download haneWIN NFS Server from http://www.hanewin.net/nfs-e.htm

2.  install the software using the setup utility.  By default, the program installs into Program Files\nfsd, but I chose to install to Program Files\haneWIN, as it’s more meaningful

3.  this should also automatically install and start the two necessary services.  To check: Start > All Programs -> Administrative Tools -> Services

screenshot of nfs service hanewin

screenshot of sunrpc service hanewin

 4.   from either the Desktop or the Start menu, select the NFS Server program.  Note that this ‘control panel’ doesn’t have to be running for the NFS server to work (just the two Windows services above, which should start with Windows), it is only used to setup the server.  You can also start the program from the Windows Control Panel

screenshot of start menu hanewin

5.  select the Exports tab and select the ‘Edit exports file’ button.  The exports file is how you tell the NFS Server what shares you want to share with your WD TV.  An example exports file is included with haneWIN and this will have opened in Notepad when you selected this button

6.  modify the exports file according to your needs.  You need to insert the Windows path, followed by a space, followed by ‘-name:’ and then the name you want to call the share (this is how you will reference it from the WD TV).  Below is an example:

screenshot of exports hanewin

Note that the exports file has no extension – the filetype is just ‘File’, so don’t try and save it with a .txt extension because haneWIN won’t like it.

7.  select the ‘Restart Server’ button

NOTE: when you make changes in the future, I would advise you to stop the NFS Server service before editing the exports file.  Then, either restart it manually or select the Restart Server button.  This is because sometimes I found that the exports file would get corrupted if I tried to edit it whilst the server was still running and I had to delete and create a new exports file.

8.  the Exports tab should now auto-update.  This is what my Exports tab now looks like:

screenshot of exports tab hanewin

Notice that the Exports tab shows only the name I gave the share, not the full path.

That should be all we need to do on the PC side – you should be able to leave all the other haneWIN settings at default.  Before we set things up permanently on the WD TV we’ll first test to make sure we can see the NFS share from the WD TV.  [If you are not comfortable with using telnet/SSH and/or the command line, you don’t have to do this, but it’s a lot quicker because you don’t have to edit any files or reboot the WD TV etc.] 

10.  login to your WD TV, using a username of ‘root’ and a blank password (ie. press return)

11.  type the following:

xmount <IP address>:/DVDs DVDs nfs

where <IP address> is the IP address of your PC, for example xmount 192.168.1.2:/DVDs DVDs nfs.  If the command has been successful you will receive no messages (though just because you receive no message does not necessarily mean the share is mounted)

12.  type:

mount -t nfs

this will show you all the mounted NFS shares, if any.  If you don’t get anything back, it didn’t work.  You should see something like this:

192.168.1.2:/DVDs on /tmp/media/usb/USB1/DVDs type nfs (rw,v3,rsize=8192,wsize=8192,soft,intr,lock,proto=udp,addr=192.168.1.2)
192.168.1.2:/DVDs on /tmp/media/usb/DVDs type nfs (rw,v3,rsize=8192,wsize=8192,soft,intr,lock,proto=udp,addr=192.168.1.2)
192.168.1.2:/DVDs on /tmp/media/usb/USB1/8AA6-71D0/DVDs type nfs (rw,v3,rsize=8192,wsize=8192,soft,intr,lock,proto=udp,addr=192.168.1.2)

the pathnames may be slightly different with the WDLXTV custom firmware and the parameters at the end may be different (regardless of firmware), but don’t worry about this for the moment

13.  on the haneWIN control panel, select the Mounts tab.  It should now reflect the shares that the WD TV has mounted:

screenshot of mounts tab hanewin

14.  if all is well, you can now set things up on a permanent basis on the WD TV.  You need to edit the net.mounts file, either by copying it to your PC, editing it using your favourite text editor and writing it back to the USB stick (or hard drive in the case of WDLXTV) or, if you are feeling adventurous, use vi (or another text editor) directly on the WD TV.

Here’s the relevant line for my share:

xmount 192.168.1.2:/DVDs DVDs nfs udp,rsize=32768,wsize=32768

the UDP parameter forces haneWIN to use the UDP protocol as opposed to TCP – most people, including myself, have found UDP to be faster.   The rsize and wsize parameters tell NFS what transfer block size to use – because haneWIN supports NFS v3, it allows us a maximum of 32768 bytes.  However, you may have better results using a smaller size depending on your network etc.

15.  you will now need to reboot your WD TV.  Test that the share is visible by going in to the relevant folder from the GUI/OSD.  Make sure the share contains at least one file of the relevant type (ie. a video file if you are going via ‘Video’).

If you have any problems disable any firewall on your PC and try again.  If  problems persist I would recommend starting a new topic at wdtvforum.com

June 17, 2009

How to setup WD TV with NFS using TrueGrid

Filed under: NFS,WD TV — Mr Lazy @ 15:55
Tags: , , , , , ,

Purpose: describe how to set up NFS shares on a Windows Vista PC using TrueGrid NFS Server V1.1 and mount them from your WD TV.  This how-to assumes you are already running one of the community firmwares, have a working USB LAN adaptor and have set up networking (ie. your WD TV has an IP address and you can see it from your PC).

Note that TrueGrid only supports NFS version 2 – the only significant disadvantages of this are:
a) it limits you to a maximum transfer size of 8192 bytes. 
b) the maximum file size is 2GB (actually in my testing I’ve found it to be around 2.2GB).  If you want to stream files bigger than this, you probably need to look for another NFS server (ie. haneWIN etc.) or a NAS.

Also, it only supports UDP not TCP, though this should not be an issue for most users.

You may have heard some people talking about ‘NFS Dream’.  NFSDream is a GUI front-end for configuring TrueGrid which was developed by owners of the Dreambox Linux-based satellite receiver.  You may download and install it if you wish, but personnally I found that it did not help, therefore I will not be including it in this how-to.

At the time of writing I’ve only gone through this using ext3-boot, but in theory WDLXTV should work the same way.

1. Download TrueGrid NFS Server V1.1 from either of these sources:
http://www.acmeconsulting.it/pagine/opensource/download/
ftp://ftp.slac.stanford.edu/groups/glast/Online/support/nfs.zip

2. create a folder where you want TrueGrid to reside.  I created a folder in Program Files. 

3. extract the files to that folder

4. create a directory called ‘etc’ in C:\Windows

5. copy the files ‘rpc’ and ‘exports’ to the etc folder

 etc folder

6. the ‘exports’ file is where we tell the NFS Server which shares (ie. directories) we want the WD TV to be able to see.  Open up ‘exports’ into Notepad or your favourite text editor

7. see the screenshot for an example exports file:

example exports file

I’ll use the ‘test’ share for the purposes of this how-to, but before we move on take a look at the 2nd line – “/OurMusic” is how the folder will be shared with the WD TV – the WD TV will have no knowledge of the actual directory path ie. C:\Users\admin\Music.  You can either use ‘test’ to follow the rest of this how-to or set up your own share in the exports file now.

8. now we need to install and start the necessary services in Windows.  Open a command prompt window

9. cd to the directory where the TrueGrid files are

10. type:

portmap add
nfs add
portmap start
nfs start

keep the command prompt window open for the moment

11. check that the two relevant services are running by opening up the Services window.  There may be more than one way to do this on your PC depending on how you’ve customized it:

Start -> Administrative Tools -> Services
OR
Start -> All Programs -> Administrative Tools -> Services
OR
Start -> Run… -> type ‘services.msc’ -> press Enter

you should see two services called ‘TrueGrid NFS Server’ and ‘TrueGrid Portmapper’ and their status should be ‘Started’.  From now on these services should start with Windows

12. let’s make sure that the NFS server is ‘exporting’ our test share.  Back to the command prompt window and (making sure we’re still in the TrueGrid directory) type:

showmount -e

you should see something like this:

TrueGrid SHOWMOUNT UTILITY.
COPYRIGHT (C) BY XYZ SCIENTIFIC APPLICATIONS, INC., 1998
ALL RIGHTS RESERVED.  TrueGrid IS A TRADEMARK OF
XYZ SCIENTIFIC APPLICATIONS, INC.
---
/test      (everyone)

13. before we set things up permanently we’ll first test things to make sure we can see the NFS share from the WD TV.  [If you are not comfortable with using telnet/SSH and/or the command line, you don’t have to do this, but it’s a lot quicker because you don’t have to edit any files or reboot the WD TV etc.]  Login to your WD TV, using a username of ‘root’ and a blank password (ie. press return)

type the following:

xmount :/test test nfs

where is the IP address of your PC, for example xmount 192.168.1.2:/test test nfs. If the command has been successful you will receive no messages (though just because you receive no message does not necessarily mean the share is mounted)

type:

mount -t nfs

this will show you all the mounted NFS shares, if any.  If you don’t get anything back, it didn’t work.  You should see something like this:

192.168.1.2:/test on /tmp/media/usb/USB1/test type nfs (rw,v2,rsize=8192,wsize=8192,soft,intr,lock,proto=udp,addr=192.168.1.2)
192.168.1.2:/test on /tmp/media/usb/test type nfs (rw,v2,rsize=8192,wsize=8192,soft,intr,lock,proto=udp,addr=192.168.1.2)
192.168.1.2:/test on /tmp/media/usb/USB1/8AA6-71D0/test type nfs (rw,v2,rsize=8192,wsize=8192,soft,intr,lock,proto=udp,addr=192.168.1.2)

the pathnames may be slightly different with the WDLXTV custom firmware and the parameters at the end will almost certainly be different (regardless of firmware), but don’t worry about this for the moment

14. back at the PC, you can type the following into your command prompt window:

showmount

you should see something like this:

TrueGrid SHOWMOUNT UTILITY.
COPYRIGHT (C) BY XYZ SCIENTIFIC APPLICATIONS, INC., 1998
ALL RIGHTS RESERVED.  TrueGrid IS A TRADEMARK OF
XYZ SCIENTIFIC APPLICATIONS, INC.,
---
wdtv:/test

15. if it worked, you can now set things up on a permanent basis.  You need to edit the net.mounts file, either by copying it to your PC, editing it using your favourite text editor and writing it back to the USB stick (or hard drive in the case of WDLXTV) or, if you are feeling adventurous, use vi (or another text editor) directly on the WD TV.

Here’s the relevant line for our test share:

xmount 192.168.1.2:/test test nfs rsize=8192,wsize=8192

the rsize and wsize parameters tell NFS what transfer block size to use – as previously stated TrueGrid allows us a maximum of 8192 bytes, and I see no reason to use anything less.

If we wanted, we could call the share something other than ‘test’ at this point.  If I had used ‘xmount 192.168.1.2:/test movies nfs udp’ then WD TV would represent the share using a folder called ‘movies’ and not ‘test’.  I would recommend keeping export and share names consistent throughout the whole path as well as trying to keep exports similar to the directories that they reference, otherwise things could start to get very confusing.

16. you will now need to reboot your WD TV.  Test that the share is visible by going in to the relevant folder from the GUI/OSD.  Make sure the share contains at least one file of the relevant type (ie. a video file if you are going via ‘Video’).

If you have any problems disable any firewall on your PC and try again.  If  problems persist I would recommend starting a new topic at wdtvforum.com

Blog at WordPress.com.