Follow on from 01 Oct 08 APNIC Box – Linux on a Mikrotik 532a, Part 2

The device runs a 2.4.30 kernel on a debian woody (mipsel) environment. If anyone can contribute anything for 2.6.x and debian etch, that would be great.

Installation instructions:

#prepare your local cross compile environment
apt-get install toolchain-source
apt-get remove autoconf
apt-get install autoconf2.13
apt-get install fakeroot
tpkg-make mipsel-linux
apt-get install debhelper
apt-get install dpatch
debuild -uc -us
debinano -w /usr/bin/tkpg-install-libc
>>wget $SERVER/debian/dists/stable/main/binary-${debarch}/Packages.gz -O $TDIR/packageset.gz || exit 2
tpkg-install-libc mipsel-linux

#Build boot kernel
#Download linux-2.4.30
#Apply patch

mv config.mipsel .config
make ARCH=mips menuconfig
#Change kgcc to gcc
make ARCH=mips CROSS_COMPILE=mipsel-linux- dep
make ARCH=mips CROSS_COMPILE=mipsel-linux- vmlinuxcp vmlinux linuxrc
echo "root=/dev/ram0 ramdisk_size=8192" >kernel.params
echo "root=/dev/cfa2" >kernel.params
mipsel-linux-objcopy --add-section kernparm=kernel.params vmlinux
mipsel-linux-objcopy --add-section initrd=initrd.gz linuxrc
mipsel-linux-strip vmlinux
mkdir /rb/
cp vmlinux linuxrc /rb/

#Prepare your initrd
mkdir test
cd test
dd if=/dev/zero of=initrd bs=1024 count=8192
/sbin/mke2fs -F -b 1024 initrd
mkdir mnt
mount initrd -o loop ./mnt
cd mnt
tar -xzf root.tar.gz
mv debian-mipsel-root/* .
rm -f debian-mipsel-root
rm linuxrcmknod dev/cfa b 13 0
mknod dev/cfa1 b 13 1
mknod dev/cfa2 b 13 2
mknod dev/cfa3 b 13 3
mknod dev/cfa4 b 13 4
sed -e s/delo// usr/lib/debootstrap/scripts/woodycd ..
umount mnt
gzip initrd
mv initrd.gz /rb/

Prepare dhcpd and tftpd on your host machine so that the routerboard can network boot it’s setup

apt-get install dhcp
nano -w /etc/dhcpd.conf
>>default-lease-time 21600;
>>max-lease-time 2100;>>host rb500 {
>> hardware ethernet 00:0C:42:0A:6A:7A; #mac address of your routerboard's eth0
>> filename "/linuxrc";
>> fixed-address;
>>}>>subnet netmask {
>> option subnet-mask;
>> next-server; #tftp server ip
>> option broadcast-address;
>> option routers;
>>}apt-get install atftpd
remove atftpd from /etc/inetd.conf
killall -HUP inetd
atftp --daemon /rb/

Set your machine up for masquerading so the device has network access for setup.

echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -X
iptables -t nat -I PREROUTING -i eth0 -j ACCEPT #internal interface
iptables -I FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE #external interface

At this point, you’re ready to start your routerboard and begin the setup. You have an initrd (initrd.gz) and a kernel (linuxrc), as well as the host serving these via DHCPD/TFTPD. Connect your RB via serial console and ensure that the it is set to Ethernet boot. The vmlinux that you made will be used after setup. You can use gtkterm/minicom on Linux, or PuTTY/Hyper Terminal on Windows. If you’re seeing nothing or a load of junk output to your console, a) make sure that the cable is correct and connected, b) Make sure your connection settings are: 57600 8N1

For the installation process via your serial terminal:

Run through installer
Create 4M partition on /dev/cfa1 (0x27)
Create 475M linux partition on /dev/cfa2 (ext3)
Allocate remaining space to /dev/cfa3 (swap)
* Perform install

Once install is complete of base system, execute a shell.
Generate a new kernel on the host machine

cd /var/www
cp /usr/src/linux-2.4.30/vmlinux ./vmlinux
echo "root=/dev/cfa2" > kernel.params
mipsel-linux-objcopy --add-section kernparm=kernel.params vmlinux
mipsel-linux-strip vmlinux* wget this vmlinux onto the routerboard
dd if=./vmlinux of=/dev/cfa1Edit /target/etc/inittab with nano-tiny
t0:23:respawn:/sbin/getty -L console 115200 vt100

cd /target/
mknod dev/cfa b 13 0
mknod dev/cfa1 b 13 1
mknod dev/cfa2 b 13 2
mknod dev/cfa3 b 13 3
mknod dev/cfa4 b 13 4

* Configure setup options and root password

apt-get update
apt-get remove ppp pppconfig tasksel setserial info nvi pppoe pppoeconf ed fdutils bsdmainutils adduser man-db console-common gettext-base groff-base manpages modconf libreadline4 libgdbmg1
apt-get install wget dropbear debconf-english localepurge [Don't select any locales]
apt-get upgrade
apt-get clean; rm -rf /var/lib/dpkg/*-old

And you’re done. 😎

These are the notes that I took and corrected throughout my own installation process. I’m sure that there are corrections and a number of explainations required – please do contribute or comment. Thanks!