Installing Openwrt On A Mikrotik Routerboard

Posted on
Installing Openwrt On A Mikrotik Routerboard 4,5/5 12 votes
  1. Mikrotik Routerboard Winbox
  2. Mikrotik Metarouter
  3. Mikrotik Routerboard 1100

Introduction

This document contains a step-by-step process for installing the Commotion software on MikroTik routers. If you have a new, in-the-box MikroTik device, this guide is for you.

We have written this guide because the Open Technology Institute is expanding Commotion router software support for MikroTik routers. The software is an alternative operating system, similar to Linux for +your home or office computer. MikroTik hardware comes from the factory installed with their custom software, called RouterOS - just like a new computer usually comes with Microsoft Windows or Mac OSX installed. Installing Commotion on your router instead will add new features to your router, including the ability to mesh with other routers that use Commotion.

  • Routers: What is the advantage of. X86 hardware or on MikroTik's own 'RouterBoard' hardware which. 3G/4G data cards similar to OpenWRT/DD-WRT.
  • OpenWrt is a Linux distribution primarily targeted at routing on embedded devices. [*] Devices with NAND flash (mostly Mikrotik). Target Profile. Press x to leave the setup and let the RouterBOARD reboot. If all has been.

The instructions for installing Commotion on MikroTik devices are much more complicated than those for Ubiquiti or TP-Link hardware. The guide assumes you are familiar with Linux and working on the command line. The installation process should take about an hour, or longer. If these steps do not work for you, or if you have a router that failed to properly flash Commotion or will not respond in any way, then please see the External Resources section.

Time required: 1 hour or more.

Materials + Supplies Needed

Copy the file openwrt-ar71xx-mikrotik-vmlinux-initramfs-lzma.elf to a clean directory like ~/tftproot/. Rename the file to vmlinux (this helps when testing other images).

To install Commotion, you will need the following items on-hand:

  1. A computer with an Ethernet port.
  2. The MikroTik router and its power supply (or a 24V PoE supply).
  3. Access to a power outlet.
  4. One Ethernet switch with two open ports.
  5. Two Ethernet cables.
  6. A computer with a serial port, or a USB-to-Serial adapter.
  7. A serial cable to connect to a DB-9 male serial console
  8. An Internet connection or the appropriate Commotion software image.

If your computer doesn’t have a serial port, you will need a USB to serial adapter. Some examples of these can be found in the External Resources section.

Download Commotion

Download the MikroTik Commotion images for your hardware:
https://commotionwireless.net/download/routers

You will need three files to fully install Commotion on your MikroTik routerboard device:

Routerboard
  • openwrt-ar71xx-nand-vmlinux-initramfs-lzma.elf
  • openwrt-ar71xx-nand-rootfs.tar.gz
  • openwrt-ar71xx-nand-vmlinux-lzma.elf

Save the file somewhere you can access easily later. A good place to save the file is on your Desktop, or in your Downloads directory.

Configure your computer

The Commotion software cannot be written directly to the router’s storage via the update system in Mikrotik's RouterOS. So installing Commotion is a two step process:

  • First, boot the router from a DHCP server on the local area network. A TFTP server then provides an .ELF firmware file that is loaded into the router's memory.
  • Second, a Web server provides a separate firmware file on the local area network for permanent installation.

These server packages must be installed on whatever computer you are installing the Commotion software from. For a guide on installing and running these servers, please see the MikroTik Installation Server Setup. Read through and perform the necessary steps in those instructions before coming back to this document and proceeding with the installation.

Setup the Hardware

  1. Unpack the MikroTik router and install the external antennas (if the unit has them).
  2. Turn off your computer’s Wi-Fi, if it is on.
  3. Plug in one Ethernet cable to the Switch, then plug that cable into your computer’s Ethernet port.
  4. Plug in a second Ethernet cable between the Switch and the Ethernet port on the MikroTik router.
  5. Plug in the USB-to-Serial adapter to your computer, and connect the DB-9 connector to the Serial Console port on the MikroTik router.

Don’t plug in the router yet - there are a few more setup steps.

Setup the Serial Console

If you don’t have a terminal program that can access serial port consoles installed, you can use minicom or something similar. Open a terminal and install the package by typing the following:

You will need to configure minicom to the proper port andt receive an IP, set an IP address for the Ethernet interface on the node statically. Run this command:

After this, you can load the image files from the computer to the note. This command assumes that your computer's IP address is 192.168.10.254, as recommended in the guide above:

If successful, your serial console should display information indicating that the device is being flashed, and eventually it will reboot.

Once the device is rebooting, use the commands below on your computer to turn off dnsmasq and lighttpd:

You should now set your computer’s Ethernet port to receive an IP address via DHCP. When the router has completely rebooted, it will provide your computer with a DHCP lease. Once this has happened, you can open a web browser, and in the URL bar enter http://thisnode - the address of the administration page on the Commotion node. Next, run the Commotion setup wizard and configure the settings for your network. If you want to read more about this process, see the document Configure Commotion.

External Resources

If your computer doesn’t have a Serial port (most computers made in the past 5 years do not), you will need a USB to serial adapter, such as these models:

  • Sabrent USB 2.0 TO Serial DB9 male - model # CB-RS232
  • TRENDnet USB to Serial Converter - model # TU-S9
  • StarTech USB to RS232 Serial DB9 Adapter - model # ICUSB232PRO

In addition, you will likely need a DB-9 “turnaround” - also known as a gender changer, such as these:

  • Tripp Lite DB9 F/F Gender Changer - model # P150-000
  • StarTech DB9 RS232 Serial Null Modem Adapter F/F - model # NM9FF

Documentation

  • Commotion Construction Kit
    • Installing + Configuring

Mikrotik Routerboard Winbox

The Mikrotik Routerboards are cheap and versatile embedded platforms that can be used for routers, WiFi APs and the like. In a rather wide range of products, I happen to have access to the RB411 and the RB750 two devices of very different properties. While the RB750 is effectively a 5 port 10/100 Mbit Ethernet switch with an Atheros AR71xx CPU on it, the RB411 has the same CPU with one Ethernet port and a Mini PCI slot as well as a serial port (and a beeper ;)). Because of their price (around 40 €), both are very interesting targets to do some experiments with them. Unfortunately, they come with Mikrotiks RouterOS which seems to be a modified Linux that officially cannot be modified. Interestingly, the RB do not ship with a GPL and as far as I have heard, Mikrotik does not publish the source code as required by the GPL. So, who wants RouterOS anyway? 😉

Although I do not have other Mikrotik products, I assume that the OpenWRT flash procedure is similar for products using RouterBOOT as bootloader and the Atheros AR71xx CPU. However, this guide comes without warranty, everything you do is at your full risk. Although I was unable to do so, there is a certain risk of permanently bricking your device.

The process of flashing the Routerboard has 5 major steps:

  1. Prepare an OpenWRT Ramdisk Image
  2. Prepare the OpenWRT target Image
  3. Configure the TFTP and DHCP Server
  4. Boot the Routerboard using the Ramdisk Image
  5. Flash the Target Image

Prepare an OpenWRT Ramdisk Image

Compiling OpenWRT from the SVN is actually more straight forward than you might imagine. Take your favorite Linux Distribution (Ubuntu in my case), check our the SVN, configure it and hit make. There you go.

  1. Get the source code
    Check out the latest and greatest version of OpenWRT:

    I have used revision 27019.

  2. Configure OpenWRT according to your needs

    While you are of course free to select all the packages you need and deselect those you do not need, you have to set the following options to make it work in the Routerboards:

  3. Build it
    The build process of OpenWRT takes a long time, but is very simple:

    The result image is located in the bin/ar71xx directory and is called openwrt-ar71xx-nand-vmlinux-initramfs.elf.

Prepare the OpenWRT target Image

  1. Configure OpenWRT according to your needs

    This time, you have to change the Target Images to tar.gz as follows:

  2. Build it

    The target image consists of two files in the bin/ar71xx directory:

    • Kernel Image: openwrt-ar71xx-nand-vmlinux.elf
    • Root File System: openwrt-ar71xx-nand-rootfs.tar.gz

Configure the TFTP and DHCP Server

  1. Configure your network Interface
    The network interface to which the Routerboard is connected must have a unique IP with a DHCP running on it. To make debugging easier, it is usually a good idea to directly connect the Routerboard to your NIC without other devices involved.
    Configure the Interface within the subnet 192.168.1.0/24 (OpenWRTs default subnet) but try to avoid 192.168.1.1 (OpenWRTs default IP). I have used 192.168.1.2.
  2. Install DHCP and TFTP Servers
    You will need a DHCP Server to assign an IP address to the Routerboard for the flash process. Also, the DHCP server tells the board which file to use as image. Frankly, the tftp Server is responsible to provide the image file to the RB.
    On Ubuntu Linux, I have used these packages:
  3. Configure the DHCP Server
    The DHCP Server does not need much configuration. I use the following as /etc/dhcp3/dhcpd.conf:

    You may want to modify the IP range to match your subnet, the hardware ethernet MAC address of your router board, the next-server address of your tftp server and the filename of the ramdisk image that should be booted over the network.

  4. Configure the TFTP Server
    Edit /etc/default/atftps to avoid running the daemon over inetd. My file looks like this:

    You can see, that the tftp server will look for image files in /tftpboot. Either change this directory or copy the OpenWRT ramdisk image (openwrt-ar71xx-nand-vmlinux-initramfs.elf) to /tftpboot.

  5. Apply the changed configuration

