Mr Lazy

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.


Blog at