Installing OpenWRT on Raspberry Pi 4 using USB boot device

; Date: Wed Jul 06 2022

Tags: Raspberry Pi »»»» OpenWRT

OpenWRT is a professional grade package for Internet routers. With a little work, running OpenWRT on the Raspberry Pi 4 can make an excellent router. But, it's best to use a regular disk rather than an SD card, for reliablity.

Your Internet router must be reliable, yes? Don't we install Internet, run it 24/7 all year long, leaving the router on a shelf to gather dust for a couple years? That requires robust hardware chaoices that will remain running without maintenance for years.

The default OpenWRT installation on Raspberry Pi uses a microSD card, as is typical of Raspberry Pi projects. But, how can we expect a system running off a micro-SD card to last for years at a time? SD cards wear out in continuous use scenarios. For example, I have an ODROID NAS device that has an excellent design, but it boots off an SD card. After a few months that SD card wore out, and the device crashed, fortunately with no data loss.

The point is that devices like a NAS, or a router, must be reliable, and it does not make any sense for them to run off an SD card. It simply does not make sense to install OpenWRT on Raspberry Pi on the built-in SD card. Instead, what makes sense is to install it on a regular disk drive, mounting it in an external USB enclosure, using it to boot the Raspberry Pi.

As we noted in a recent article, How to Boot a Raspberry Pi 4 or 400 from a USB drive , it's fairly easy to set up a Raspberry Pi 4 to boot from a USB drive, and the result will be more reliable and performant.

Other articles in this series:

Unfortunately the standard OpenWRT build for Raspberry Pi is hardcoded to boot from the SD card. Fortunately there's a simple remedy.

Getting and installing the OpenWRT build for Raspberry Pi

The OpenWRT website has documentation specific to the Raspberry Pi line. Interestingly, the RPI 1 is supported. Somehow I don't think it's worth dusting off my RPI1 to try that out, so let's stay focused on the RPI4.

See: (openwrt.org) https://openwrt.org/toh/raspberry_pi_foundation/raspberry_pi

The installation on Raspberry Pi is very simple.

  • Download the selected image to your computer. There is a suggested image on that page. Another way is to go to the OpenWRT downloads page, click on the Table of Hardware link, which takes you here: (openwrt.org) https://openwrt.org/toh/views/toh_fwdownload Under the Brand column, enter Raspberry Pi in the box, then hit ENTER. A list of builds will be available.
  • Once downloaded, burn the image to a USB drive or SD card. I used Raspberry Pi Imager, but I hear that Balena Etcher works as well.
  • Attach the USB drive (or SD card) to the Raspberry Pi, connect it to your ethernet, and turn it on.

I suggest, for the initial boot, to have it connected to a monitor and keyboard. Once OpenWRT is setup you can disconnect both and administer the machine via a web application.

While booting, you'll see a zillion text messages scrolling by. If everything is working, you'll eventually see messages that the system is ready, and that you can hit RETURN to enable console mode. If you do that you'll immediately see a root shell, and also be informed that the underlying operating system is BusyBox.

If it's successful, the OpenWRT web GUI will be available at 192.168.1.1. Log in using the root user name and no password. Make sure to change the password right away, then set about configuring the system.

Correcting issues to boot OpenWRT from a USB drive on the Raspberry Pi 4

The previous section discussed the happy path, meaning the path that will simply work. But, I ran into two problems with getting OpenWRT to work from a USB drive.

I didn't record clear evidence of the first issue. There was no SD card present, only the USB drive on which I'd burned the OpenWRT distribution. The behavior was that upon booting the Raspberry Pi 4 was that the bootloader showed an image like this:

This image demonstrates that the device was trying to boot from USB. However, it kept cycling through the BOOT_ORDER sequence, spending a few seconds on the USB drive, trying the SD card, then cycling back to the USB drive.

The solution for that issue was to format the drive to have a single partition before running the Imager software to burn the OpenWRT image.

The second is that the boot process stops at some point, and the console had this message

Notice that it is waiting for the root device /dev/mmcblk0p2. That device name is for the root partition on the SD card. Since we're booting from a USB drive, there will never be a /dev/mmcblk0p2 device show up.

Notice that a few lines above messages that sda was recognized, and that it recognizes the sda1 and sda2 partitions. Since this the USB drive is a Linux boot disk, sda1 maps to /boot and sda2 maps to /root.

To fix this, first attach your USB device to the computer you used to burn the OpenWRT image. The /boot partition should show up, since it is a FAT partition. We need to edit the cmdline.txt file and change the root= reference.

console=serial0,115200 console=tty1 root=/dev/sda2 rootfstype=squashfs,ext4 rootwait

The result should look like this, and the important part is root=/dev/sda2. Initially, you'll find that root= refers to /dev/mmcblk0p2. As said above that is the SD card, which will never show up. The device name /dev/sda2 is for the root partition on the first USB device, which is what will show up.

Once you make this change, the Raspberry Pi will boot into OpenWRT from the USB drive. You can then proceed with usual OpenWRT configuration.

By default it will come up with the IP address of 192.168.1.1, with no root password. You MUST immediately change the root password to something reasonable, right?

Summary

It's relatively easy to install OpenWRT on a Raspberry Pi, even when using a USB drive. The step, editing cmdline.txt, is not difficult.

Having installed OpenWRT and kicked the tires, I'm not entirely convinced this is the choice for me. For instance, the OpenWRT installation consumes only 14GB of drive space, stranding the other 460GB on the disk I used. I had thought this would support using this router with Samba so it does dual service as a network attached storage device. That's still to be explored. Another package, RaspAP, seems to be more suitable in that regard.

I am wondering why the OpenWRT team doesn't discuss booting from USB in their documentation. It's clear to me that an SD card is not going to provide reliable service for years at a time. Why base your most critical device on something that will almost certainly fail in a few months? As they say, a house built on sand will wash away in the next storm.

About the Author(s)

(davidherron.com) David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.