Optware, the Right Way

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 13:23, 20 November 2009 (edit)
Masterman (Talk | contribs)
(Frater's no hassle, newbie friendly Optware)
← Previous diff
Revision as of 13:25, 20 November 2009 (edit) (undo)
Masterman (Talk | contribs)
(Connecting the Drive to your Router)
Next diff →
Line 322: Line 322:
* Core USB support * Core USB support
-* USB 2.0 support+* USB 2.0 support (Asus WL520gU routers must use USB 1.1 drivers only!)
* USB storage support * USB storage support
* Printer Support (optional) * Printer Support (optional)

Revision as of 13:25, 20 November 2009

Contents

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 (Harddisk, flashdrives etc.), although the SD/MMC Method is working. For USB users, you wont be needing JFFS2, so DISABLE it!


Services that will be installed:


  • Bash instead of shell in busybox (LFS support)
  • Automounting and unmounting of storage device partitions
  • Network printing
  • Torrent transmission with watchdog
  • Hotmount
  • Pre-configured samba share
  • Reverse proxy featuring pound
  • Service tool
  • Xinetd
  • Pound
  • Asterisk
  • Lighttpd
  • Vlighttpd
  • Countryblock
  • AsiaBlock
  • Services running as other users than root
  • Vim with proper terminal support
  • Twonky Media


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!

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.


My personal favorite is Ubuntu as it provides a very user friendly interface and can be understood in a matter of minutes no matter what OS you use (Windows, MAC etc) and not to mention Firefox is already installed. Just download the free for life version of your choice (32 or 64 bit) from the above link, and use a burning software like Nero to burn the Image to a CD. After that, simply pop the disc into your CD/DVD drive and reboot.


If your PC BIOS settings are set like they should be (first drive to boot should be the CD/DVD drive), then sit back and wait for it to load.


It will then prompt you for language selection, and then the query prompt will proceed. Default is "Try Ubuntu without any changes to your computer." Hit enter and let it load.

Once in Ubuntu, connect the drive you wish to format and partition.


Drive Preparation

You will need to set the storage device as Unallocated. In Ubuntu go to System->Administration->Partition Editor. Use the drop down menu on the right to select the storage device you want to partition and format. Once selected, navigate to the top menu and select Device then select Create Partition Table then select Create

It will look like this:


Image:Screenshot-1.png



Once completed, navigate to the browsing menu at the top of the screen and look for Applications->Accessories, then click Terminal


Once in the Terminal window, read the following directions and enter the following commands:


NOTE: All BOLD text in this Wiki will be the commands that you enter.


Type sudo su - as this allows you to become root, or full administrator of the machine.


Using the fdisk command, you will be creating four partitions:

  • sd?1 - the /opt partition, where Optware will reside.
  • sd?2 - the swap partition, where Linux will swap jobs.
  • sd?3 - the /jffs partition
  • sd?4 - the data partition, which you will share via Samba or FTP.

NOTE The ?'s are the drive letters Linux assigns. You will need to determine which one is correct by issuing the command fdisk -l. You will be looking for the disk you want to format (It will almost be towards the end of the print-out). Here is an example of what it should look like:


root@ubuntu:~# fdisk -l (lower case L)
Disk /dev/sda: 100.0 GB, 100030242816 bytes
255 heads, 63 sectors/track, 12161 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x89e489e4
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       12160    97675168+   7  HPFS/NTFS
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0c347bdb
  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001    7  HPFS/NTFS
Disk /dev/sdc: 2055 MB, 2055019520 bytes
215 heads, 43 sectors/track, 434 cylinders
Units = cylinders of 9245 * 512 = 4733440 bytes
Disk identifier: 0x000e0383
  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1         435     2006854+   c  W95 FAT32 (LBA)
Partition 1 has different physical/logical endings:
    phys=(249, 214, 43) logical=(434, 32, 4)
Disk /dev/sdd: 8015 MB, 8015314944 bytes
255 heads, 63 sectors/track, 974 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0006fe25
  Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         974     7823623+   b  W95 FAT32


fdisk /dev/sdd
Command (m for help): p
Disk /dev/sdd: 8015 MB, 8015314944 bytes
255 heads, 63 sectors/track, 974 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0006fe25
  Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         974     7823623+   b  W95 FAT32


Another more user friendly way is to use Ubuntu's GParted tool, which is located in System->Administration->Partition Editor. Here you can either use it to identify the drive letter of the disk, or you can Partition it.


It's important to understand everyone's disk drive configuration will be different. If your drive is 40 GB or smaller, use the smaller set of partition sizes below. If your drive is over 40 GB, you can use the larger set of partition sizes.

Disk 40 GB or less


  • /opt 256 megabytes
  • swap 32 megabytes
  • /jffs 128 megabytes
  • data remainder of the disk

Disk greater than 40 GB


  • /opt 512 megabytes
  • swap 64 megabytes
  • /jffs 256 megabytes
  • data remainder of the disk


NOTE For smaller storage devices such as SD/MMC and flash drives, the minimum partition size for /opt should be 256MB


Also the /jffs partition is not necessary if you are only installing this Optware.


Code: (the ? are the drive letters (c,d,e etc.) so make sure you choose the correct one!) The bold texts are the commands

fdisk /dev/sd?
Command (m for help): d (deletes the partition)
Selected partition 1
Command (m for help): p
Disk /dev/sdd: 8015 MB, 8015314944 bytes
255 heads, 63 sectors/track, 974 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0006fe25
Device Boot      Start         End      Blocks   Id  System
Command (m for help): p 
Disk /dev/sd?: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-621, default 1):<HIT ENTER>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-621, default 621): +512M <HIT ENTER>
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (197-621, default 197):<HIT ENTER>
Using default value 197
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +64M <HIT ENTER>
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (197-621, default 197):<HIT ENTER>
Using default value 621
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M <HIT ENTER>
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 4
First cylinder (197-621, default 197):<HIT ENTER>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): <HIT ENTER>
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap)      
Command (m for help): p
Disk /dev/sd?: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
Device Boot    Start       End    Blocks   Id  System
/dev/sd?1   *         1       196    395104+  83  Linux
/dev/sd?2           197       262    133056   82  Linux swap
/dev/sd?3           263       458    395136   83  Linux
Command (m for help): w

