Turning a Linksys NSLU2
into a generic Linux box:
I have assembled most of this information from
the helpful pages at http://www.nslu2-linux.org
in combination with some additional insights from my own experiences with
Linux.
Throughout this article, I refer to the Linksys
NSLU2 as a "Slug" which is how it is affectionately refered to by
those who are familiar with this wonderful piece of equipment.
I begin this "how-to" guide assuming
that you have a "bricked" Slug. This means that the Slug will not
boot (probably because of a failed re-flashing of the firmware). The reason
it's useful to start here is that the "bricked" state is the lowest
common denominator and you will always be able to return to the first step no
matter how badly you screw up your Slug. Those who have a perfectly functioning
(i.e. straight-from-the-factory) Slug can just use the built-in web-based
firmware upgrade utility to flash the OpenSlug firmware and then skip to Step
2. Starting at Step 1 with a perfectly working Slug is not a problem either.
One thing to keep in mind is that there are many
ways to skin a cat... therefore, you may find easier ways to do what I describe
below. You may also find that you can skip some of the steps below… however I
developed this recipe to be comprehensive.
Step 1: Clearing the Slug and Installing
the OpenSlug firmware
In order to fully reset the Slug you will need
the following tools:
·
A
Windows PC
·
A
Network hub or switch
·
The Sercomm
Utility
·
The OpenSlug firmware (look in the SlugOS
link)
·
A
Windows SSH Client (another
good one is here)
Now we're ready to get started...
a) Plug the Slug and Windows PC into the hub or
switch
b) Make sure that there is nothing plugged into
the USB ports of the Slug
c) Set the PC to a fixed IP of 192.168.0.100
with a mask of 255.255.255.0
d) Put the slug into RedBoot mode
1. Open two Windows command prompts
2. In the first cmd prompt type ping -t -w 1
192.168.0.1
<return>
3. In the second cmd prompt type telnet
192.168.0.1 9000
4. Turn on the Slug and as soon as you can see
pings coming back in the first command prompt, hit return on the line with the
telnet prompt
5. Immediately hit CTRL-C
6. You should now be at a command prompt. If you
missed it, you will have to unplug the Slug, reboot and try again.
e) Clear the configuration area and install the
OpenSlug firmware
1. Type fis erase -f 0x50040000 -l
0x20000
2. Type upgrade
3. The Ready/Status light should now be flashing
red
4. Use the Sercomm Utility to install a new
firmware
5. The SLUG will automatically reboot at the end
of the upgrade
Step 2: Connecting to the Slug and
Configuring the Basic Settings
a) Connect to the Slug for the first time after
flashing the new firmware. Note that the newest versions of the firmware automatically enable
DHCP which means that the Slug may just get an IP within your network's normal address range.
If this is the case, then you only need to SSH into the Slug and jumpe to step 3 (turnup init).
1. Set PC to Fixed IP of 192.168.1.100
with a mask of 255.255.255.0
Note
that this IP address is different than the one in Step 1c.
2. Using your SSH client, connect to 192.168.1.77
Username: root
Password:
opeNSLUg
3. Once logged in, type turnup init
Answer
the basic questions. You probably want to enable DHCP at this point if you have
a DHCP server (which will automatically give the Slug an IP address on your
network). The ideal is if you can configure your DHCP server to always give it
the same IP address.
4. Reboot the Slug (type reboot)
and login again with the username root
. Keep in mind that if you changed the
password, it will no longer be opeNSLUg.
b) Your Slug should now be configured to boot
normally on your network using DHCP. At this point you can reset your PC
Network settings back to normal (i.e. DHCP)
Step 3: Configuring the Disk (or USB
Flash Drive)
a) SSH into the Slug as the root
user. Keep in mind that the IP
address and Password will be what you have configured it to in Step 2.
b) Insert a USB hard-drive (or USB Flash Drive)
into the bottom USB port of the Slug (the port labeled Disk 1)
c) Figure out the device name of your Drive
1. Type mount
2. Look for a device /dev/sda1 or something
similar (it might be /dev/sdb1, for example)
3. Note: This will tell you what your device is
called (and it may vary depending on what type of device is plugged in (i.e. a
USB Flash Drive or a CF Flash Card plugged into a USB card reader)
4. In all future steps, I will assume the device
is /dev/sda but substitute /dev/sdb or whatever else according to your
situation.
d) umount /dev/sda1
(and /dev/sda2 and /dev/sda3 if they
exist)
e) NOTE: SUBSEQUENT STEPS WILL WIPE ALL DATA
f) Partition the disk
1.fdisk /dev/sda
2. p
to get a list of the current
partitions
3. d
to delete the partitions (you want to
delete all of them)
4. Create 3 new paritions
i)
n
to create a new parition
ii)
p
to make it the primary partition
iii)
1
(then 2
then 3
) to make partitions 1-3 respectively
iv)
Enter the start and end cylinders for each partition respectively
As
a rule of thumb, you want to make the first partition the
largest
and then leave about 128MB each in the 2nd and 3rd
partition. Use a calculator to pro-rate the number of cylinders based on the
known drive
size. (e.g. if you have a 2GB disk with 246 cylinders, then make the first
partition about 88% of the total number of cylinders (216) and split the
remainder
with the other partitions).
5. Write the partition table with the w
command, q
to quit and then reboot
g) Format the partitions
1. SSH back into the SLUG if you haven’t done so
2. Unmount all the /dev/sda devices
i)
umount
/dev/sda1
ii)
Use the mount command to check if /dev/sda2 and 3 are mounted
iii)
Unmount them if they are mounted (umount /dev/sda2
and 3
)
3. mkfs.ext3 /dev/sda1
4. mkswap /dev/sda2
5. mkfs.ext3 /dev/sda3
6. Reboot and SSH back in
h) Copy the root file system to the drive
1. umount
all of the /dev/sda partitions like
in step 3g.2
2. turnup disk -i /dev/sda1 -t
ext3
3. If this takes more than a minute or so, then
check that you have unmounted all the /dev/sda partitions. You may need to
reformat them.
4. Reboot and SSH back in
i) Clean up
1. Activate the swap parition: swapon /dev/sda2
i)
Note, this may fail
2. Edit /etc/fstab
i)
vi
/etc/fstab
ii)
i
(to enter interactive mode)
iii)
Scroll to the bottom and add the following:
/dev/sda3 /home
ext3 defaults 1 1
/dev/sda2 /swap swap defaults 0 0
iv)
CTR-[
to enter command mode
v)
ZZ
to save and exit (must be capital
letter Zs)
3. Reboot and SSH back in
4. Type mount
and it should show that /dev/sda3 is
on /home and /dev/sda1 is on /
Step 4: Enable Optware Packages
a) Bootstrap the Optware Packages
1. Note: Each of the following steps is a single
command line (don’t hit enter until the end of the line)
2. su
3. wget http://ipkg.nslu2-linux.org/feeds/optware/slugosbe/cross/unstable/ipkg-opt_0.99.163-9_armeb.ipk
4. tar -xOvzf ipkg-opt_*_armeb.ipk
./data.tar.gz | tar -C / -xzvf –
5. sed -i -e
's|/stable|/unstable|' /opt/etc/ipkg.conf
6. /opt/bin/ipkg update
b) Note that there are two independent ipkg
commands and two sets of packages:
1. /usr/bin/ipkg
2. /opt/bin/ipkg-opt
c) It's important to make sure you specify the
command clearly (explicitly with full path if you do not have the PATH
including /opt/bin).
d) Keep in mind the following:
1. Make sure your environmental variables, like
PATH, are updated to include your /opt directories, like /opt/bin.
2. Otherwise, /opt installed utils & shared
libraries may not be found.
3. Always check to see if a package is available
via the ipkg command first, before installing it using ipkg-opt.
Step 5: Install some good basic tools
a) Nano – a great text editor: ipkg install
nano
1. Type nano
<filename> to view/edit a file
b) Vsftpd – a great FTP server: ipkg install
vsftpd
1. Check http://vsftpd.beasts.org/vsftpd_conf.html
for help
2. Basic settings are in /etc/vsftpd.conf
c) CoreUtils – some core utilities: ipkg install
coreutils
d) PHP-Apache – a great Web server: /opt/bin/ipkg-opt install
php-apache
1. Run apache with /opt/sbin/httpd
2. Restart apache with /opt/sbin/httpd
–k restart
3. To get PHP to work, you need to copy the text
from /opt/etc/apache2/conf.d/php.conf
into
/opt/etc/apache2/httpd.conf
4. You can test PHP by creating a file called test.php
with the following contents:
<?php
phpinfo(); ?>
and surf to http://<slugip>/test.php
e) ipkg list
and ipkg-opt list
will display the available packages
1. Packages installed with ipkg-opt will go in
the /opt/ directory
Step 6: Some initial comments to get you
started
a) You can add new users with adduser
<username>
b) You probably should change the owner of
Apache’s web directory
1. Type chown –R
<username> /opt/share/www
c) /sbin
is where installed packages go
d) /etc
is where config files go
e) /var
is where log files go
f) For Optware packages, check in /opt/sbin
, /opt/etc
and /opt/var
Step 7: Success!
You now have a general purpose Linux
“computer” that can run any of the hundreds of packages out there. These include
Asterisk (PABX), Samba, various media servers, etc.