How a slug made friends with...

... a penguin, a gnu and a swirl

The NSLU2 (aka slug) uses an ARM processor, specifically the intel IXP420. The arm architecture is fully supported by Debian linux, so naturally I thought that I would take advantage of this.
My reasoning was that if I used one of the other flavours of linux, I would have to compile everything manually, and sort out all of the dependancies... very tedious... with debian however, I can just apt-get most things!

The only difficulty is... how to install it. I mean, you can't just stick a CD in and boot it - there is no CD drive... This has been thought of though:
You can download firmware for the slug from www.slug-firmware.net, which you can either upload through the linksys web interface (provided you've formatted you HDD with the linksys interface; not recommended), or using the Sercomm upload utility (from windows, there are other methods from other OSes, but I used windows).
Once the device boots this firmware, it will run the debian installer... but of course with no screen or keyboard how are you meant to use it? Simple, you use ssh to connect.
You'll know when it's ready for you to connect because once it's got a taste of debian from the installer, it says "feed me more", although some people hear it as "beeep beeep beeep"
The debian installer will download it's packages over the internet, so you better have a decent connection and a router.

Warning: this is where I came unstuck... The debian installer picks up it's IP settings from the sysconf area, meaning that if you've set them manually then it will use your settings, otherwise it will use DHCP.
The problems with my slug were: the IP address wasn't in my subnet (I didn't set it up - second hand slug) and I hadn't set up the DNS or gateway addresses. This meant that I couldn't download any packages so couldn't complete the installer :(
It also meant that I couldn't change the settings at this stage... I had to flash the original Linksys firmware to get a working slug, which I then configured properly and tried again... this time it worked!

The key issue with the installation is that the NSLU2 doesn't have much RAM, so it's best to keep it as light as possible to start with. I recommend partitioning and formatting your disk in advance (with a live CD, like knoppix, if needed), to save the installer doing it, and to select only the minimum packages (install things you need later).
This has another advantage - provided you've created a swap partition, the installer will use it when it runs out of RAM!
The other thing I did to help it along was to de-underclock it (by removing a resistor, very simple!).

2 hours later, debian has installed.

gnu linux penguin debian swirl

See, making friends with a penguin, a gnu and a swirl is that easy.!

... King Harald Gormson

