Introduction

With the latest DD-WRT (v23 SP2 and v24 SP1), it is possible to install Optware packages from NSLU2-Linux project. This port of Optware is tailored for DD-WRT and extends the router to full feature linux if enough storage (jffs, SD/MMC Card, USB) is provided for packages.

The main feature of this package is that it installs all required files under /opt with 1000 ported applications. With buildroot toolchain, system library independence is also added. This means that packages now depend on /opt/lib/uClibc.so and dynamic loader also in /opt/lib with separate /opt/etc/ld-opt.so.conf for custom .so cache.
Applications are built with wchar and locale support which makes uClibc library somewhat greater than other uClibc packages, but still far smaller than glibc based aplications.

Basic preparation of /jffs is required (enable, clean). On WRT54GS there is room for some aplications. SD card (/mmc) may give enough space for many applications. For testing purposes also smbmount can be used. If a non /jffs filesystem is available, it is recommended to unmount /jffs and then mount eg. mmc in place of /jffs.

Creating drive space for your Optware packages

Prerequisite for optware is writable /opt partition/drivespace. Required size depends on packages installed. Three options to create writable partition/drivespace is listed here. A fourth option could be the SDmod.

Option A: Preparing /jffs for /opt

Depending on the dd-wrt firmware version you choose, you may have enough space on the /jffs drive.
Example: WRT54GS with 8MB flash and DD-WRT v23SP2 Mini leaves 5248k blocks for /jffs which can be binded to /opt.

Use command df to keep track of how much space is left on your /jffs and /opt "drives"

Option B: Preparing USB drive for /opt

Read USB storage wiki for guide to enable, partition, format and mount a USB drive. Note that /opt must be mounted on an ext2/3 filesystem for linking to work which is required by the Optware installer.

Option C: Partition-in-a-file on CIFS for /opt

Installing ipkg-opt and uclibc-opt

First we will install uClibc library required by all packages and better ipkg-opt packager.
Recommended way for installing basic two packages is with installation script that will also check for
possible network problems and /opt directory availability. To install (or reinstall) issue the following
command:

/opt backup

Now we have prepared /opt for adding more packages. We can also create backup of the whole /opt tree
in case of router upgrade, to give preinstalled /opt to a friend or just safety backup. We will create
such backup with

~ # tar czf /tmp/opt-backup.tar.gz /opt

Destination for /tmp/opt-backup.tar.gz should be large enough! Beware that /tmp is RAM. Destination should be disk or remote smbfs partition. Extracting /opt backup could be:

cd /
rm -rf opt/*
tar xvzf /tmp/opt-backup.tar.gz

If /opt space is tight and no packages requiring libstdc++ will be used (like Amule) then removing this large
shared library is recommended

ipkg-opt downloads packages into /opt directory and erases them after installing. If you have enough free RAM and /jffs only then adding --tmp-dir /tmp is recommended instead of default /opt

Search PATH

Note: as of EKO svn11218 (dec 2008) it is no longer necessary to add to path or profile. As the mentioned changes are already added to the default path and profile.
For your scripts it may however still be beneficial to adjust LD_LIBRARY_PATH and PATH, as shown below, and as used in Startup for external USB Disk example.

Adding /opt/bin to search PATH will save us from tedious typing of /opt/bin for each command from /opt/bin. For running applications from /opt tree search path should be expanded with

Installing torrent client

Of course there are many more packages which should run on router without a problem. All binaries have built in /opt/lib search path and there should be no problem with libraries clash like problems with OpenWRT packages. All packages have builtin package dependencies and will install required libraries automagically. Lets show this on installing torrent clients enhanced-ctorrent (Stopped developing since June 2008), Enhanced CTorrent is a revised version of CTorrent:

We will not show running example for this clients as normally huge amount of storrage is required.

Another torrent client with WWW interface is Transmission. Now it has two branches listed in Optware.

Transmissiond

Lightweight BitTorrent daemon with CGI WWW interface, has a rich-functional web interface watching daemon state and controlling its work, transmission_watchdog can automatically watch and process torrent files in a directory. This one has lower memory footprint, but the development has stopped.

Transmission

Joshe created completely different "daemon" from scratch and maintained as one branch of transmission. Now it has merged the Clutch web interface, and listed as transmission in the list of Optware. The Clutch has better look but less function.The daemon can watch a directory for new torrent files now but you need to config this via it's setting file. Also the current build v1.93-1 (transmission-daemon, transmisison-remote, transmissioncli) seems bugy.

Below is a example of installing transmissiond (the old transmission). For example of installing the one with Clutch web interface please hit Transmission (v1.93-1) Note the config file between the two daemons are not compatible.

Transmissiond installation comes with /opt/etc/init.d/S80busybox_httpd to run its web interface. However, we will configure "Throttling HTTP server" (see next section) to show the startup page at port 8008. Although dd-wrt v23SP2 uses /opt/sbin/httpd (httpd -> /opt/bin/busybox) for its WEB interface, this httpd server cannot be reused as it has serioius problems running CGI programs and showing index.html files.

For public trackers CGI interface provides 'Fetch' button which downloads .torrent file into /opt/torrent/source directory. Private trackers use passkey which means that .torrent file should be saved with browser itself.

After seeing .torrent file in Queued list, one can press Watchdog button to force queue processing. This will move .torrent file from source into work directory and notify daemon for the change to start processing the file. After download finishes, transmission_watchdog will automaticly move torrent from work to target. Meanwhile, user can press Update button to see status of active torrents.

Besides transmissiond two other daemons are required for normal queue processing. Both are provided by dd-wrt if enabled in the web-GUI. "Cron" is enabled under Admin control panel. "Syslogd" is enabled under Services tab.

Cron should regulary run /opt/sbin/transmisison_watchdog with sample /opt/etc/crontab

*/30 * * * * root /opt/bin/nice /opt/sbin/transmission_watchdog

Visit CRON page to see where this line should be included. I recommend

cat /opt/etc/crontab >> /tmp/crontab

at startup,

Syslog will collect cumulative reports from transmisisond and CGI will show it when
Log or Update is pressed. If gnuplot is installed then also transfer graph is showed when Log is pressed. SYSLOG line in /opt/etc/transmission.conf must be changed to

SYSLOG=/opt/var/log/messages

to be able to see Log messages from daemon when Log button is pressed.

By default after enabled syslogd in the dd-wrt web-GUI, syslogd logs messages to /tmp/var/log/messages which is in ram. You can create S05syslogd in /opt/etc/init.d/ as below so it will log messages into disk everytime the router is rebooted.

After that you will be able to see default index.html page at http://192.168.1.1:8008/ assuming that your router is at 192.168.1.1 . There is also link to CGI page http://192.168.1.1:8008/cgi-bin/transmission.cgi which is preaty empty with several buttons for controlling daemon. Fetch command is useful only for fetching torrent files without passkey as there is no possibility to pass cookies to server. Use with care. Proper
fetch would be "download in browser and then upload to server (accessing server using samba, ftp or scp)".

Installing Samba2

Samba2 the easy way

See Slim Samba2 - a stripped down version of Optware Samba 2 for use on USB drives, just unpack a .tar.gz file, adjust a few settings in the web-GUI, and you are up and runnig.

See HDsamba2 - a fully automated install and boot script for installing Optware Samba2 with SWAT, and more... on a USB HD. Format you HD, adjust a few settings in the web-GUI, run the install script, and you are up and running.

Samba2 the step-by-step way

It looks like Samba 3 is too big for all "swapless" routers. Normally Samba 3 will use 10M RAM when up and will use more RAM when new connections established and it forks new threads. Samba 2 will roughly use half of this amount of RAM. For this reason I have prepared Samba 2 packages with Samba Web Admin Tool (SWAT) which will ease config and admin for samba newcomers.

But with Samba 2, you will get a slower data transfer speed (1.5M for Samba 3 and 1.3M/s for Samba 2 over wireless), this is a trade off for the RAM. If you have 64M RAM and have a external hard disk for swap, you can go for Samba 3. Also, you can run Samba as a xinetd service instead of a daemon, so it will only up on request. Running Samba 2 with xinetd, not as Daemon

