Thursday, June 24, 2010

Software Installation on DD-WRT -- Part 1

One thing interesting about the router is its exotic hardware specification -- 400MHz processor, 32MB flash ROM, 64MB RAM and most important of all, a USB port. All these make the router a very versatile little Linux box with tons of capabilities. However, one thing might confuse non-experienced users is that, the CPU in the router is MIPS(MIPS in big-endian), while the popular Broadcom routers(such as Linksys WRT54G) are MIPSEL(MIPS in little-endian). I don’t want to go into technical detail here, but just remember, even both are MIPS, they’re different and prebuilt binary for Broadcom routers WILL NOT work on this WZR-HP-G300NH and other Atheros based devices.

Thanks to the OpenWrt guys, with some effort, we can now put the OpenWrt binary on this router and it will run as good as the popular “optware”.

In this tutorial, I'll guide you through the process and all software will be installed on USB disk though the Buffalo router has a gorgeous 32MB flash ROM. The reason is simple – the flash ROM jffs partition will NOT survive during a firmware upgrade and you definitely don’t want to reinstall everything again each time. Also, USB disk is much faster than internal flash.

This guide will also work with other USB enabled Atheros routers such as TP-LINK TL-WR1043ND, Linksys WRT160NL, D-LInk DIR-825 RevB and Netgear WNDR3700

  1. Prepare the USB disk
    Here we can use a USB flash drive or a USB hard drive and the drive must be preformatted to ext2 or ext3(recommended) before plugging into the router.
    Any Linux live CD should do the trick and I personally recommend GParted, which can be installed in CD or USB disk.

  2. Set up DD-WRT accordingly
    a. Turn on ssh.
    This is under Services->Service->Secure Shell. See the picture below. Then click “Apply Settings” at the bottom of the page.
    ssh-enable

    b. Set USB Support
    Under Services->USB tab. Will disable “Automatic Drive Mount” here. After that, click “Apply Settings”usb-enable

    c. Disable the jffs partition
    Under Administration->Management, disable “JFFS2 Support”. After that, click “Apply Settings”.

  3. Download WinSCP, PuTTY and prebuilt libraries
    WinSCP is used to copy file between PC and router and PuTTY is for router shell login. Both are freeware.
    Also, you’ll need some prebuilt OpenWrt libraries called lib.tar(thanks Luyi@DD-WRT forum check original discussion thread)
    Get it from DD-WRT forum(login required) or mirror site.

  4. Now plug in the USB drive and reboot the router.

  5. After rebooting, login the router with PuTTY.
    Fill in router’s IP(192.168.1.1 in most cases), left everything else on default(port 22 and Connection type SSH) and click “Open”.
    The login username is always root and password is the web password you set.

  6. Mount the USB drive
    Type the command in PuTTY window
    ls /dev/discs/disc0/
    and the result might look like this
    disc-partitions
    Now here is the tricky part. If you’re using a USB flash drive with only one partition, most likely, you will only see “disc” but not “part1” and “part2”. If you’re using a USB HDD with multi partitions you might expect an output similar to mine. Both are OK.

    If you see “disc” only, use the command line below to mount an ext3 USB drive to /mnt
    mount -t ext3 -o noatime /dev/discs/disc0/disc /mnt
    *Use mount -t ext2 /dev/discs/disc0/disc /mnt for ext2 drive

    For USB drive with multi partition, the command below will mount the first partition to /mnt. Adjust accordingly.
    mount -t ext3 -o noatime /dev/discs/disc0/part1 /mnt
    *Use mount -t ext2 /dev/discs/disc0/part1 /mnt for ext2 partition

  7. Now create and prepare necessary folders
    Type the commands below in PuTTY

    cd /mnt
    mkdir etc opt root
    touch optware.enable
    chmod 755 etc opt root
    mkdir opt/lib
    chmod 755 opt/lib
    cp -a /etc/* /mnt/etc/
    mount -o bind /mnt/etc /etc
    mount -o bind /mnt/opt /jffs

    So now we have a writable /etc and /jffs folders while they both reside in the USB drive. All other folders -- especially /bin, /usr and /sbin – will be left untouched to keep the change minimal. The /etc folder will also be handled with extra caution.

  8. Extract lib.tar and upload all files to router’s /jffs/lib folder by using WinSCP.
    Same as PuTTY, the username will always be root, the file protocol must be set to SCP. See the picture below
    winscp-login
    After that, ignore all warning messages and click “yes” all the way. You’ll see the file transfer Window then. Also please refer to DD-WRT Wiki if there is any other question.

    Now extract lib.tar(using WinRAR or 7Zip) and upload everything to router’s /jffs/lib folder.

    In the Putty window, run
    ls /jffs/lib
    to make sure all files are uploaded, then run
    chmod a+x /jffs/lib/*
    to set the properties.

  9. Install OpenWrt’s opkg
    Now in the PuTTY window, type

    cd /tmp
    wget http://downloads.openwrt.org/backfire/10.03/ar71xx/packages/opkg_513-2_ar71xx.ipk
    ipkg install /tmp/opkg_513-2_ar71xx.ipk

    After that, run the command to create the configuration file for newly installed opkg

    cat > /etc/opkg.conf << EOF
    src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/
    dest root /opt
    dest ram /tmp
    lists_dir ext /tmp/var/opkg-lists
    EOF

    Also notice the underlined /opt. In the future, all software will be installed to /opt folder in case some might still want to use internal flash. The /jffs folder is only necessary for initial setup.

  10. Set the startup script to make the changes take effect each time upon reboot
    Under DD-WRT’s web interface, Administration->Commands,  input the following command in the window then click “Save Startup”

    #!/bin/sh

    sleep 5
    #mount -t ext3 -o noatime /dev/discs/disc0/disc /mnt
    mount -t ext3 -o noatime /dev/discs/disc0/part1 /mnt
    #choose one for your drive, see Step #6

    sleep 2
    if [ -f /mnt/optware.enable ]; then
    mount -o bind /mnt/etc /etc
    mount -o bind /mnt/root /tmp/root
    mount -o bind /mnt/opt /opt
    else
    exit
    fi

    if [ -d /opt/usr ]; then
    export LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib'
    export PATH='/opt/bin:/opt/usr/bin:/opt/sbin:/opt/usr/sbin:/bin:/sbin:/usr/sbin:/usr/bin'
    else
    exit
    fi
     

    Reboot to make the change take effect.

  11. Test opkg package system
    After reboot, login with PuTTY again, run

    export LD_LIBRARY_PATH='/opt/lib:/opt/usr/lib:/lib:/usr/lib'
    export PATH='/opt/bin:/opt/usr/bin:/opt/sbin:/opt/usr/sbin:/bin:/sbin:/usr/sbin:/usr/bin'
    opkg update

    to check if opkg(the OpenWrt’s variant of ipkg) is installed and working properly.
    Then install/upgrade some base libraries and the busybox utility

    opkg install libc
    opkg install libgcc
    opkg install uclibcxx
    opkg install libncurses

    opkg install busybox

Almost done! There’re still some work and fine tune left which will be covered in the next part.

308 comments:

«Oldest   ‹Older   601 – 308 of 308
«Oldest ‹Older   601 – 308 of 308   Newer› Newest»

Post a Comment