If you get a message saying that the current table is in use and will be executed on next reboot, then do it! Make SURE though after rebooting that when you open the terminal for the next sequence of commands, do a sudo su - followed by an fdisk /dev/sd? and type p as this will verify the partition table


Continuing:

Formatting the /opt, /jffs and data partitions, and preparing the swap partition

NOTE

If an error occurs for the following such as:

root@ubuntu:~# mke2fs -j -m 1 -L Optware /dev/sdd1
mke2fs 1.41.4 (27-Jan-2009)
/dev/sdd1 is mounted; will not make a filesystem here!

Please refer to the previous page with the Image.



Terminal Commands:


mke2fs -j -m 1 -L Optware /dev/sd?1

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
Filesystem label=Optware
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122112 inodes, 243964 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
15264 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

mke2fs -j -m 1 -L Shared /dev/sd?3

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
Filesystem label=Shared
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122112 inodes, 243964 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
15264 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

mke2fs -j -m 1 -L Data /dev/sd?4

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
Filesystem label=Data
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122112 inodes, 243964 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
15264 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done


mkswap /dev/sd?2


Now your disk drive is partitioned and formatted for Linux! If you are a windows user, you can either proceed (recommended) using Linux (Ubuntu comes with FireFox already installed) or shut down the Linux distro you used, and make sure the boot disk pops out, as you wll need to get back to windows.

Connecting the Drive to your Router

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


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


3. There are several methods of doing this. Once you have all your partitions set on the external device, add this to your Start-up script in Administration->Commands

Startup script (make sure you install to the/opt partition. Replace the ? after ..lun0/part with the appropriate partition number that /opt is designated. It SHOULD be 1)

sleep 10 && mount -t ext3 /dev/scsi/host0/bus0/target0/lun0/part? /opt &
n=1
while [ ! -d /opt/etc/init.d ] ; do
 sleep 3
 [ $n -gt 30 ] && break
 let n+=1
done
/opt/etc/init.d/optS

Click Save Startup


Shutdown script:

/opt/etc/init.d/optK

Click Save Shutdown


It should look like this:

Image:Start-up.png


Give the router a minute or two to process and reboot.


Alternative (easier):

Web Interface Method:

Go to Services->USB. Enable USB Core support, USB 2.0 Support, USB Printer Support, USB Storage Support, Ext2/3 support, FAT File System Support (optional) and Automatic Drive Mount.

Once the drive and partitions are recognized, Select /opt from the Drop-down menu. Click Apply settings (your router will reboot)

NOTE This may be easier, but the initial Command Line method is much more reliable!


Next, start a terminal session to your router with the command telnet 192.168.1.1, followed by login (root) and your routers password, or use a program like PuTTY if using Windows.


First issue these commands to ensure /opt is mounted:

root@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@DD-WRT:~#



Here's just a little sample of my device output parameters. Yours will not look like this yet.


root@Asus:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                5.0M  5.0M     0 100% /
/dev/root             5.0M  5.0M     0 100% /
/dev/scsi/host0/bus0/target0/lun0/part3
                     259M  213M   44M  83% /opt
/dev/scsi/host0/bus0/target0/lun0/part4
                     293G  6.7G  284G   3% /mnt
/dev/scsi/host0/bus0/target0/lun0/part1
                      69M  5.6M   63M   9% /jffs
root@Asus:~#


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, type reboot into either the BusyBox/Telnet Shell (why not, your right there) or through the Web Interface.

Using PuTTy to enable/disable Services

Image:Puttyexample.png



The BusyBox/Telnet Commands to enable/disable the services are are follows:

service - show all services (enabled/disabled)
service <service name> - if "status" is supported it will run the service-script with "status" asparameter. 
service <service name> on - Enable the script (chmod +x  /opt/etc/init.d/S<servicescript>)
service <service name> off - Disable the script (chmod -x  /opt/etc/init.d/S<servicescript>)
service <service name> <parameter> - Run the script with the parameter.


  • Once you enable a service with the on parameter, you will also need to issue a start directly proceeding it to initiate the service.


Examples:

service
service xinetd
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 start

This service MUST be enabled for Network Printing, etc.


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 unmount <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


NOTE

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!

SD/MMC Method

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.

  • Boot router.
  • 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.
  • Enable jffs.
  • Copy the SDHC driver from HERE to the root directory of the MMC card via WinSCP
  • 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.


Code:

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.


Code:

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)



Useful scripts

mount
fdisk -l
blkid
df -h
cat /tmp/fdisk
cat /tmp/blkid
cat /opt/etc/automount
cat /opt/etc/nomount
lsusb



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!