loading

Give your Cisco Linksys NSLU2 some muscle. (part 1)

The NSLU2 is sort of a NAS (network addressed storage) where you have to use your own drives. Great for backups and whatever, but it can do so much more. There is alternative firmware such as Openwrt that can be installed on it to allow it to act as a router, You can find other firmware that will even allow the unit to act as a PBX. Those are specially distributions. We wanted to go all the way and install a full Linux distribution on it. Then the sky is the limit of what you can do with it. all of this only takes a few watts compared to the traditional server that uses hundreds of watts. True energy saving.

The NSLU2 has been named the "slug" for it's slow speed. Despite that it can do so many wonderful things. Another shortcoming is that you will not be able to use a monitor out of the box to watch it. You will have to use another computer or terminal to access it. Ironically I had an old text based unix terminal to work with it. That terminal has gone to a better place. Have actually converted the NSLU2 to Linux before but returned it to the original firmware when it looked like it might fizzle out. Fortunately the Arm processors (CPU) are now all the rage. I thought that I might see a zillion of the units on Ebay. Nope there were none. So that is a testament to how useful the unit is.

Note: if you have any drives connected or that have been connected to your NSLU2, make sure you can access them from another computer before you even start thinking about doing this project. If not you could lose valuable data!!!! Try this project at your own risk, as I will not be responsible for any or all issues. Get a linux professional if you feel uncomfortable with this project.

 
Remove these adsRemove these ads by Signing Up

Step 1: What's needed:

Picture of What's needed:

Hardware
-------------------
1 - nslu2
1 - Hard drive or thumb drive, (I used an eight gigabyte thumb drive for this project.) You can add more drives later!
1 - sturdy paperclip
1 - network connection.
1 - Debian based computer or a virtual machine running Debian, Ubuntu or the like.) that is networkable.

Software:
-------------------
Pre-made file system:
http://people.debian.org/~tbm/nslu2/squeeze/base.tar.bz2
http://people.debian.org/~tbm/nslu2/squeeze/base.tar.bz2.asc

Redboot firmware image:
http://www.cyrius.com/debian/nslu2/files/armel/sda2-2.6.32-5

Other software:
http://sourceforge.net/projects/webadmin/files/webmin/1.590/webmin-1.590.tar.gz
ptelnet.prc for you palm handheld
http://ptelnet.en.softonic.com/palm/download

Step 2: Getting the software.

Picture of Getting the software.

Your computer installation:
--------------------------------
$ sudo apt-get install upslug2

$ wget http://people.debian.org/~tbm/nslu2/squeeze/base.tar.bz2
(about 150 megabytes for the above file)

$ wget http://people.debian.org/~tbm/nslu2/squeeze/base.tar.bz2.asc

Verify checksums:
$ sudo gpg --keyserver subkeys.pgp.net --recv-key 68FD549F
$ sudo gpg --verify base.tar.bz2.asc base.tar.bz2

Step 3: Preparing your drive.

Picture of Preparing your drive.
Screenshot from 2012-07-12 11:43:23.png

Be careful: If possible do this on a new usb drive. Get a professional to help if you are unsure.

Find out what is connected to your computer:

$ lsusb.

You should see the thumb drive. In this case a Kingston.
Bus 001 Device 003: ID 0951:1603 Kingston Technology DataTraveler 1GB/2GB Pen Drive

Now we need to see what partitions are available

$ sudo fdisk -l

Notice which channel it is on: (sdb)

Disk /dev/sdb: 8027 MB, 8027897856 bytes
14 heads, 22 sectors/track, 50907 cylinders, total 15679488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x04030201

Device Boot Start End Blocks Id System
/dev/sdb1 2232 15679487 7838628 b W95 FAT32

Notice the 8027 MB is the same size as our 8G thumb drive. If it is any other size say the size of your hard disk, you need to exit the program and start over. Linux can not use that partition per se so we will have to delete that partition and create two new partitions.