Who is this King Harald Gormson? He was the son of King Gorm the Old. He was also the king of Denmark and Norway in the latter part of the 10th century.
Still not sure? Another clue: He was known as Harald Blåtand, which roughly translates as Harald Blue-tooth (or Harald Dark-tooth, but that doesn't suit our purpose).
He was known for uniting groups of people, in much the same way as the bluetooth standard was intended to do with electronic devices.
Naturally, wikipedia has all the information you could possibly want (and an awful lot more!).

bluetooth

Back to my slug... he has bluetooth inside!
There were a few challenges to this feature, which I'll try to explain:

The software part was half easy and half very awkward!! The adapter was recognised immediately by debian and I installed the bluez-utils package and everything sprung into life. That was the easy part!
The awkward part is that bluetooth support in linux is very primitive! OK, it would be fairly easy to make it connect to the internet via a mobile phone, but that is not needed when I have a 100mbps network connection to my broadband router! I wanted to be able to obex push files from my phone to the slug and vice versa... not as easy as you'd think!
I haven't (yet) finished this... pushing from the slug to phone is workable now, with some scripting and examples courtesy of openobex (particularly the last item on that page), but I haven't got the obex receive working to my liking... I can use the slug to connect to my phone, browse the directory structure and pull files off, but I want to initiate it from my phone!

... media players

My main objective with getting a slug was to use it as a UPnP media server, to stream music and movies to any compatible device. Mainly I was being lazy and wanted my favourite movies without having to actually find the DVD and put it in the machine and all that tedious physical movement!
To this end, I'm very pleased with my current setup! I have got mediatomb installed, monitoring a specific directory (with inotify, none of this windows-esq polling!) and sharing all of my media.
It's extremely customisable, for example it reads all the id3 metadata from my mp3 collection, and presents a virtual structure based on it. This means I can select my music by genre, artist, album, year, etc!

All while dancing

That's right, my slug dances... or it runs, not sure which (neither are very slug like!)... it runs samba for windows file sharing.
I know that when linksys ship it, it does this, but a fresh minimal debian install doesn't, so I had to install and configure it... thankfully that was fairly trivial: apt-get install samba
This means that I have an easy way to add my media to the slug (also note the inotify support in mediatomb), but also gives me somewhere to backup to (critical because I've seen A LOT of hard disk failures, and how much people then realise the value of a backup!).

And everything else...

Hardware hacks

I have done 3 hardware hacks so far: the bluetooth adapter mentioned above, de-underclocking as mentioned above and...
I've replaced the power LED with a 5mm rainbow coloured LED! This is purely cosmetic, and a direct replacement... the rainbow LED is a lot brighter, so the standard one must be quite inefficient.
If you haven't heard of a rainbow LED before, they're like normal LEDs but constantly change colour - they have 3 LEDs in one package and switch between individual colours and combinations of them - every combination possible in fact.
Not only do they look good in a slug, but they also make great, cheap christmas decorations! I got mine from ebay user goodwillsales, www.goodwillsales.com

Other services/software

I have also installed a web server, lighttpd with php support (via fastcgi)...
I was using this while I was building this page, but my ADSL isn't always up so I've put this page in a datacentre - you can try the slug hosted version at home.peter-woods.co.uk, although the disk is probably spun down so it may take a while for the initial access (while the disk spins up); also this page is mainly for my reference in case I ever have to rebuild my slug and I realised that if I'm rebuilding my slug, it's inbuild webserver won't be available!
Note that by default php will scan for old temporary files (and cron will log this) twice an hour... edit /etc/cron.d/php5 to change this to allow the disk to spin down.

A VPN server, so I can log in remotely... it's not 100% reliable but if I keep trying it eventually gets there; because it's just for me I'm not too bothered.

An iptables firewall - a lot more hassle than I expected with recent releases of debian - there doesn't seem to be any consensus on where to store rules or how/when to load them.
I chose to store my rules in a new file within /etc/, and load the rules with iptables-restore < /etc/iptables-rules from within the network's if-up.d directory. This works for me, but you may want to choose something different.

rtorrent to download bittorrent files. No, bittorrent isn't illegal - some people use it for illegal purposes, but some of us actually believe it's a good distribution protocol for things like linux iso files.
By running on my slug, I can leave it on over night and other times when I don't want a full PC running, and it's low power so it's green as well (about 10W all in vs. approx 300W for a PC).
I tried other clients, but found rtorrent the easiest, fastest and kindest - my load average sits around 0.4 with it running although it goes up to around 2.6 when computing the hash to verify the download.

Power button: The default behaviour within debian (at least on the slug hardware) when the power button is pushed is to initiate a restart. I wanted it to initiate a shutdown so that, should I want to, I can turn the slug off in a civil manner whilst in front of it, rather than having to do it remotely. If I want to restart it and I'm in front of it, I can simply push the button again!
Thankfully, this is a fairly simple thing to fix - the power button effectively sends the os a ctrl-alt-delete signal, so all that is required is to edit /etc/inittab and replace the /sbin/shutdown -t1 -a -r now with /sbin/shutdown -t1 -a -h now.
I chose to make it slightly more complicated: I wanted to retain a linksys-style beep when the button is pushed (although custom, naturally), so my inittab now says ca:12345:ctrlaltdel:/sbin/powerbutton... And I've created a shell script in /sbin/powerbutton containing:
#!/bin/bash
echo $'\a' > /dev/tty1
sleep .3
echo $'\a' > /dev/tty1
shutdown -t1 now
which translates as: "beep, wait 300ms, beep, start shutdown". Note that I omitted the -a from the standard shutdown command, because the power button doesn't have a login so checking permissions is pointless!
Obviously, this file needs permissions of at most 755 because it will be run as root, so we don't want anyone else to be able to modify it. Not that I intend to allow unprivileged people write access to arbitrary files on my slug anyway, but just in case!

And another beep: I wanted confirmation when the slug has finished booting. Since I can't tell by looking at the screen (no screen hence no login prompt), I thought I'd use the on-board buzzer.
This was extremely easy to accomplish: crontab -e, then add in: @reboot echo $'\a' > /dev/tty1

Silencing my slug

I spent a lot of time getting my hard disk to spin down when not in use, to conserve power, noise and heat as well as extend the disk's life. I selected my external hard disk to be one that automatically spun itself down when not in use, but had a challenge getting it to not be in use!
First thing: mount the filesystem with the noatime option, meaning that if a file is cached in ram then it doesn't have to wake the disk to write the last accessed time for that file - this is done easily in /etc/fstab (search online for "noatime" for examples).
Next priority: have syslog cache changes in memory, only writing to disk when needed: I've put a hyphen before each of the files in syslog.conf (except the critical error levels).
Next thing I found was that exim was running it's queue runner fairly regularly. I don't use mail on my slug at all, so apt-get remove exim4 and a bit of tidying up and that problem was solved.
I then found that syslog will write "-- MARK --" to the log every 20 minutes if it hasn't written something in that time... very annoying because it takes the disk 10 minutes to spin down; thankfully this was solved by putting "-m 0" in the relevant part of /etc/default/syslogd.conf.
Then I found that every hour cron was running it's hourly jobs and logging as such, which would be fine if I had anything that I wanted done that often, which I don't... so I disabled cron.hourly in /etc/crontab
Next challenge: I found that with samba running it would record the netbios names and addresses in it's /var/cache/samba/browse.dat file... which I figure is fairly useful for samba, but also not needed to be kept through a reboot, so... I turned /var/cache/samba into a small ramfs partition, mounted when samba starts (from the init script: /etc/init.d/samba)... this way, samba can still do it's thing without bothering the disk! I have also got it umounted from the init script, should I ever stop the samba service!
To achieve this, directly after the start) in /etc/init.d/samba, I entered: rm -rf /var/cache/samba/*
mount -t ramfs none /var/cache/samba -o maxsize=512
The maxsize=512 specifies that the ramdisk will never grow to more than 512k, although being a ramfs it will use the minimum required ram anyway (critical on the slug)
For completeness, at the end of the stop) section (just before the ;;), I added a line umount /var/cache/samba.

Also see above for why installing PHP kept spinning the disk up (hint: /etc/cron.d/php5
That was everything I needed to do on my system, but to find out what is writing files, or specifically, which files are changed, I would leave a ssh connection open, wait 10 minutes (or until the disk spun up again) and run find / -cmin -10 -prune|grep -v /proc/ |grep -v /sys/. In english, that means "find all files on this system which have changed within the last 10 minutes, excluding /proc/ and /sys/ (because they aren't real files and are constantly changing but don't affect the disk)". OK, there are other, better?, ways to do this, but that worked for me.

The future

My future plans for my slug are:


I apologise to all the people who's phraseology I've blatantly pilfered for this page, please view it as a compliment that I felt they were worth repeating!
This applies particularly to Kapil Hari Paranjape of linuxgazette, whose article was probably the most helpful I found in getting my slug running.
Just remember: copying from one person is plagiarism, copying from many is research.


Disclaimer: This page is intended mainly to help my memory, in case I should ever need to do all this again. It is also a small showcase of what can be achieved with a humble NSLU2.
I in no way encourage anyone else to open their devices, let alone wield a soldering iron to them. If you are going to flash non-standard (i.e. third party) firmware then you better know what you're doing first.
Always have a fallback plan in case a flash goes wrong, in the case of the NSLU2, that means knowing how to get it into upgrade mode and reflash the stock firmware, and also being able to telnet into redboot to erase the sysconf area.
If you don't know what that means, don't touch it. If you mess up the redboot area, you'll need to make a serial lead and connect to the jtag interface, but this very much invalidates your warranty and could easily lead to a completely dead slug.
You have been warned.


If you have any comments, questions or suggestions, please email me: