TechInfoDepot:DD-WRT/Optware, The Right Way

From TechInfoDepot
Jump to navigationJump to search
Optware, The Right Way
Developer frater
Target dd-wrt Broadcom devices

Be aware that there are two versions of Optware.
This page is for information OTRW (frater).

if you are looking for OTRW2 please go here


NOTE: Optware, The Right Way is for broadcom devices running DD-WRT only.

Source: Optware, The Right Way

Frater's no hassle, newbie friendly Optware

This is the latest, greatest and easiest way to enable Optware on your Router. It is recommended that you have a router with USB capable storage (Harddisks (must be self-powered), flash-drives etc.) and the LATEST build! (preferably freshly flashed)

For BrainSlayer builds. Common routers use broadcom or broadcom k26. Choose the appropriate newest build, then navigate the directories.

For Eko Builds, K26 here All Others Here

The SD/MMC Method is working thanks to DHC Darkshadow. For USB users, you wont be needing JFFS2, so DISABLE it! Another aspect to note is that some of these services (i.e Twonky) consume alot of CPU resources, so make sure you check your resource consumptions.

UPDATE For everyone using K26 builds or builds that were compiled in December, you will no longer need a startup or shutdown script. Use the Automount feature in Services->USB and mount to /opt in the drop down menu.

Default Services:

A complete list plus details can be found here

  • Asiablock - A custom iptables firewall that is configurable to block certain countries from accessing your Webserver, FTP or just general Web surfing.
  • Fixtables - This service is used to fix a firewall rule-set bug that is present in all K26 firmwares. K24 is not affected.
  • Pixelserv - A super minimal webserver, it's one and only purpose is serving a 1x1 pixel transparent gif file. Using some creative firewalling (netfilter/iptables) rules you can redirect some webrequests (for adds for example) to pixelserv. http://proxytunnel.sourceforge.net/pixelserv.php
  • Pre-configured Samba share - Samba provides file and print services for various Microsoft Windows clients and can integrate with a Windows Server domain, either as a Primary Domain Controller (PDC) or as a domain member. http://www.samba.org/
  • Service tool - Control all of these services. (Usage explained below)
  • Services running as other users than root
  • StopHack - This CRON script will check /var/log/messages for pound entries that are malicious and put the IP's in /opt/etc/asia.spam. The AsiaBlock service MUST be running for this to work.
  • Vlighttpd - Allows you to get a 2nd IP on your system and run virtual hosting there.
  • Worldblock - Very similar to Asiablock, other than the fact that it is for blocking everything except your country. To properly use this service, you must know how to use Vi editor to add your country.
  • Xinetd - A replacement for inetd, the internet services daemon. Controls user defined network services such as printing and SWAT (Samba Web Administration Tool) http://www.xinetd.org/
  • Other various useful tools such as net and storage diagnostics..

In my opinion, Everyone with a router that has storage device capabilities should take advantage of this! You will NOT regret it, even if it can be a time consuming process! If you are worried about formatting to a Linux filesystem and it's compatibility with windows, check out this thread from the forum on using the Windows NT Filesystem (NTFS)!

Getting Started

If starting from scratch, you will need to first format and partition your harddisk, flashdrive or SD card to an EXT2 or EXT3 Linux filesystem. It is much easier than you think, and can be accomplished via a Linux Live boot-CD. There will be NO changes to your PC whatsoever, and it is very simple to implement.

Drive Preparation and Prerequisites

Before you can utilize this extremely beneficial addition to your USB capable router, you must follow these important instructions:

How to - Format and Partition External Storage Device

The ext3 partitions can also be made in windows with MiniTool Partition Wizard, which is also free.

This must be done for Optware to work correctly!

Connecting the Drive to your Router

NOTE:For users using builds 15407 or newer may have to disable automount and load the drivers manually. The Dev's have decided to have the drivers load "On Demand" which doesn't do any good for multiple mount points outside of the single mountpoint made by automount. If you are using a single partition and monting your mount points inside that partition then the GUI automount will probably be ok.

To load the drivers manually place this in the "saved startup" section on the commands tab.

insmod mbcache
insmod ext2
insmod jbd
insmod ext3

NOTE:For users with small /opt partitions (Less than 256 MB, such as flashdrives and SD/MMC cards) use this as your start-up script:

mount -o noatime -t ext3 /dev/scsi/host0/bus0/target0/lun0/part1 /opt

For external HardDrives, use the following method:

1. In the DD-WRT web GUI screen, on the Services USB tab enable the options for:

  • Core USB support
  • USB 2.0 support (Asus WL520gU routers must use USB 1.1 drivers only!)
  • USB storage support
  • Printer Support (optional)
  • ext2/ext3 File System support
  • FAT File system support (optional)
  • Automatic Drive Mount
  • In the Disk Mount Point drop-down menu, mount to /opt

2. From the DD-WRT web GUI screen, click on Apply Settings. This will reboot the router.

3. If everything was done correctly, this should appear on your Services -> USB Tab:

Drivemount2.jpg

IMPORTANT

If using a USB hub to connect multiple devices, make sure NOT to overload the routers power supply. If the devices are self-powered, still be careful. Flashdrives do consume quite a bit of power, and even the I/O of the self-powered devices pulls some current.

Executing the Script

Start a terminal session using telnet or SSH

To do this in Windows, go to Start -> Run and type the following:

telnet 192.168.1.1

Enter the following at the telnet prompt:

login:root

password: router's admin password to the web interface.

NOTE When entering your password, the characters will not show up. This is normal for security. If it doesn't work the first time, make sure you don't make a typo or that the caps lock is not on when entering it.

See also: Telnet/SSH and the Command Line

In Windows, telnet can be accessed from a command prompt... Start ->Run, while a program like PuTTY will allow for either telnet or SSH sessions and is a much more flexible and secure shell prompt. It does not even need to be installed..

NOTE - Can't login via SSH

If you find that you can't log in to SSH after installation, check that you're using a build greater than, and including 12827. The reason is that bash is used as shell after installation, but older firmware builds don't allow for shells other than /bin/sh to be used in SSH.

Once logged in:

Issue the command mount to ensure /opt is mounted (K24 and K26 have different Device paths, observe the following; #1 is K24 #2 is K26):

root@Project:DD-WRT/~#mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro)
none on /dev type devfs (rw)
proc on /proc type proc (rw)
ramfs on /tmp type ramfs (rw)
devpts on /proc/bus/usb type usbfs (rw)
/dev/scsi/host0/bus0/target0/lun0/part1 on /opt type ext3 (rw)
root@Project:DD-WRT/~#
root@Project:DD-WRT/~# mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro)
none on /dev type devfs (rw)
proc on /proc type proc (rw)
ramfs on /tmp type ramfs (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw)
devpts on /proc/bus/usb type usbfs (rw)
/dev/discs/disc0/part1 on /opt type ext3 (rw)
root@Project:DD-WRT/~#

Make sure you are able to connect to the internet through the router. Pinging a domain is a good example:

ping yahoo.com (or any other domain of your choice)

You should get a multi-line response along the lines of:

PING yahoo.com (72.30.2.43): 56 data bytes
64 bytes from 72.30.2.43: icmp_seq=0 ttl=52 time=106.551 ms
64 bytes from 72.30.2.43: icmp_seq=1 ttl=52 time=102.864 ms
64 bytes from 72.30.2.43: icmp_seq=2 ttl=52 time=101.219 ms
64 bytes from 72.30.2.43: icmp_seq=3 ttl=52 time=100.507 ms
64 bytes from 72.30.2.43: icmp_seq=4 ttl=52 time=96.661 ms

Once you see a few lines of that, hit CTRL+C to return to a root prompt.

If you do NOT see output as mentioned above, you need to troubleshoot to establish an internet connection first. Some possibilities:

A) Reboot the router. (this alone may help. If not, continue to suggestion B)

B) Power off your cable modem, then the router.
Wait 30 seconds, then power on the cable modem.
Wait 30 seconds and power on the router.
Wait 30 seconds, then telnet back into the router and repeat the ping test demonstrated above.

Now you should have a connection. If so, continue with the following steps.

Enter the following commands into Busybox/Telnet:

wget -O /tmp/prep_optware http://wd.mirmana.com/prep_optware
sh /tmp/prep_optware

This will load all the necessary Optware and supporting scripts that Frater wrote from the ground up.

This will take about 10-20 mins depending on your connection and your router CPU clock. Close your Web Interface as this consumes precious memory and CPU resources

Once everything has completed, wait you will be returned to a root prompt. Wait a minimum of 1 minute, then type reboot into either the BusyBox/Telnet Shell (why not, your right there) or reboot via Web Interface.

Important After rebooting, wait again at least another minute before logging back into the Telnet/SSH session!

Ensure Partitions are mounted

In either telnet or SSH, enter the command mount , if everything is working properly, it should look like this:

Mount.jpg

Important To keep track of your drives free space, issue the command df -h

You will get an output like this:

root@Asus:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                5.7M  5.7M     0 100% /
/dev/root             5.7M  5.7M     0 100% /
/dev/discs/disc0/part1
                     756M  215M  534M  29% /opt
/dev/sda4             293G  173G  117G  60% /mnt
/dev/sda3             504M   17M  483M   4% /tmp/c
root@Asus:~#

Using PuTTy to enable/disable Services

Service.jpg

BusyBox/Telnet Commands for services:

service - show all services (enabled/disabled)
service <service name> - if "status" parameter is supported, will show service status, otherwise will show whether specified service is running
service <service name> on - Enable the script, allowing execution (chmod +x  /opt/etc/init.d/S<servicescript>)
service <service name> off - Disable the script, disallowing execution (chmod -x  /opt/etc/init.d/S<servicescript>)
service <service name> start - Start/execute the script, as long as service is enabled (i.e. permissions allow execution)
service <service name> stop Stop/kill the script, if the service is running
service <service name> restart Stop/kill the script, if the service is running, and then start/execute the script, as long as service is enabled
service <service name> <parameter> - Run the script with the parameter.

For a service to work it must be first switched on*, and then told to start.

service <service name> on
service <service name> start
  • Once you enable a service with the on parameter, the service is set to allow execution, and will run the next time you restart your router. You will need to issue a start directly proceeding it to initiate the service if you wish to start the service without restarting your router. A service must be set to on before it can be started.

Examples:

service xinetd status
service xinetd off
service xinetd on
service xinetd start
service xinetd stop
service xinetd restart

NOTE Xinetd will need to be started after the optware has been installed and the router has rebooted.

Issue:

service xinetd on
service xinetd start

This service MUST be enabled for services such as Network Printing, SWAT (web admin/config for samba) and OpenVPN

Turning off Twonky

Twonky Media Server (google it) may be enabled by default. It is a massive resource hog and can bog down even the most powerful routers. It is recommended to disable it unless you require its services.

service twonky stop
service twonky off

Automount

service automount start - mount all partitions
service automount stop - umount all partitions instead of the one to /opt
service automount status - show all partitions
service automount umount <partition|mountpoint> - unmount that partition and remove it fromautomount
service automount nomount <partition> - Do not automount this partition
service automount nonomount <partition> - remove this partition from the nomount list

Upgrading to Samba 3.5

If you wish to remove the default Samba filesystem (Samba 2), and you have the necessary hardware resources, Samba 3 is a good tutorial to follow.

See NOTES at the bottom of this page for important/useful commands

Service Explanations/Configuration Examples

A complete list plus details can be found here

Accessing services in web browser

You can also turn a service on or off through the web interface command line in Administration-> Commands (for people who don't like the hassle of SSH):

Examples:

 /opt/usr/sbin/service transmission-daemon on
 /opt/usr/sbin/service transmission-daemon start

 /opt/usr/sbin/service xinetd on
 /opt/usr/sbin/service xinetd start

Choose the service(s) you wish to execute and click Run Commands in the Administration->Commands box.

You are ready to go! It is also wise to wait at least 30 seconds after enabling these services before accessing them.

Some services have their own web interface:

* Asterisk - http://asterisk.:1313/cgi-bin/asterisk
* Swat/Samba - http://your.routers.ip:901
* Torrent Transmission - http://your.routers.ip:9091
* Twonky Media - http://your.routers.ip:9000

SD/MMC Method

After haveing so time to play around with my TM now that I have a new gateway, It seems

cd /opt
rm -r *

causes more problems than it's worth. If you are running OTRW and need a clean install, wipe the card and start from scratch.

After and including build 13309

  1. Make sure you have 13309 or higher on your router. Start with a fresh system 30/30/30 reset.
  2. Partition the card - partition1 data, partition2 opt, partition3 jffs,partition4 swap reference How to - Format and Partition External Storage Device.
  3. Boot router.
    1. Enable SD support. The firmware will automount the first partition to /mmc.
    2. Enable jffs.
    3. Setup your internet connection.
    4. Save the following script to Startup in Administration->Commands.
      1. mount /dev/mmc/disc0/part2 /opt
    5. automount will do the rest
  4. Log into the router via Putty (SSH) and run fraters script below. This will take a while. It will tell you when it's finished.
    1. wget -O /tmp/prep_optware http://wd.mirmana.com/prep_optware
    2. sh /tmp/prep_optware
  5. When the script is done, it will tell you so and advise a reboot. (it is wise to wait ~1-2 mins after completion before rebooting)
  6. Reboot

Before build 13309

First off credit goes to frater for the optware script and the driver script credit goes to aszu and the startup script for the driver goes to phuzi0n. My hats off to you guys.

An update on my situation. The SD cards speeds were too slow and were overwhelming the router. I have steps for anyone using SD. It uses the new driver for the install. I have tested this 4 times on 2 different sd cards.

Start with a fresh system 30/30/30 reset, a Clean formatted SD card in either ext2 or ext3 with a /jffs directory, then create /opt inside of /jffs. Ex. /jffs/opt.

For some reason the later builds have a problem with formatting a card on setup, it screws the partition making the card invisible to the router. The above remedies this, and a service ticket has been submitted to fix this.

Continuing:

1.
a. Boot router.
b. Enable and setup GPIO's in the GUI for the SD Mod, because in the later builds auto GPIO is broken. Also setup your internet connection.
c. Enable jffs.
d. Copy the SDHC driver from HERE to the root directory of the MMC card via WinSCP
e. Save the following script to Startup in Administration->Commands. This Startup script will run the new SDHC driver all the time. It is only necessary until the release of a build with it all ready ported.

 cp /mmc/sdhc-gpio2.o /tmp
 umount /mmc
 rmmod mmc
 insmod /tmp/sdhc-gpio2.o
 mount /dev/mmc/part1 /mmc/
 mount --bind /mmc/jffs /jffs
 mount -o bind /mmc/jffs/opt /opt

2. Log into the router via Putty (SSH) and run fraters script below. This will take a while. It will tell you when it's finished.

wget -O /tmp/prep_optware http://wd.mirmana.com/prep_optware
sh /tmp/prep_optware

3. Reboot (it is wise to wait ~1-2 mins after completion before rebooting)

Notes

Useful commands

mount - Shows what disks/partitions are mounted
fdisk -l - Shows disk information
blkid - Shows disk information
df -h - Shows disk usage and available space.  Very important
lsusb - Shows devices in /dev/usb/ like printers, USB hubs etc.
top - Shows all running processes and resources as well as swap file usage and CPU-Memory usage.
htop - A more user friendly application that allows you to kill processes, change their "nice" value, etc.
netstat -lnp - Shows which ports are open and what services are using them.
cat /tmp/fdisk
cat /tmp/blkid
cat /opt/etc/automount
cat /opt/etc/nomount
cat /var/log/messages - Shows the kernel logs if Syslogd is enabled.  Useful for debugging or viewing Events.
cat /opt/var/log/messages - Shows the Optware logs.  Great for information.
  • You may find it easier to browse the logs using parameters separated with a | such as more and grep . Grep means find, and more will allow you to view the entire log one line at a time by pressing or holding down Enter . The parameters can also be used in conjunction:

Example :

root@Asus:~# cat /var/log/messages | grep Linux
Jan  1 00:00:06 Asus user.notice kernel: Linux version 2.6.24.111 (root@dd-wrt)
(gcc version 4.1.2) #1058 Wed Mar 24 04:18:19 CET 2010
root@Asus:~#

cat /var/log/messages | grep Linux | more

  • To remove this optware completely (which should be done after a build upgrade, or if you don't need all of these services) do the following:
cd /opt
rm -r *
  • When using USB storage (or maybe other form of storage as well), in order to automount the remaining partitions, the packages 'util-linux-ng' and 'grep' should be installed as well:
ipkg-opt install util-linux-ng
ipkg-opt install grep

Many more exciting packages are in the works, so be sure to follow This forum thread and further help is always available on the forums.

Enjoy!

OTRW Logging

If you want optware to allow logging of accepted packets and you have plenty of space for it, comment out the following lines from the file S94stophammer located in the directory /opt/etc/init.d.

if [ `nvram get log_accepted` -ne 0  ] ; then
  nvram set log_accepted=0
  nvram commit
  optlog "${NAME}" "I turned off logging for accepted with 'nvram set log_accepted=0', sorry"
fi
init_files


Kernel 2.6 Problems! [READ!]

Currrently (As of Build 13972), Media Servers (Twonky, Mediatomb, UShare, Etc) are not working under the 2.6 Kernel! If you want to use these services, use the 2.4 Kernel! But, make sure you can put the 2.4 kernel on your hardware first.