$ sudo fdisk /dev/sdb
eddie@oedt01:~$ sudo fdisk /dev/sdb

Command (m for help): ?
?: unknown command
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help):

Press d for delete.
Command (m for help): d
Selected partition 1

Press p to see that there are now no partitions.
Device Boot Start End Blocks Id System

Now you want to add two partitions. First a swap drive and then the operating system drive. On MSWindows the swap file is on the
drive. With Linux they are on separate drives.

Press n, press p for a primary partition, Use the default first sector, and lastly use +512M for the end or partition size.

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-15679487, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-15679487, default 15679487): +512M

Command (m for help):

press p (and enter) to see the new partition.

Device Boot Start End Blocks Id System
/dev/sdb1 2048 1050623 524288 83 Linux

So far so good. Now we said we were going to use this as a swap partition. So we need to change the partition type.

Press t (and return)
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sdb: 8027 MB, 8027897856 bytes
14 heads, 22 sectors/track, 50907 cylinders, total 15679488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x04030201

Device Boot Start End Blocks Id System
/dev/sdb1 2048 1050623 524288 82 Linux swap / Solaris

Now we need to make our operating system partition. so press n again and use all the defaults. Normally you would make several partitions, but for the sake of simplicity, we will only have two.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (1-4, default 2):
Using default value 2
First sector (1050624-15679487, default 1050624):
Using default value 1050624
Last sector, +sectors or +size{K,M,G} (1050624-15679487, default 15679487):
Using default value 15679487

Command (m for help): p

Disk /dev/sdb: 8027 MB, 8027897856 bytes
14 heads, 22 sectors/track, 50907 cylinders, total 15679488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x04030201

Device Boot Start End Blocks Id System
/dev/sdb1 2048 1050623 524288 82 Linux swap / Solaris
/dev/sdb2 1050624 15679487 7314432 83 Linux

Command (m for help):

Aah, we have the partitions done. Now we need to save create what we have done.

Press w (and return)
The program should take a second or two and then exit

Note: you might have to remove and reinstall the thumndrive for the system to recognize the new partitions.

Now we need to format the drives.

$ sudo mkswap /dev/sdb1
$ sudo mkfs.ext3 /dev/sdb2

Step 4: Preparing the file system.

Picture of Preparing the file system.

Actually we have it pretty easy as we are ready have one. I remember to do the Debian linux install and it took forever to get all the files to be set up. You get a short cut.

We need to mount the drive

First create a mount point if you do not have one.
eddie@oedt01:~$ sudo mkdir /media/usb

Mount the drive's linux partition. Remember we set up the second partition for the os.
eddie@oedt01:~$ sudo mount /dev/sdb2 /media/usb

Change to the mounted partition

eddie@oedt01:~$ cd /media/usb
eddie@oedt01:/media/usb$

Now let's expand the tar archive to install all the files.
Note zjvf s/b xjvf
$ sudo tar xjvf ~/base.tar.bz2

It will take a while. Then let's see the new partition file list

$ ls

eddie@oedt01:/media/usb$ ls
bin dev home lost+found mnt proc sbin srv tmp var
boot etc lib media opt root selinux sys usr
eddie@oedt01:/media/usb$

Almost there! Umount the drive and remove.

Step 5: Adding the firmware, first boot and first login!

Picture of Adding the firmware, first boot and first login!
You will need to install upslug2 for installing the firmware on your pc (or virtual machine).

$ sudo apt-get install upslug2

change to the directory where you downloaded the firmware.
$ cd Downloads

Type in, but do not press enter yet!

eddie@oedt01:~/Downloads$ sudo upslug2 -i sda2-2.6.32-5

Now you have to write the Debian firmware image to your NSLU2. You can do this with upslug2, a tool for Linux and Unix which can be used to write a firmware image to the NSLU2 via the network (the software is packaged for Debian).

First, you have to put your NSLU2 in upgrade mode:

Disconnect any disks and/or devices from the USB ports.
Power off the NSLU2
Press and hold the reset button (accessible through the small hole on the back just above the power input).
Press and release the power button to power on the NSLU2.
Wait for 10 seconds watching the ready/status LED. After 10 seconds it will change from amber to red (on older NSLU2) or dark orange (on newer machines). Immediately release the reset button.
the NSLU2 ready/status LED will flash alternately dark orange and green (there is a 1 second delay before the first green). The NSLU2 is now in upgrade mode.

Press enter.

Connect your hard drive immediately when upslug2 is done and then your device will reboot. The first time you boot, the system will probably check your drives. Please wait patiently until this is over. When the drive check is done, your NSLU2 will reboot again and directly boot into your new Debian system.
The system includes support for the Intel IXP4xx network chip (including the proprietary microcode that is required for operation) and will try to obtain an IP address via DHCP on eth0. SSH is installed and remote root logins are allowed. The password is root.

eddie@oedt01:~/.ssh$ ssh root@192.168.1.120
root@192.168.1.120's password:
Linux oesrvr3 2.6.32-5-ixp4xx #1 Mon Oct 3 12:19:10 UTC 2011 armv5tel

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Jul 11 17:01:27 2012 from oedt01.homelinux.com
foobar:~#

Step 6: Housekeeping.

Picture of Housekeeping.
Since the file system is from another computer, you will need to do some cleanup.

Change the root password

# passwd root


You want to add at least one user as it is not good to be logged in as the administrator (aka root) for security purposes.

# adduser username

You need to recreate the system ssh key so it will be your own.

# rm /etc/ssh/ssh_host*
# dpkg-reconfigure openssh-server

You need to update where software to be installed is from.

# vim /etc/apt/sources.list

old:
deb http://ftp.uk.debian.org/debian/ squeeze main

deb http://security.debian.org/ squeeze/updates main

new:
deb http://ftp.us.debian.org/debian/ squeeze main

deb http://security.debian.org/ squeeze/updates main

