In previous part, we have everything settled(almost). Now its the time for some more fine tune.
By employing the techniques in Part 1, we have the following setup upon each reboot:
- A USB drive mounted and accessible at /mnt
- A writable /etc folder(actually /mnt/etc) and has exact same content as original /etc folder
- A writable /opt folder(actually /mnt/opt) -- where all future software will be installed and run from(/opt/bin, /opt/sbin, /opt/usr/bin, just name a few) and keep the original DD-WRT folders like /bin /sbin untouched.
- A writable and persistent /tmp/root(actually /mnt/root). This will be the home folder for user root
- An empty file /mnt/optware.enable. This is used to control the whole optware installation. By renaming or deleting this file, all customized software/modification WILL BE DISABLED and thus put the router back to standard DD-WRT. This is useful for debugging and firmware upgrading.
Still, there is something left to do, notably that, with current setup, the LD_LIBRARY_PATH and PATH variables have to be set each time before running any command. We might also want to run some installed software as service.
- Set the initial variables
Login with PuTTY then copy/paste the commands below to PuTTY window to create a script running each time when user root logins.
cat > /mnt/root/.profile << EOF
export PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
The above script will set the variables for us and also provide a nice colored command line prompt. Now exit the current PuTTY window and connect again, if you see a colored prompt then it's working correctly. Run
directly and it should work now -- no need to set the lengthy variables each time. Also, if you're not familar with vi, time to get the nano editor
opkg install nano
Then type nano to launch it.
- Run installed software as service
In previous guide(Part 1), our DD-WRT startup script does nothing more than mounting several folders. We don't use it to launch any programs simply because its not necessary as DD-WRT has a feature that, it will run any script during startup automatically once it's in correct location with correct name.
To run a script with our current setup, all we need to do is to put the scripts to /opt/etc/init.d folder and name them in the format of S##ScriptName. The ## is two digit from 00 to 99, script with smaller number will run first. For example, to run Samba file server and p910nd printer server as services, we just need to create two startup script
then make symbolic links:
ln -s /opt/etc/init.d/p910nd /opt/etc/init.d/S30p910nd
ln -s /opt/etc/init.d/samba /opt/etc/init.d/S50samba
and p910nd will start up first then samba. And, in case you don't need them as service, delete the symbolic links(S30p910nd/S50samba) but keep the original startup script so it can be easily recovered. The program can also be launched directly by running the corresponding script(/opt/etc/init.d/p910nd and /opt/etc/init.d/samba)