openwrt on x86-64

Installing openwrt on x86-64

Most openwrt installs are on small embedded routers and you are working with a build for that particular router type that already includes the right kernel modules, knows about the flash size and layout, etc. But it’s also possible to install on normal x86 PC hardware, and the openwrt project provides builds for both x86 32bit and 64bit hardware. This is particularly interesting if you require hardware features that PC’s can provide that embedded routers cannot (CPU, RAM, more network devices, storage, etc). For example, currently doing SQM on a ~100mbit cable modem link requires more CPU than embedded routers can provide.

However, “PC” is a pretty broad term and depending on your particular hardware you might need to install particular kernel module packages, or make decisions about where and how things are installed, network devices are mapped, filesystem types, etc. depending on your goals. So it might take a little more work than the average openwrt router install. Luckily openwrt is designed to be very modular and flexible, so whatever you plan to do it’s probably possibly without much extra effort.

x86-64 builds

Currently the features that I need are only in the in development “Chaos Calmer” (CC) release, so until it actually releases I am using “trunk” builds, which get generated on a (mostly) daily basis. The x86-64 builds are at downloads.openwrt.org/snapshots/trunk/x86/64

Here are the files in the directory:

File Extension Description
openwrt-x86-64-vmlinuz Linux kernel for x86-64 build
config The kernel config file for the above kernel
openwrt-x86-64-rootfs.tar.gz tar.gz of filesystem image of openwrt root filesystem
openwrt-x86-64-rootfs-ext4.img.gz ext4 filesystem image (compressed) of openwrt root filesystem, same contents as above
openwrt-x86-64-combined-ext4.img.gz disk image (compressed) containing
partition type size fs used notes
1 Linux 4MB ext4 2.3MB marked bootable, ext4 fs, 2.3MB used, boot/grub/grub.cfg, boot/vmlinuz
2 Linux 48MB ext4 6MB same contents as root.tar.gz
MBR with grub. grub is configured to boot the kernel in partition 1, boot/vmlinuz and set root=PARTUUID to the id for partition 2. Configured to use both vga and serial (ttyS0,115200n8) for both grub and linux console. noinitrd(just mounts root)
openwrt-x86-64-rootfs-squashfs.img squashfs filesystem image of openwrt root filesystem, same contents as above plus /dev/console
openwrt-x86-64-combined-squashfs.img similar to combined-ext4 above, but partitions are squashfs instead of ext4
OpenWrt-ImageBuilder-x86-64… Image Builder for x86-64, to build custom images without compiling
OpenWrt-SDK-x86-64… SDK Toolchain for compiling single userspace packages
OpenWrt-Toolchain-x86-64… Full Toolchain used to build these files
packages/ directory of packages for trunk x86-64, opkg will pull packages from here
md5sums md5 checksums of the files in this dir, so you can check the copies you downloaded are correct
sha256sums sha256 checksums of the files in this dir, so you can check the copies you downloaded are correct

Installing

Using the combined images

As you can see above, the “combined” images are bootable and contain partitions with the needed components to boot openwrt: bootloader, kernel, and root filesystem all setup to work correctly. They are ready to be written directly to a disk device (USB flash drives, USB Harddrive, SATA Harddrive, etc) and booted by the PC BIOS.

combined-ext4

This image uses the normal Linux ext4 filesystem which is read-write when booted. Any changes you make to the filesystem persist across boots.

Using another system (or on the target system, booted with a “live CD”, etc) you can write the raw image to the drive you intend to use. This image is compressed, gunzip it first or use zcat

# zcat openwrt-x86-64-combined-ext4.img.gz > /dev/sdX

where X is the drive you want to OVERWRITE. WARNING: if you overwrite data you care about you will be SAD :(
(MacOSX disk-utility should also be able to write raw images OK, I have no idea how to do it on Windows)

This will result in the drive having a partition table containing 2 partitions, and only consuming ~53MB of the drive. After the drive is created, if there is free space you would like to use, you can

  1. extend the second partition and it’s filesystem to give you more space in the root filesystem. Or..
  2. instead just create an additional partition and ext4 filesystem and then configure openwrt to mount the extra partition.

combined-squashfs

This image uses a “squashfs” compressed filesystem which, when booted is read-only but a second “overlay” read-write filesystem is mounted on top of that in order to store changes. Any changes you make persist across reboots. This is the method used on most “home router” embedded devices because their internal storage is very small and this allows much more to fit on the device.

Using another system (or on the target system, booted with a “live CD”, etc) you can write the image to the drive you intend to use.

# cat openwrt-x86-64-combined-squashfs.img > /dev/sdX

where X is the drive you want to OVERWRITE. WARNING: if you overwrite data you care about you will be SAD :(

This will only use about 6.3MB of the drive. If you want to use more space on the drive, you cannot (easily) extend the squashfs, but you can create an additional partition and filesystem and configure openwrt to mount that on boot.

Creating your own

Because all the individual components are provided, you can create your own installs, or add openwrt to other existing installs. Some examples:

  1. Create your own partitions and filesystems of larger sizes, then untar the openwrt-x86-64-rootfs.tar.gz tarball in the root partition and put the openwrt-x86-64-vmlinuz kernel in the /boot parition and then install and configure the bootloader to point at the kernel and new partition as root.
  2. Same, but just write either the openwrt-x86-64-rootfs-ext4.img.gz or openwrt-x86-64-rootfs-squashfs.img to it’s own partition (any size, as long as it’s big enough
  3. use PXE to netboot the kernel and root, no local drive needed at all!
  4. make a CDROM (what are those?) that boots the kernel+root (no persistent storage)

Booting

Once you are able to successfully boot openwrt, follow my other openwrt instructions to finish getting things installed. Remember that openwrt trunk builds start with a very small base and you have to add the things you need. Also see the additional notes below.

Notes on PC hardware

  • This x86-64 build includes quite a few network drivers, but if it doesn’t have yours by default you may have to use opkg to install it. This might prove to be tricky if you don’t have network to install it…. :) If you run into this situation it might be interesting to modify your install procedure to get the right packages on the install (or consider using “Image Builder”).
  • openwrt assumes that eth0 is “lan” and eth1 is “wan”. Also the order it discovers things might vary depending on the hardware. So you may need to edit /etc/config/network to swap things around, or just be aware of which cables will need to be plugged in where.
  • by default the combined images display grub, kernel output, and login prompt on both the graphics console as well as the first serial port (ttyS0, 115200n8).

Upgrading

Most openwrt routers builds have “factory” and “sysupgrade” images that are used for initial install and upgrading. These images are built with knowledge about where on the system the flash is, it’s size, how it’s split up, etc. So when you are upgrading one of those system, you can use the luci web interface or other standard methods to upgrade. Because x86-64 doesn’t have “sysupgrade” images, the upgrade procedure can be a little different. Here is one method:

  1. Backup the router config, by going to “System” → “Backup / Flash Firmware” → “Generate archive” and save the resulting backup archive
  2. Reinstall openwrt as you did originally
  3. Restore the backup archive via the same page.

It may be possible to upgrade an x86-64 system in place, but I haven’t investigated how to do that yet.