Get the correct time as the NSLU2 does not have a clock. (for the first time, you'll probably have to setup the clock manually using the date command).

# ntpdate pool.ntp.org

Update the system software: (this will take a while)

# apt-get update
# apt-get upgrade
# apt-get dist-upgrade

Correct the time zone:

# dpkg-reconfigure tzdata

Correct the locale:

# dpkg-reconfigure locales

Use your own host name

# vim /etc/hosts (use your own new name.

oldname: foobar
new name: oesrvr3

# vim /etc/hosts
Again change the old name to the new name same as the previous step.

oesrvr3:~# cat /etc/hostname
oesrvr3
oesrvr3:~# cat /etc/hosts
127.0.0.1    localhost
127.0.1.1    oesrvr3


# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
oesrvr3:~#

Add one more command so we do not have to log in as root

# apt-get update
# apt-get install sudo

Edit the sudoers fille and add the username to the list under root:

# vim /etc/sudoers
# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL
Newusername     ALL=(ALL) ALL

# Allow members of group sudo to execute any command
# (Note that later entries override this, so you might need to move
# it further down)
%sudo ALL=(ALL) ALL

Shut down the system and take a rest with:

# poweroff

Step 7: Preparation for part 2.

Picture of Preparation for part 2.
Once you have cranked up the NSLU2 and logged in, you will want to add a couple of pieces of software.

$ sudo apt-get install build-essential boa screen

Build-essential is the C compiler to generate the programs we will use.  Boa is a lightweight Web server that supports cgi that we need for part two. Screen allows us to detach from the unit when an install will take a while.

For more information:
C
See K&R

Boa:
$ man boa

Screen
$ man screen

Do not forget to update your router to include the nslu2.

Stay tuned for part 2!!

Note: http://www.cyrius.com/debian/nslu2/troubleshooting.html for troubleshooting.

Step 8: Extra: Music server.

Picture of Extra: Music server.
Screenshot from 2012-07-12 15:57:52.png
Till we get to the home automation part, let use use your new server for music repository for your networked entertainment devices. We like daap compatible devices. Firefly aka mt-daapd is a favorite program of ours. it actually has two versions as the program was forked or two separate developers started working on it. The newer version is more powerful, but the older version has a web interface.

eddie@oesrvr3:~/$ sudo apt-cache search mt-daapd
forked-daapd - media server with support for RSP, DAAP, DACP and AirTunes
mt-daapd - iTunes-compatible DAAP server

Install the software.
eddie@oesrvr3:~/$ sudo apt-get install mt-daapd

Edit the configuration file source directory and the passwords. (it is self explanatory).
eddie@oesrvr3:~/$ sudo vim /etc/mt-daapd.conf

Copy your music to the directory.

$ sudo cp srcdir/* destdir/.

Then you may want to restart it to reflect changes.
eddie@oesrvr3:~/$ sudo service mt-daapd restart

Go to your music player and have fun. We use Rhythmbox, but any daap compatible device or a unit that has itunes should work. 

Note: Song names are faked so that the instructable sounds more interesting.

Step 9: Webmin to show off your NSLU2

Picture of Webmin to show off your NSLU2
Screenshot from 2012-07-12 05:37:29.png
Was going to wait for the second instructable, but you can use it now.  At this point you can really only access the NSLU2 only from the command line. Now you will be able to access the NSLU2 with a more powerful interface than the original web page.  So now you need to get the Webmin software.

$ wget http://sourceforge.net/projects/webadmin/files/webmin/1.590/webmin-1.590.tar.gz

lets go to a directory where the install will be out of the home directory.

$ cd /opt

You want to expand the archive to a usable form.

eddie@oesrvr3:/opt$  tar xzvf ~/src/webmin-1.590.tar.gz

Change into the working webmin directory just created.

$ cd webmin-1.590

Run the install program

eddie@oesrvr3:/opt/webmin-1.590$ sudo ./setup.sh

This will take a while and you may have to answer some questions. I think we just used all the default.

To access the page, go to system with a web browser and point the url:10000  to the NSLU2. Now you can show off you little unit. to everyone.

Step 10: Using a serial terminal.

Picture of Using a serial terminal.
Screenshot from 2012-07-14 05:30:24.png
PICT0173.JPG
Luckily, the Debian installation has the drivers for the typical usb to serial cable. We will be using an old Palm IIIxe as our terminal, but any old handhelp, regular computer, or even an old unix terminal with rs232 port should work. I am also assuming you know how to connect all the cabling.

For the palm, you need to go to  http://ptelnet.en.softonic.com/palm/download and download ptelnet.zip. After extracting the file, you will need to get it to your palm. Assuming you have already installed software such as jpilot to sync data with your palm and that works, you will need to install one more piece of software on your computer.

$ unzip ptelnet.zip

$ sudo apt-get install pilot-xfer

Then you can use pilot-xfer to transfter the ptelnet to your palm. Your pc may use another port besides /dev/ttyUSB0 so use what ever jpilot uses.

$ sudo pilot-xfer -p /dev/ttyUSB0 -i ptelnet.prc

On your palm, You will want to set up ptelnet to use a serial connection instead of telnet. Of course all the port settings should be the same on both devices. 

To test the connection, on the NSLU2 from the pc using ssh to get into the NSLU2, use:

$ sudo /sbin/getty -h -L ttyUSB0 9600 vt100

If you get an error you may need to also (and the run the getty command again):

$ sudo chmod 666 /dev/ttyUSB0

On your palm, click on the ptelnet and make sure the on box is hi-lighted, If everthing is setup right, a login prompt should appear on your Palm. You can login and do your thing. No more need for the ssh session from the pc. (after you have modified inittab)

To make the serial port login permanent:

You need to edit /etc/inittab

$ sudo vim /etc/inittab

Insert into /etc/inittab before the line starting with 'l3:3:wait...'
T0:23:respawn:/sbin/getty -h -L ttyUSB0 9600 vt100

Save your edit and exit vim. Now you can use any rs232 device  at 9600 baud to access your NSLU2.

Note: if there are no ports left for the usb-serial cable, you will need a usb hub to connect all the devices. A hub that has it's own power source will work best as not to overtax the NSLU2. If you use an rs232 device, you may also need a null modem cable or adapter to connect to the NSLU2.

Note 2: You could easily use this same method with the Raspberry Pi running Debian.


Note: replaced the Palm III with an HP Jornada 620lx. Much better now.

Step 11: Temperature sensing.

Picture of Temperature sensing.
SUNP0034.JPG
In progress.

http://martybugs.net/electronics/tempsensor/hardware.cgi

$ sudo apt-get digitemp

Once inststalled You can use

$ sudo digitemp_DS9097u -s /dev/ttyUSB0 -w

"

Now, to read the temperatures. You'll want the digitemp package, which is pre-packaged in Debian and probably most other Linux distributions. Once it's installed, you'll need to know what program to use. Several are available for different DS masters, but in the LinkUSBi's case, you'll want digitemp_DS9097U. To begin, verify the bus is working correctly by walking it:

# digitemp_DS9097U -w -s /dev/ttyUSB0
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
...
Devices on the Main LAN
28D1483C0200002F : DS18B20 Temperature Sensor
28E9393C020000C3 : DS18B20 Temperature Sensor
010EBED512000046 : DS2401/DS1990A Serial Number iButton

This shows the two DS18B20 temperature sensors (T-Sense probes), as well as the DS2401 embedded in my LinkUSBi. (The DS2401 literally does nothing but return a serial number. Still, as mentioned before it's useful to have to verify the bus is working correctly even if no other devices are plugged into it.)

Next you'll want to create a config file. I chose to store it in /etc/digitemp.conf.

# digitemp_DS9097U -i -c /etc/digitemp.conf -s /dev/ttyUSB0
DigiTemp v3.5.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
Turning off all DS2409 Couplers
...
Searching the 1-Wire LAN
28D1483C0200002F : DS18B20 Temperature Sensor
28E9393C020000C3 : DS18B20 Temperature Sensor
ROM #0 : 28D1483C0200002F
ROM #1 : 28E9393C020000C3
Wrote /etc/digitemp.conf

You will be left with a file called /etc/digitemp.conf that looks something like this:

TTY /dev/ttyUSB0
READ_TIME 1000
LOG_TYPE 1
LOG_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F"
CNT_FORMAT "%b %d %H:%M:%S Sensor %s #%n %C"
HUM_FORMAT "%b %d %H:%M:%S Sensor %s C: %.2C F: %.2F H: %h%%"
SENSORS 2
ROM 0 0x28 0xD1 0x48 0x3C 0x02 0x00 0x00 0x2F 
ROM 1 0x28 0xE9 0x39 0x3C 0x02 0x00 0x00 0xC3 

You can rearrange the ROM mappings as you'd like. 1-Wire refers to devices by their 64-bit IDs; the numeric mappings are for digitemp's benefit. In my case, 28D1483C0200002F is the probe I'd like to use, so #0 is fine.

Now, let's see what's being returned:

# digitemp_DS9097U -q -c /etc/digitemp.conf -a
Mar 04 22:22:43 Sensor 0 C: 25.38 F: 77.67
Mar 04 22:22:44 Sensor 1 C: 27.56 F: 81.61

Great, works fine. We'll soon need the data in a machine-readable format, so here's how to do that:

# digitemp_DS9097U -q -c /etc/digitemp.conf -o 3 -a
0	77.79	81.50
"