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:

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/
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/ 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/ /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/

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: on /tmp/media/usb/USB1/OurMusic type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr= on /tmp/media/usb/OurMusic type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr= on /tmp/media/usb/USB1/8AA6-71D0/OurMusic type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr= on /tmp/media/usb/USB1/DVD type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr= on /tmp/media/usb/DVD type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr= on /tmp/media/usb/USB1/8AA6-71D0/dvd type nfs (rw,v3,rsize=8192,wsize=16384,hard,lock,proto=udp,addr=

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:

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:


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:

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

15. remember to set the correct permissions:

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

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

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.

Create a free website or blog at