Thursday, June 24, 2010

Software Installation on DD-WRT -- Part 2

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.

  1. 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 LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib:/opt/usr/local/lib'
    export PATH='/sbin:/opt/bin:/opt/usr/bin:/opt/sbin:/opt/usr/sbin:/bin:/usr/bin:/usr/sbin:/opt/usr/local/bin'
    export PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
    export TERMINFO='/opt/usr/share/terminfo'
    EOF

    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
    opkg update
    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.

  2. 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
    /opt/etc/init.d/p910nd
    /opt/etc/init.d/samba
    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)
    Guide for Samba server and the p910nd printer server will be detailed in future articles. This is just to get you an idea how the startup control system works.

12 comments:

Kev said...

This is very good info. I appreciate your writing this blog. I just got the same router and the information is very helpful.

One suggestion on the part 1, you should note that errors when running the original package install is normal. That got me confused for a good while.

Matthis Rouch said...

Thank you very much for this guide!! I'm now ready to have lots of fun with my router!!

picard said...

great work, thx!!!

Anonymous said...

Thanks I've been trying to get Samba working for about a week now and with in 15mins I further than I've been thanks to your blog.

Anonymous said...

The scripts in /opt/etc/init.d (hosted on the external drive now) all source /etc/rc.common which doesn't exist.
Any thoughts on that?

Anonymous said...

Why do I get this:
root@PDROOT root $ opkg install nano
Collected errors:
* opkg_install_cmd: Cannot install package nano.

Can someone help me please?

Anonymous said...

rc.common & functions.sh can get here: https://dev.openwrt.org/browser/trunk/package/base-files/files/etc

Anonymous said...

I am able to install nano ("Package nano (2.2.5-1) installed in root is up to date.")

But, when I try to run nano, putty says "Segmentation fault" and stops taking keystrokes.
Forgive my ignorance, but at what point does the "/opt/etc/init.d/samba" file/folder get created? I'm pretty sure that is what is keeping this from working.

Anonymous said...

Great Guide!!!

WNDR3700.

G.P.Sri said...

Hi Man, Thanks for your guide this is very useful for me to do more tricks in my router :)
Regards,
GPS

Angela Navejas said...

There are many confusing software available in the market that is the installation of these software are not an easy task so some companies provide online help to solve these problems.

Norton Antivirus Support | Mcafee Antivirus Support

Angela Navejas said...

This is really a nice and helpful post in which you discuss about the interactive grammar to which one get enough knowledge.

Tech Support Live | McAfee Antivirus Security Scan

Post a Comment