Note about optware xinetd on dd-wrt: If you get a "can't resolve symbol '__ctype_b_loc' "error, means xinetd doesn't load the right lib from your environment setting. You could try: /opt/sbin/xinetd -d. The recommended approach is adding this line at the top of /opt/etc/init.d/S10xinetd to override the environment setting for xinetd :

export LD_PRELOAD=/opt/lib/libuClibc-0.9.28.so

Now run Xinetd and Samba

/opt/etc/init.d/S10xinetd start
/opt/etc/init.d/S80samba start

Point your browser to http://192.168.1.1:901/ to administer samba.(Here xinetd start the SWAT when there's a request on port 901)
Installation of xinetd is optional and it is not required if
one wants to manually edit /opt/etc/samba/smb.conf

Setting up smb.conf

Setting the "correct" (read: usable) settings in the /opt/etc/samba/smb.conf file seems to be an art all to itself.

If you prefere "security=user" settings, then the following settings in windows might still let you have access to your samba shares

If you are using Vista/Windows 7 Beta, with the stock security settings of the OS, you won't be able to log in into Samba 2's share when your Samba 2 share mode set to USER. The issue is related to an incompatible authentication protocol that runs between Vista/Windows 7 Beta and Samba 2 (lot's of NAS running it). This can be overcome by editing the security settings in windows. See also Instructions for Using Windows Vista with a Network File Server (NAS) Also, Samba 3 doesn't have this issue.

Setup other users to use the Samba Share

Adding users to sambaThe username need to be already in your /tmp/etc/passwd. And need to use the tool /opt/bin/smbpasswd to add that user into the Samba password file which by default is /opt/etc/samba/smbpasswd (configured in smb.conf). For example, add user root will be:

/opt/bin/smbpasswd -a root

Check the Samba log files

Try to look at the log files created by Samba, and check what happens.

Default location of log files are: /opt/var/samba/log.*

use command: ls /opt/var/samba/log.* - to see names of all log files

use command: cat /opt/var/log/samba/log.nmbd - to have one log file displayed

use command: cat /opt/var/log/samba/log.nmbd | more - to have one log file displayed, one page at a time

use command: vi /opt/var/log/samba/log.nmbd - to use vi editor be able to move curser up and down through the log file.

Type: :q! to exit vi editor

Other location of log files can be specified in smb.conf

in section [global]

use line: log file = /tmp/sambalog.%m

Default location of smb.conf file is: /opt/etc/samba/smb.conf

use command: cat /opt/etc/samba/smb.conf | grep 'log file' - to see if special log path is specified in smb.conf

Protect your FLASH memory

A long term problem that could happen when running samba on FLASH memory like jffs, mmc or USB stick is
FLASH wear. Such use could destroy FLASH if log files and browsing databases are constantly updated. Use of /tmp partition is recommended for such use. Amend startup script with:

if you have the line [ -d /tmp/samba ] || mkdir /tmp/samba in your samba start script, then simply add log file = /tmp/samba/sambalog.%m to smb.conf under [global], like:

[global]
log file = /tmp/samba/sambalog.%m

Running at startup

With dd-wrt.V24 the difference between system and OpenWRT Whiterussian R6 uClibc is so big, that running even simple programs causes segmentation fault. Optware also uses its own uClibc that resides in /opt/lib but all programs have built-in rpath to /opt/lib. This means that it is simpler to use Optware packages under DD-WRT than OpenWRT packages.

is also recommended as this will unset LD_LIBRARY_PATH provided by
stock /etc/profile

Although ext3 filesystem uses journaling that prevents major corruption and faster recover during crash, it is recommended that one writes its shutdown scrtipt as alias for /etc/profile that kills all optware daemons, umounts filesystems and then issue /sbin/reboot. This is what we call clean shutdown.

Note: as of EKO svn11218 (dec 2008) it is no longer necessary to add to path or profile. As the mentioned changes are already added to the default path and profile.
For your scripts it may however still be beneficial to adjust LD_LIBRARY_PATH and PATH, as Startup for external USB Disk example shows below.

Startup for external USB Disk

The following script is recommended when using external USB hard disk. The main feature of this script is prevention of disk corruption and automatic replacement.

It also shows how LD_LIBRARY_PATH can be used to compensate uClibc incompatibility between dd-wrt /lib and OpenWRT /jffs/lib .

The following script relies on two OpenWRT packages just to provide filesystem checking and enabling swap at startup. Besides reguired USB kernel modules, two disk related packages were installed: e2fsprogs and swap-utils. All others packages could be used from Optware.

Known bugs

ngrep doesn't work

ngrep is compiled with IPV6 support and ddwrt doesn't provide IPV6 support.

If ngrep is recompiled without IPV6 support, it works ok after adding the nobody user to /etc/passwd

# grep nobody /etc/passwd
nobody:x:99:99:Nobody:/:

Optware on CIFS - Partition in a file

[added by --omegadraconis 02 August 2010
I just took a note from the jffs mount and decided to use mount bind: mount -o bind /cifs1/Router /opt

I am sure there are reasons I should not do it this way but, I couldn't find any and I didn't have to load a bunch of kmods.

[added by --gruad23 27 June 2010
I prefer using a cifs-share itself as /opt and install optware as to the way Azuretech describes using a loop-mounted ext2-container on the cifs-share. I described the way I did it on [knowwiki:optware_on_cifs]

[added by --Azuretech 19:14, 20 February 2009 (CET)]
I have successfully used a SMB share for /opt, well, actually used a CIFS share, but the technique is the same, regardless. The trick is to create an ext2 partition inside of a file on the CIFS/SMB share, and mount that using the loop device. I have this working on v24. The technique is as follows:

Update: I discovered since I went to a mega build that this no longer works, because of lack of JFFS on some mega builds. Not to worry, here is a fix for this little problem. First disable JFFS in the GUI on DD-WRT, since it doesn't work anyways, and you can't mount it elsewhere if its active. After mounting a CIFS share, simply create a subdirectory in the CIFS share called jffs then:

And there you have it, optware is installed onto your CIFS or SMB directory.

Now that this part is complete, so long as you don't wipe your /jffs directory, you won't need to re-complete this every time you boot, since optware is stored safely on your CIFS file system, I simply added the following to a startup script in my CIFS share that will execute once the CIFS share is mounted.

And now that you can run all those cool optware apps, you're going to want a swapfile so you don't run out of memory.... This is a bit tricky... You can just create a swap file on the SMB share, swapon will protest, you need to create and mount an ext2 file on the SMB share, and then create the swapfile on that. Here's the sequence I followed on the BS mega builds:

So now your swap file will automatically be enabled shortly after boot up. To make sure your swap file is working just issue swapon -s you should get something like this back:

Filename Type Size Used Priority
/tmp/swap/swapfile file 65536 0 1

UPDATE: Now, I have discovered that aparantly, some builds are not compiled with swap support, and so even though you install the swap-utils package, you get a response of "can't resolve symbol 'swapon'" when you try to activate the swap file with the swapon command. If this should happen to you, you can resolve this by instead of installing the swap-utils package, install the optware busybox package with /opt/bin/ipkg-opt install busybox then calling swapon as /opt/sbin/swapon /tmp/swap/swapfile So, the correct sequence to follow in this case is:

For some reason I had problems creating the swap.ext2 and swapfile files using the commands above on my router. Instead, I created them on another computer running Linux and then copied them to the router.

Remarks

DD-WRT provided /bin/ipkg is not full feature ipkg but it can do the job for installing ipkg-opt. It could also be used for installing other packages, but this is not recommended any more.

DD-WRT kernel lacks many "server" features like NFS, NBD support, ... Provided samba, mysql, thttp-php and other applications can do the job if enough space is provided. This means that external storage is required for memory hungry applications. Experience from nslu2 and Oleg firmware showed that 512MB swap space is recommended if external USB hard disk is available. See USB page for instructions how to initialize USB kernel modules and harddisk.