I’ve setup an NSLU2 to serve video to my iPod Touch. Here’s what I did.
I have a conflicted position with regard to technology. On one hand I think technology should just work. I have no time for cryptic interfaces and poorly written instruction manuals. This is why I like Apple. I have a Macbook, and Airport Extreme (with printer and hard drives attached) and an iPod Touch. These three devices constitute my home network and I’m pleased to say that it works perfectly.
However, I’m also a geek. When I see the flash of a green LED I can’t help but ask myself ‘I wonder if…’. Over time my geekish tendencies to fiddle have been tempered by my desire to have elegant solutions, so much so that I know refuse to let a geekish endeavour compromise the integrity a working solution. It turns out that this restriction has, possibly unsurprisingly, caused my geekish side to raise its’ game.
A few years ago I bit the bullet and ripped all of my CDs. It took a while, but it was a worthwhile investment. Ever since then I’ve had my sights set on my DVD collection. Ripping all my DVDs is a harder problem to crack. The sticking point was not the ripping, it was the watching. I have no problem having my music only being accessible from my laptop (or my transferring to my iPod), but that won’t do for movies - I don’t want to mess with my laptop just to watch a movie. I want a solution that just works;
I want to be able to watch a movies by expending less effort than if I were to put a disc in a dvd player. So how do I do it? First of all lets take a look at the elements that constitute the current solution. Firstly there are the shelves full of DVD discs, secondly there’s the DVD player to play them on.
Replacing the DVD player is relatively straight forward. I have a TV-out cable for my iPod Touch which I’m very pleased with. This is the simplest replacement for the DVD player.
Replacing the shelves of DVDs is less straight forward. The first problem is deciding where to store the video. They could be stored on the laptop, but there are problems with this. The laptop only has a 500GB hard drive video files take up a lot of space. Even if the hard drive had nothing except movies on it, it wouldn’t take too long before the hard drive was full. Also, if the movies were stored on the laptop then the laptop would have to be turned for the movies to be accessible. My anal-retentive non-geeky side deems this unacceptable as it would require turning the laptop on whenever I wanted to watch a movie. The alternative to storing them on the laptop is to store them on a network drive. With this in mind I bought a 2TB WD RAID drive and attached it to the Airport Extreme. I set up the drive to act in mirror mode to provide a backup if one of the drive fails (it’s not possible to backup network drives with Time Machine).
The second problem is how to get the movies from the Airport to the iPod. The movies can be transferred via iTunes or they can be access wirelessly via HTTP or a different protocol, such as uPnP (“there’s an app for that”). Obviously transferring movies via iTunes is not an option for the same reasons that storing the movies on the laptop are not an option. That leaves the wireless network option — which raises the question of a server.
The Airport Extreme has only 2 network protocols AFP and SAMBA, neither of which can be accessed via the iPod touch. Game over? No. The solution is to add another network device which can access the Airport Extremes network drives and then make that data available via a protocol that the iPod Touch can work with. The obvious device is another computer. Another computer could easily be setup to act as a server. But there in lies the problem, another computer could easily do a lot more than sever video. Another computer is massive overkill. The wasted energy and computing power of having a computer set up just to act as a web server for one or two clients makes me shudder.
So what else could do the job? The Linksys NSLU2, affectionately known as a slug. The NSLU2 has one LAN port and 2 USB ports. The idea is that you attach USB hard drive to the NSLU2, hook it up to your network and the hard drive become accessible via the network. At least that’s how Linksys expected the device to be used, some geeks had different ideas. NSLU2-Linux is the home of the alternate firmware for NSLU2. By installing alternative firmware the NSLU2 becomes capable of much more. There are a few different firmwares to choice from. After a bit of playing with them I decided to go for the Debian Lenny. This provides a full Linux system with a huge selection of software to install.
1. Install Debian (Lenny)
Martin Michlmayr has detailed instruction for installing Debian on the NSLU2. I used the unofficial image from Slug-Firmware.net and upslug2 for flashing the NSLU2. There isn’t a pre-compiled version of upslug2 for OS X. I used a Ubuntu 9.04 virtual machine. There is an upslug2 package in the pre-configure Ubuntu repository. To install it type the following use the following command:
apt-get install upslug2
Once Lenny is installed you will need access to edit files. This can be done via SSH and edited in the terminal with vi or nano, but Macfusion offers an alternative. Macfusion makes it possible for arbitrary resources to mounted as part of the local file system, (Macfusion is based on FUSE). FTPFS is such a resource. FTPFS clients can connect to an out of the box Lenny installation. If you install Macfusion you will be able to browse the NSLU2 filesystem with Finder and edit files with the app of your choice.
2. Install SAMBA
Once Lenny has installed, login to the NSLU2 via SSH, and install the SAMBA package (we only need the client package):
NSLU1:/# apt-get install smbfs
Create a directory to mount to:
NSLU1:/# mkdir /media/Movies
Mount the shared drive:
NSLU1:/# mount -t smbfs //AIRPORT-IP-ADDRESS/AIRPORT-VOLUME-NAME /media/Movies -o password=AIRPORT-PASSWORD
Check that it worked:
NSLU1:/# ls /media/Movies
The contents of the root directory of you shared drive should be listed.
3. Mount SAMBA drive on boot
fstab is used to determine where to mount devices. By adding an entry for the shared drive the NSLU2 will mount the drive at boot. Open
/etc/fstab and add the following line:
//AIRPORT-IP-ADDRESS/AIRPORT-VOLUME-NAME /media/Movies smbfs password=AIRPORT-PASSWORD 0 0
Make sure there is a blank line at the end of fstab.
Check that the amendment has worked by rebooting:
After the reboot the contents of the network drive should be available in
4. Install a web server (Nginx)
Nginx is a very capable alternative to resource-hungry Apache. Nginx is resource-light thus making it well suited to the NSLU2.
NSLU1:/# apt-get install nginx
Check that nginx has installed by entering accessing your NSLU2 via a browser.
5. Configure Nginx
Organise the web server directory to make it easier to add extra features later:
NSLU1:/# mkdir /var/www/public_html
Create a symlink to the mount point of the shared network drive:
NSLU1:/# ln -s /media/Movies /var/www/public_html/Movies
Next, add the mime types for mpeg 4 movies to the Nginx mime type config file. The file is found at
/etc/nginx/mime.types, open it and add the following lines above the closing curly bracket.
The last step is to configure the Nginx site so that it serves the files from the correct directory and is capable of sending large files. Open the default site config file located at
/etc/nginx/sites-enabled/default (this file is actually a symlink to a file in sites-available).
Change the value of
/var/www/public_html;. Add the following line into the server section:
Finally, restart nginx:
NSLU1:/# /etc/init.d/nginx restart
Access your slug via the browser and you will be able to files shared by the Airport. Movies will be accessible from an iPod Touch or iPhone. If everything went as planned the NSLU2 will mount the network drive and start Nginx when it is turned on.
Install a scripting language (eg PHP)
Installing a server-side scripting language gives you greater control over the pages you server. Scripting languages have to run as a fastCGI server for them to be accessible from nginx. I installed PHP. Here’s some screen shots of the site my NSLU2 servers up:
I did this by setting the autoindex to a script that is located in the root of public_html. The source code is a bit messy so I won’t release it just yet. However, if you’d like the messy version just send me an email.
FireFly is an DAAP server. DAAP is the protocol used by iTunes and AppleTV to access remote media. Unfortunately the version of FireFly in the Lenny repository doesn’t serve video correctly. There are other DAAP servers, but I haven’t investigated them.
Access your NSLU2 from anywhere
Setting up a dynamic DNS would allow you to access your NSLU2 from anywhere on the internet.