It is currently 01 Aug 2010, 05:36





Post new topic Reply to topic  [ 9 posts ] 
 Booting Debian on Linksys WRT54GL: a complete HOWTO 
Author Message
Administrator
User avatar

Joined: 01 Dec 2007, 20:56
Posts: 65
Location: Poland
Post Booting Debian on Linksys WRT54GL: a complete HOWTO
Introduction

Why Debian? OpenWRT distribution offers very limited set of features and software comparing to standard Linux distributions. That's pretty obvious when comparing WRT and PC capacity and performance. But, since we have MMC hack available, we can now actually run Debian on our Linksys as well. There is a MIPS version of Debian already available as one of standard architectures.

There are several tutorials out there on how to run Debian on WRT, but all of them involve just chroot-ing over NFS and has nothing to do with native Debian boot. This tutorial shows you how to install Debian distribution on MMC card, how to configure it for WRT environment and finally how to make your router boot directly from it.

See video showing the boot process:



If you want that on your router, read on...

This tutorial was tested on Linksys WRT54GL v1.1 and it worked, but I'm still not responsible for any damage you will cause to your router, especially if you try that with other router versions.

Requirements

Here is what you will need for this hack:
  • serial port mod
  • MMC mod
  • at least 512MB SD/MMC card
  • SD/MMC card reader
  • a standalone desktop PC or laptop with Debian Linux installed and Internet access

I will not describe serial and MMC mods here, as it is already well documented at openwrt.org.

My Debian installation occupies over 300MB of MMC card + 64MB for swapfile. That's why I recommend at least 512MB. I think it should be possible to install on 256MB as well, but you will quickly run out of space. I personally use 1GB card.

Also make sure that your card reader is properly handled by Linux. Put the SD/MMC card into it and plug the reader to a PC running Debian. You should see kernel debug messages telling you that a new block device is available. If this is not the case, you could try mounting Debian system over NFS and doing everything from there instead of a standalone PC, but it will last much longer.

The Hack

You will probably have at least one partition already created on the card, but we will use entire disk only (/dev/sda here). This is due to partitioning being broken in GPIO MMC driver on WRT.

Prepare ext2 file system and swapfile for future use on the card (remember, don't use partitions like sda1 as it will not work on WRT, use entire disk only!):

Code:
# mke2fs /dev/sda
# mount /dev/sda /mnt
# dd if=/dev/zero of=/mnt/swapfile bs=1M count=64
Prepare bootstrap Debian system on the card (use your local Debian mirror as the last parameter for best performance):

Code:
# debootstrap --arch mipsel --foreign etch /mnt http://ftp.debian.org/debian
Insert MMC into Linksys router and boot OpenWRT. Install MMC and loopback packages with ipkg (load both kernel modules with insmod if not loaded automatically). Then, mount MMC, /proc and swapfile on it:

Code:
# mount /dev/mmc/disc0/disc /mnt
# mount -t proc /dev/null /mnt/proc
# losetup /dev/loop/0 /mnt/swapfile
# mkswap /dev/loop/0
# swapon /dev/loop/0
Now we can chroot into the bootstrap Debian and continue installation:

Code:
# chroot /mnt /bin/bash
# debootstrap/debootstrap --second-stage http://ftp.debian.org/debian
When second stage is done, install some more software packages for convenience using apt-get (some editors, utils, sshd, etc.):

Code:
# apt-get install mc ntpdate dnsutils modutils nano ssh
# apt-get clean
Now we need to configure the system for WRT environment, which is a bit specific:
  • we don't have RTC available
  • the kernel we will use has devfs support enabled
  • our console will be on serial port
  • swap is on a file and not on a partition
  • we need to remove unnecessary daemons to save RAM

Edit /etc/fstab and put the following lines into it:

proc /proc proc defaults 0 0
/dev/mmc/disc0/disc / ext2 errors=remount-ro 0 1
/swapfile none swap sw 0 0


Edit /etc/network/interfaces and configure your network parameters, for example:

auto lo eth0
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp


Edit /etc/init.d/checkroot and locate part of the script responsible for executing fsck. Remove the entire section, as executing fsck on boot up will put your router into an endless loop due to the lack of RTC. Debian will try to fix time/date 'problems' on the card with every reboot, and with every reboot the 'problem' will obviously remain.

Edit /etc/inittab and comment out all console lines. Put serial console line instead:

co:2345:respawn:/sbin/getty -L 115200 tts/0 linux
If you have installed ntpdate with apt-get (recommended), then edit /etc/default/ntpdate and set NTPDATE_USE_NTP_CONF to 'no'. This will cause ntpdate to sync system clock at boot time using predefined set of NTP servers.

Remove any unnecessary boot up scripts and daemons (the below set of links to remove is just an example, you need to decide yourself what you don't need - just leave the system-critical stuff in place, like mount scripts, etc.):

Code:
# cd /etc/rcS.d
# rm S20modutils S50hwclock ...
# cd /etc/rc2.d
# rm S20inetd S89cron ...
# cd /etc/rc0.d
# rm K20inetd K11cron ...
# cd /etc/rc6.d
# rm K20inetd K11cron ...
Don't forget to set root password as well. Now we can leave the bootstrap and unmount everything:

Code:
# exit
# umount /mnt/proc
# swapoff /dev/loop/0
# losetup -d /dev/loop/0
# umount /mnt
Download kernel image that I compiled. It contains optimized MMC and GPIO diag (with predefined 0x9c mask) drivers built in (so you don't have to worry about them at startup). It also has modified kernel boot parameters which cause mounting MMC card as the root file system.

Attachment:
openwrt_kernel_for_debian.zip
Flash the image using flash.sh script located in OpenWRT development tree or mtd utility from within booted OpenWRT. Be ready to reflash with working OpenWRT image if something goes wrong. Reboot the system and if all goes well, you should see Debian login prompt after a while.


You do not have the required permissions to view the files attached to this post.

_________________
Regards,
www.hwhack.com admin


17 Apr 2008, 08:27
Profile WWW

Joined: 09 May 2008, 02:39
Posts: 3
Location: China
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
Hi,
I met an error: "mount: Mounting /dev/mmc/disc0/disc on /mnt failed: Invalid argument" when I do "mount /dev/mmc/disc0/disc /mnt". How can I solve this problem? Thanks first!


11 May 2008, 14:36
Profile
Administrator
User avatar

Joined: 01 Dec 2007, 20:56
Posts: 65
Location: Poland
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
It probably means you have no ext2 filesystem support in your OpenWRT. You need to install it first with ipkg (altough I don't remember the name of the package - you'll need to find it yourself).

Also make sure that you have MMC module loaded first and that your card was detected properly.

Let me know if that worked.

_________________
Regards,
www.hwhack.com admin


12 May 2008, 13:40
Profile WWW

Joined: 09 May 2008, 02:39
Posts: 3
Location: China
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
rawsock wrote:
It probably means you have no ext2 filesystem support in your OpenWRT. You need to install it first with ipkg (altough I don't remember the name of the package - you'll need to find it yourself).

Also make sure that you have MMC module loaded first and that your card was detected properly.

Let me know if that worked.

Yes. I have kmod-ext2 installed and have MMC modules loaded showing "Using mmc.o", but I still met the same situation above.


13 May 2008, 02:11
Profile
Administrator
User avatar

Joined: 01 Dec 2007, 20:56
Posts: 65
Location: Poland
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
- Make sure you are able to mount any other MMC card. Did you test your MMC hack before?
- Use the latest OpenWRT distribution
- Verify with lsmod that ext2 module is loaded
- Verify that '/dev/mmc/disc0/' directory is not empty
- If yes, try the 'mke2fs' command on the MMC again, but this time do it on OpenWRT (with '/dev/mmc/disc0/disc' argument obviously). Did it work?

If all above tests pass, maybe you have some incompatible MMC card reader. Try to format the disc on OpenWRT and then install bootstrap Debian using regular Linux and card reader. Remember to never use partitions, use entire disc only (/dev/mmc/disc0/disc).

_________________
Regards,
www.hwhack.com admin


13 May 2008, 08:50
Profile WWW

Joined: 09 May 2008, 02:39
Posts: 3
Location: China
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
Quote:
Install MMC and loopback packages with ipkg (load both kernel modules with insmod if not loaded automatically).

Could you tell me how to install loopback packages with ipkg?
Many thanks.


19 May 2008, 17:14
Profile
Administrator
User avatar

Joined: 01 Dec 2007, 20:56
Posts: 65
Location: Poland
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
So you are one step further. That's good.
You can install it using:

ipkg install losetup
ipkg install kmod-loop

_________________
Regards,
www.hwhack.com admin


19 May 2008, 20:18
Profile WWW

Joined: 06 Dec 2008, 16:44
Posts: 1
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
I have a big interest in this. I've had no problems getting Debian running on my Dlink DNS 323 as well as other products. I've did work with the ASUS routers, but I have a ton of Linksys WRT's laying around with SD cards. Overall your directions seem relatively easy, but I'm not sure why the serial port mod is needed. From what I understand you need to setup the SD CARD on another Linux machine. So long as the SD CARD mod is working, after flashing with your custom firmware you would insert the sd card and boot the Linksys router. If all goes well you should have a working debian install correct?

I'll read over your directions a couple more times, but what I'm really needing is help in getting the Wireless Broadcom working. Have you been able to get Debian to control the Wireless of the router? I don't really care about having WPA or WEP, I just need Debian to allow the router to run in Open AP mode and allow people to access the Internet.


06 Dec 2008, 16:50
Profile
Administrator
User avatar

Joined: 01 Dec 2007, 20:56
Posts: 65
Location: Poland
Post Re: Booting Debian on Linksys WRT54GL: a complete HOWTO
Well, in fact, you don't need the serial mod. However you must be sure to setup everything correctly, install sshd etc., so that you will be able to remotely login after successful bootup. If you are doing this for the first time, it is nearly impossible to do everything right. There is always some problem with bootup and you will end up needing a serial port mod anyway for debug. So, try it once with serial mod and you do the same steps for other routers without it.

As for the wireless - I didn't try that, but it should definitely work in Debian as long as you have a proper driver. I currently do not remember if the driver is build in the above kernel image. If not, you might need to build it for yourself or try to load one from OpenWRT.

_________________
Regards,
www.hwhack.com admin


07 Dec 2008, 13:54
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © phpBB Group, phpBB SEO.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.