Running Debian on a Router

Use Debootstrap to generate a Debian image and run it on your router using chroot.

First, you need to know what Debootstrap is.

Then read the first section of this document: EmDebianCrossDebootstrap.

You’ll see that there are several ways to achieve our goal. My router’s CPU is an MT7621, which uses the mipsel architecture.

I used the method in the second section: QEMU/debootstrap approach.

My host system is Ubuntu.

Following the instructions, install the required packages:

1
apt-get install binfmt-support qemu qemu-user-static debootstrap

Then create a directory, for example:

1
mkdir mipsel_debian

Now run the bootstrap command. Note that the architecture should be changed. After that comes the Debian release you want (e.g., Jessie), then the target directory you just created, and finally the Debian mirror.

1
debootstrap --foreign --arch mipsel jessie mipsel_debian http://ftp.cn.debian.org/debian/

Once that’s done, continue following the official instructions. Some steps need to be adapted.

1
2
3
4
5
cp /usr/bin/qemu-mipsel-static mipsel_debian/usr/bin
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C \
chroot mipsel_debian /debootstrap/debootstrap --second-stage
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C \
chroot mipsel_debian dpkg --configure -a

Now it’s ready. You can copy the whole directory to a USB stick, plug it into your router, SSH into the router, and chroot into the Debian environment.

Before using chroot, you need to mount some filesystems. Refer to Debootstrap for details:

1
2
3
4
mount /dev mipsel_debian/dev
mount /sys mipsel_debian/sys
mount /proc mipsel_debian/proc
cp /proc/mounts mipsel_debian/etc/mtab

Finally, chroot into Debian:

1
chroot mipsel_debian /bin/bash

If you plan to use SSH, you might also need to do the following before chroot:

1
mount /dev/pts mipsel_debian/dev/pts
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
This is Yumi’s blog where I share technology and life.
Built with Hugo
Theme Stack designed by Jimmy