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 email@example.com
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 firstname.lastname@example.org /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 email@example.com /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.