Installing Optware on TomatoUSB

Asus RT N16 - [0]

For my setup I have an Asus RT N16 with Toastmans TomatoUSB build. My USB flash drive is 4GB.
Despite the popularity of this topic it was hard to find complete instructions for installation on a USB flash drive.

Following are the steps I took:

Unmount disk, if mounted

Open Tomato menu. On the USB Support page, be sure to check Core USB Support, USB 2.0 Support, USB Storage Support, Ext2/Ext3, and Automount. Save this. Your disk should appear lower on the page under Attached Devices. On the right hand side, if it is Mounted, click Unmount. - [1]

Create Partitions

SSH into the router using PuTTY to 192.168.1.1
Use fdisk to create the partitions. In the following lines, # and after are comments. is the enter key. - [2]

fdisk /dev/sda # adjust for disk if necessary. 
p # to see existing partitions
d # to delete partition if any
n # new partition
p # primary partition
1 # a one for partition 1 for Optware
 # start at default 1 block
+512M # size of Optware partition in MB; can be larger
p # check partition
n # new swap
p # primary
2 # partition 2 Swap
 # start at default block
+64M # size of Swap in MB; can be larger
t # set type of Swap partition
2 # partition 2 is Swap
82 # swap type
p # check partitions
n # new Data for remaining
p # primary
3 # partition 3 Data
 # default start block
 # default remaining blocks
p # check partitions
w # write it all out and exit

At the end, if you see a: fdisk: WARNING: rereading partition table failed, kernel still uses old table: Invalid argument ensure you are starting fdisk with using fdisk /dev/sda and not fdisk /dev/sda1!

Format Partitions

Since I'm using a USB stick and not a USB harddrive I picked ext2 for my filesystem. ext3 is journaled and will wear out a USB flash in no time.
ext2 is still recommended over journaling file systems on bootable USB flash drives and other solid-state drives. ext2 performs fewer writes than ext3 since it does not need to write to the journal. As the major aging factor of a flash chip is the number of erase cycles, and as those happen frequently on writes, this increases the life span of the solid-state device. Another good practice for filesystems on flash devices is the use of the noatime mount option, for the same reason. - [3]
 #-L sets the labels of the partitions
mkfs.ext2 -L optware /dev/sda1 
mkswap -L swap /dev/sda2 
mkfs.ext2 -L data /dev/sda3

Automount to /opt

In the USB support page hit refresh and click mount to mount the partitions.
To automatically mount the partition named "optware" in /opt paste this in the 'Run after mounting' box
if [ -d /mnt/optware ]; then 
    mount -o bind /mnt/optware /opt
fi 
On reboot this should take effect. For now, in PuTTY, type:
mount -o bind /mnt/optware /opt 
mount
you should see this:
/dev/sda1 on /opt type ext2 (rw,nodev,noatime) 

Great! You're all set to install optware.

Install optware

Download the installation script and run it -[4]
wget http://tomatousb.org/local--files/tut:optware-installation/optware-install.sh -O - | tr -d '\r' > /tmp/optware-install.sh
chmod +x /tmp/optware-install.sh
sh /tmp/optware-install.sh

Automatic package updater

To allow optware to update its package list once a day do the following: Go to Administration » Scheduler and add the following line to the "Command" field of Custom 1, 2, or 3 (just use one that's available). Select the desired frequency (once a day is usually sufficient) -[5]
ipkg update | logger -t Optware 
This will run the update and log the output

Race-Contition Workaround

Details on the race-condition are here under 'How optware integrates with TomatoUSB'
To ensure that optware's firewall and wan scripts are run even if a race-condition occurs:
Create a new file /opt/.autorun with the following contents -[6]:
#!/bin/sh
if [ -f /var/notice/wan ]; then
   for s in /opt/etc/config/*.wanup; do $s; done
   for s in /opt/etc/config/*.fire; do $s; done 
fi

Make the file executable: chmod +x /opt/.autorun

Awesome! optware is installed!

Using Optware

List all installed packages:
ipkg list_installed

List all available packages:
ipkg list

Find a package: (eg find package 'transmission')
ipkg list | grep transmission

Install a package (eg install 'transmission')
ipkg install transmission

Remove a package (eg remove 'transmission')
ipkg remove transmission

More options:
ipkg --help

References: 
http://airfart.blogspot.com/2010/10/how-to-prepare-usb-disk-for-optware.html
http://tomatousb.org/tut:optware-installation
http://www.webos-internals.org/wiki/Optware

6 comments:

Anonymous said...

Thanks for the writeup!

I think I found a typo. Shouldn't this part be /mnt/optware:

if [ -d /mnt/Optware ]; then
mount -o bind /mnt/Optware /opt
fi

When I use /mnt/Optware, mount reports:

/dev/sda3 on /tmp/mnt/data type ext3 (rw,nodev,noatime,data=ordered)
/dev/sda1 on /tmp/mnt/optware type ext3 (rw,nodev,noatime,data=ordered)


When I change it to /mnt/optware, mount reports:

/dev/sda1 on /tmp/mnt/optware type ext3 (rw,nodev,noatime,data=ordered)
/dev/sda1 on /opt type ext3 (rw,nodev,noatime,data=ordered)
/dev/sda3 on /tmp/mnt/data type ext3 (rw,nodev,noatime,data=ordered)
/dev/sda1 on /opt type ext3 (rw,nodev,noatime,data=ordered)

/opt shows up now but it shows up multiple times. Any ideas? Thanks.

gwyneth said...

Thanks for the typo catch.

I'm not sure how you have 2 mounts to /opt.

if [ -d /mnt/optware ]; then
mount -o bind /mnt/optware /opt
fi
The code above basically means, after mounting a USB to /mnt/ if you find the folder '/mnt/optware' exists then mount that folder to '/opt' as well.

My quick suggestion to your problem would be fix the typo and reboot the router.

Hope that helps!

Ron said...


When using "mkfs.ext2" , you might
want to look int the "-m" flag, eg.
" mkfs.ext2 -m0 -L optware /dev/sda1 "
and
" mkfs.ext2 -m0 -L data /dev/sda3 "

"-m0" will set aside 0MB , which will
save some valuable space on small drives.

Josh said...

Hi

I think the code:
wget http://tomatousb.org/local--files/tut:optware-installation/optware-install.sh -O - | tr -d '\r' > /tmp/optware-install.sh
Is displaying a little bit short of the full script.

Really decent writeup!


Josh said...

Hey,

Just curious how hard woul it be to get the JRE on tomatousb and run a jar file like crushftp. I really want an ftp server with an http gui.

I know tomato is really stripped down from other distros of linux. What do you think? Is tomato running on just the linux 2.6 kernel? No desktop environment... no frills?



Josh

Lovaduck said...

Great guide, will be using it. I am not that handy with Linux but I can handle this just fine. Is there any reason why I couldn't create all the partitions on my Ubuntu desktop using Gparted instead of using Tomato? I don't see why not except for the fact that not everybody will have a Linux machine, so your instructions (very wisely) don't assume anything :)
Thanks for sharing this hack!