Booting the Ramdisk Image

The purpose of this step is to have a ramdisk version of OpenWRT running on the routerboard. This is a good basis for our flashing process and can also be used to test images without flashing them. This involves the following steps:

  1. Connecting the Routerboard
    Connect port 1 of the Routerboard with the Ethernet port that your DHCP and TFTP server listens on.
  2. Boot the Routerboard
    Now press and hold the “RES” button of the router board and connect power. Both LEDs (PWR and ACT) will be constantly on, keep pressing the button. After some seconds the “ACT” LED starts flashing, keep pressing. After some more seconds, the “ACT” LED turns off, now you can stop pressing the button. The board will now try to obtain an IP address via DHCP/BOOTP and then download and boot the Ramdisk image. You can see this activity by looking at the appropriate log files:

    You should see something like this:

    Sit and wait until 192.168.1.1 starts replying to pings. Now you can log into the board using telnet (ssh login is not possible, since no password is set as of yet).

  3. Flash the target Image

  4. Erase the flash memory
    You can look at the existing flash partitions by looking at /proc/mtd.

    Now, erase the content of “kernel” and “rootfs”:

  5. Create new file systems
    After erasing the content of the flash, we now need to create new yaffs2 partitions. In principle, we could also make the rootfs ext2/3/4, but I have not tried this. The kernel partition has to be yaffs2 as far as I know to be compatible with the bootloader.
  6. Copy the images onto the Routerboard
    Copying the images onto the routerboard can be done in multiple ways, I have used secure file copy (scp). First, we have to create a password for the root user. On the routerboard, execute

    and set a password. On the linux PC, you can now copy the images onto the Routerboard:

  7. Flash the images onto the Routerboard
    Flashing the images is simple, once you have them on the Routerboard. First, the kernel:

    Now the root filesystem:

  8. That’s it, you are done
    Finally, reboot the routerboard.

    After some while, you should be able to ping the board at 192.168.1.1.

What if the Routerboard does not boot?

Mikrotik Metarouter

Do not panic. If the board is not reachable at 192.168.1.1 after some minutes, something must have gone wrong. You can always recover the boards using Mikrotiks Netinstall. Also, you can start again at the point where the ramdisk image should have booted. Unfortunately, the RB750 does not have a serial port, debugging problems with the linux boot process is probably *very* annoying.

Mikrotik Routerboard 1100

The flash process for the Routerboard 411 is almost similar to the process for the RB750 – only the flash layout is a bit different and hence the number of the target partitions have to be changed. Apart from that, you can use the exact same procedure. However, since the RB411 offers a serial port, debugging is much more convenient.

Booting the Ramdisk Image

The purpose of this step is to have a ramdisk version of OpenWRT running on the routerboard. This is a good basis for our flashing process and can also be used to test images without flashing them. This involves the following steps:

  1. Connecting the Routerboard
    Connect the Ethernet port of the Routerboard with the Ethernet port that your DHCP and TFTP server listens on.
  2. Configure the Bootloader
    Connect a serial cable to the serial port of the routerboard using the settings 115200 8n1. The boot process should look similar to this:

    Press any key and you will end up here:

    Change the “boot device” (o) to “boot over Ethernet” (e). Reboot with x.

  3. Boot the Routerboard
    While looking at the serial terminal, you should see something like:
  4. Flash the target Image

  5. Erase the flash memory
    You can look at the existing flash partitions by looking at /proc/mtd.

    Now, erase the content of “kernel” and “rootfs”:

  6. Create new file systems
    After erasing the content of the flash, we now need to create new yaffs2 partitions. In principle, we could also make the rootfs ext2/3/4, but I have not tried this. The kernel partition has to be yaffs2 as far as I know to be compatible with the bootloader.
  7. Copy the images onto the Routerboard
    Copying the images onto the routerboard can be done in multiple ways, I have used secure file copy (scp). First, we have to create a password for the root user. On the routerboard, execute

    and set a password. On the linux PC, you can now copy the images onto the Routerboard:

  8. Flash the images onto the Routerboard
    Flashing the images is simple, once you have them on the Routerboard. First, the kernel:

    Now the root filesystem:

  9. Reconfigure the Bootloader
    Reboot the board and enter the bootloader. Now change the boot device (o) to “boot from NAND, if fail then Ethernet” (n). Save settings with x.
  10. That’s it, you are done
    After some while, you should be able to ping the board at 192.168.1.1.

What if the Routerboard does not boot?

Do not panic. Look onto the serial terminal to see, at which state the Routerboard is stuck. You can always recover the boards using Mikrotiks Netinstall.