Like many people, I have a media server which stores all of my films, music and pictures in all one central place. It's a Centos Linux box with a SATA card and software Raid5, it serves to devices like my Acer Revo running Xbmc and Mythtv frontend. With this configuration it's a little noisy, creates a bit of heat and probably uses a bit of electricity, but turning it on can be a bit of a hassle. Particularly when it's at the other end of the house. My solution autofs and wake on lan.
autofs is a suite of tools that will auto mount devices and NFS shares when you first use them. Wake on LAN on my setup was a small cable that goes between my (dlink) PCI network card and my motherboard and I had to edit the BIOS to allow the machine to be woken. There seems to be a number of different ways to setup WOL on linux. I had to use ethtool to put the network card in a fit state to be woken up when the server was shutdown:
ethtool -s eth1 wol g
I actually put this in a Bash script and then called it from a script called "ifdown-post" located in:
This gets called on shutdown.
To wake the machine up I used the etherwake command. My xbmc machine uses Ubuntu as it's base OS. The package is simply called "etherwake"
So to wake up the remote machine you would use:
In my case:
The command is located in /usr/sbin on my install. Execute and bingo the machine powers up.
Now, a little used feature on autofs is the executable map. Maps normally are just plain text showing where to and what to mount and with which options. An executable one, is a shell script, in my case Bash, which the mount bits echo'd out at the end.
To use with autofs, you need to have NFS installed running on the machine you want to mount and a filesystem or directory exported in:
which looks something like this on mine:
This allows ws022 on my network to mount that directory as read/write.
On the mounting machine you need autofs running and the maps in /etc looking something like this:
/mnt/mnts/media-server /etc/auto.media-server --timeout=60
ping -c 1 -w 1 -q $hostsrv >/dev/null
if [ $status -ne 0 ]
/bin/echo -n "video"
/bin/echo -n -e "\t"
/bin/echo -n "$opts"
/bin/echo -n -e "\t"
Edit the files and make the auto.media-server file executable:
chmod 0750 /etc/auto.media-server
Then create your mount points:
mkdir /mnt/mnts /mnt/mnts/media-server
then give it a:
service autofs restart
What the above script does, is test if the server responds to a ping. If it doesn't, send a wake up call and wait 60 seconds, this is how long my machine takes to bootup. Once booted or if it already is, echo out the mount info.
So with the server shutdown, I can on the client machine:
and the server will power up, the client will wait a while and then mount the directory. Magic!
If anyone spots any errors, improvements or indeed a way to get it to auto shutdown when autofs unmounts, let me know.