OpenWrt on x86 hardware aka PC / VM / server

OpenWrt can of course run in normal PC or server hardware, and take advantage of the much more powerful hardware the x86 (Intel/AMD) architecture can offer.

Note: For UEFI bootable OpenWrt image see OpenWrt on UEFI based x86 systems

Go here, choose the release version, then click on target and then on x86. You will see different targets.

:!: There are multiple targets for x86 OpenWrt, some are targeted at old or specific hardware and their build defaults may not be suit modern x86 hardware.

  • 64 is for modern PC hardware (anything from around 2007 onward), it is built for 64bit-capable computers and has support for modern CPU features. Choose this unless you have good reasons not to.
  • Generic is for 32-bit-only hardware (either old hardware or some Atom processors), should be i686 Linux architecture, will work on Pentium 4 and later. Use this only if your hardware can't run the 64-bit version.
  • Legacy is for very old PC hardware, Pentium MMX, what is called i586 in Linux architecture support. It will miss a lot of features you want/need on modern hardware like multi-core support and support for more than 4GB of RAM, but will actually run on ancient hardware while other versions will not.
  • Geode is a custom Legacy target customized for Geode SoCs, which are still in use in many (aging) networking devices, like the older Alix boards from PCEngines.

Now you will see different files offered, the following two are disk images you can download and use:

  • squashfs-combined.img.gz This disk image uses the traditional OpenWrt layout, a squashfs read-only root filesystem and a read-write partition where settings and packages you install are stored. Due to how this image is assembled, you will have only 230-ish MB of space to store additional packages and configuration, and extroot does not work. :!: This image must be resized beforehand to properly utilize in a VM.
  • ext4-combined.img.gz This disk image uses a single read-write ext4 partition with no read-only squashfs root filesystem, which allows to enlarge the partition. Features like Failsafe Mode or Factory Reset won't be available as they need a read-only squashfs partition to function. It has both boot and root partitions and MBR area with updated GRUB2. Careful: this is a disk image, installing it will override MBR table and therefore delete any other partition present on the disk!
  • ext4-rootfs.img.gz This is the equivalent partition image without boot partition, to be installed without overriding MBR.
  • rootfs.tar.gz This contains all files from root partition. it can be extracted on root partition without the need of rewriting the partition. It's highly recommended to remove all script and compiled files before extracting, to avoid conflicts.

All images support basic video output (screen text terminal), so you can connect a screen to the device's video ports and see it boot up.

Some images support keyboard input which can be used to configure OpenWrt. It has been tested with OpenWrt 19.07.4 64.

To communicate through a PC serial port you will need a “null-modem” aka “crossed” serial cable to connect the device's serial port to your PC's serial port.

To be able to connect to your device, the image must support the Ethernet hardware.

The 64bit image supports Intel and Realtek Ethernet chipsets. These are the kmods installed by default: kmod-button-hotplug kmod-e1000e kmod-e1000 kmod-r8169 kmod-igb

The Generic and Legacy images support Intel, Realtek, Via and some other ethernet chipsets. These are the kmods installed by default: kmod-button-hotplug kmod-e1000e kmod-igb kmod-3c59x kmod-e100 kmod-e1000 kmod-natsemi kmod-ne2k-pci kmod-pcnet32 kmod-8139too kmod-r8169 kmod-sis900 kmod-tg3 kmod-via-rhine kmod-via-velocity

The Geode images support Geode hardware so as long as you have a Geode-based board you should be fine.

NVMe SSD support is only available starting 21.02.

The installation consists of writing a raw disk image on the drive which will boot OpenWRT system. It may be a USB flash drive, USB SDcard reader with SDcard or in a SATA hard drive or SSD (recommended). You can do it either on a secondary PC, or booting the router machine with a Live CD/USB.

Installation procedure differs depending from what OS you are using to write the raw disk image from, mostly because of different tools you have to use.

WARNING: writing raw image files DELETES the content of the drive you write them on, be sure that you are not deleting anything important, and that you have selected the right drive.

If you are using a Windows / macOS, you will need a program to extract the raw disk image from the compressed archive you downloaded. Then you will need to open the raw image file with a program that can write it on the drive you want to install OpenWrt on.

A good free and opensource archiver program you can use is 7zip, or Keka.

A good free and opensource raw disk image writer program you can use is Win32 Disk Imager, or Etcher.

Extract the image file from the archive. Most sane distros will let you do so by rightclick and then select “extract”, or you will have to open up your graphical archive manager and do it from there. From the terminal it is done by gzip -d openwrt-18.06.1-x86-64-generic-ext4-combined.img.gz.

Then write the image file you extracted to the drive you want to install OpenWrt in. Many distros include a disk image writer application already (also, “Gnome Disks” application allows you to do this). From the terminal, detect how is called (sda, sdb, sdc, etc) the drive you want (in example, use sudo blkid or sudo lsblk) and then write the image with good old dd tool dd if=openwrt-18.06.1-x86-64-generic-ext4-combined.img of=/dev/sdX where sdX is the name of the drive you want to write the image on.

Note you have to write to the drive (sda, sdb), not to a partition (sda1, sdb3).

The x86 image is using the following partition layout (as seen from inside of the device):

  1. /dev/sda1 is a 16MB ext4 /boot partition where GRUB and the kernel are stored.
  2. /dev/sda2 is a 256MB partition containing the squasfs root filesystem and a read-write f2fs filesystem OR the ext4 root filesystem (depending on what image you have chosen).

Any additional space in the device is unallocated.

This is possible only if you have chosen the combined-ext4.img.gz type of image, and currently due to technical limitations you can't just resize the ext4 partition online (while it is mounted) so you will need to install OpenWrt on another drive to use it to perform the following operations. Also using a Linux system (either from a VM or actually installed in a PC) will of course work.

  1. Install fdisk and resize2fs
  2. use fdisk to show the partitions
  3. write down the starting sector address of /dev/sdb2 (which is the root partition)
  4. use fdsk to delete the partition 2 (which is sdb2), don't write the changes to disk yet
  5. use fdisk to create a new partition 2, choose/type the starting sector address you wrote down earlier (as by default it will try to place it somewhere else), and leave the default end sector address (this will mean the partition will now use all available space)
  6. write the partition table changes to disk. It may complain about partition signatures already present, write n to NOT remove the partition signature to proceed.
  7. write resize2fs /dev/sdb2 to enlarge the actual filesystem to fill the larger partition size.

an example fdisk operation on a 8GB flash drive

# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdb: 7.2 GiB, 7751073792 bytes, 15138816 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xcbad8a62

Device     Boot Start    End Sectors  Size Id Type
/dev/sdb1  *      512  33279   32768   16M 83 Linux
/dev/sdb2       33792 558079  524288  256M 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (33280-15138815, default 34816): 33792
Last sector, +sectors or +size{K,M,G,T,P} (33792-15138815, default 15138815): 

Created a new partition 2 of type 'Linux' and of size 7.2 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: n

Command (m for help): w

The partition table has been altered.
Syncing disks.

When OpenWrt is installed on a x86 machine using generic-ext4-combined.img.gz, the drive's partition table is overwritten, which means that any existing partition is deleted. Any remaining space will be unallocated and the drive will have a normal MBR partition table.

Any partition management tool that supports MBR and ext4 can be used to create extra partitions on the drive, in example fdisk, GParted.

But attention must be taken for future upgrades. If extra partitions are added, you cannot use -combined.img.gz images anymore, because writing this type of image will override the drive's partition table and delete any existing extra partition, and also revert boot and rootfs partitions back to default size.

On most embedded devices, upgrading OpenWrt is much simpler than the first installation and consists of simply executing sysupgrade. On x86 machines, on the other hand, upgrading is more complex than the first installation.

One of the advantages of x86 is the easiness to backup and restore drives, using any normal backup tool that supports MBR and ext4. Always make a proper backup of the whole drive and test its restore before any upgrade procedure. It's also recommended to restore the backup on a virtual machine and execute the upgrade on it prior to upgrading the real router, to learn and experiment the procedures without risking the real thing.

On all procedures on this section, we must either connect the drive on a secondary PC running Linux, or boot the router with a Linux Live CD/USB.

If you had used a ext4-combined.img.gz type of image to install, there are 4 options for upgrading:

  1. Write a new ext4-combined.img.gz image: this is the simplest option and is identical to first installation: all data, configs, packages and extra partitions will be wiped and you'll have a brand new OpenWrt system with default packages and configs. Then you can reinstall all packages and copy config files back and create extra partitions.
  2. Use sysupgrade: this is default upgrading procedure, but the least recommended option for x86 machines. Proceed to Sysupgrade for details.
  3. Extracting boot partition image from ext4-combined.img.gz and writing it and ext4-rootfs.img.gz, leaving MBR partition table intact.
  4. Extracting boot partition image from ext4-combined.img.gz and writing it, then uncompressing rootfs.tar.gz to existing rootfs partition.

The 2 last options require more steps to execute, but have the advantage of leaving MBR partition intact, therefore keeping boot and rootfs partitions sizes (in case of having resized them) and any extra partitions. At this time they are the most recommended methods of upgrading. The only exception is when new OpenWrt image brings a newer version of GRUB2. Part of GRUB2 is stored close to MBR and outside of partitions area, so we need to write a full ext4-combined.img.gz to update it.

The boot partition contains part of GRUB2 software, Linux kernel and grub.cfg with boot options. rootfs partition contains OpenWrt files, packages and configs.

At the moment, it's not built a separated image file with boot partition, as it's available for rootfs. To be able to upgrade boot partition without overriding the whole drive, we must extract it from ext4-combined.img.gz, this requires a spare empty drive or a virtual machine.

  1. Uncompress combined partitions image: gzip -d openwrt-19.07.7-x86-64-generic-ext4-combined.img.gz
  2. Write the image to the empty drive: dd if=openwrt-19.07.7-x86-64-generic-ext4-combined.img of=/dev/sdd (drive may be on sda, sdb, nvme0n1, etc)
  3. Extract boot partition image: dd if=/dev/sdd1 of=openwrt-19.07.7-x86-64-generic-ext4-boot.img

We will end up with the partition image openwrt-19.07.7-x86-64-generic-ext4-boot.img. Back to OpenWRT machine/drive, if the drive is on sdd and GRUB2 boot partition is on sdd1, we can write the updated image with dd if=openwrt-19.07.7-x86-64-generic-ext4-boot.img of=/dev/sdd1. Note we're here writing on the partition sdd1, not on the drive sdd.

As said above, there are 2 options for upgrading rootfs partition, when we are using the ext4 file system and not squashfs: writing ext4-rootfs.img.gz image or uncompressing rootfs.tar.gz into existing partition.

Writing ext4-rootfs.img.gz will delete any file on the partition. When using dd, it will preserve partition's actual size, it won't revert its size to image's.

  1. Uncompress rootfs image: gzip -d openwrt-19.07.7-x86-64-generic-ext4-rootfs.img.gz
  2. Write the image to the partition: dd if=openwrt-19.07.7-x86-64-generic-ext4-rootfs.img of=/dev/sdd2

For uncompressing rootfs.tar.gz, we must mount rootfs partition, delete all files from it, then uncompress updated files.

It may be tempting to not delete config files, but the risk isn't work it, because some file may conflict and not be properly upgraded. It's safer to backup config files (as we should also backup whole drive before upgrading) and copy them back after upgrading. I suggest going further and having a Subversion repository on another computer where all config files are saved and their changes are tracked, and use rsync to sync between the repository working copy and production files on the router.

# mount rootfs partition, in this example it's on sdd2
mkdir /mnt/rootfs
mount -v /dev/sdd2 /mnt/rootfs
cd /mnt/rootfs
 
# delete all files on the partition
rm -Rf *
 
# copy rootfs.tar.gz here then uncompress it
tar -xvzf openwrt-19.07.7-x86-64-generic-rootfs.tar.gz
 
# wait for uncompress then delete the file
rm openwrt-19.07.7-x86-64-generic-rootfs.tar.gz

Anyone can compile OpenWrt from source, but it's a complex procedure with many options which require some experience, specially for using it on a production router.

Different from compiling, we can build our own custom image using the Image Builder. This doesn't compile the whole software, instead it downloads required packages from the same repository used by OpenWrt to install them. Image Builder builds the same image files used for installing and upgrading OpenWrt.

Due to that it's much simpler than compiling and offers great advantages, like adding directly to the image all packages we need, removing those we don't need, and also adding to it our config files. Having packages on the image, we don't need to reinstall all of them after an upgrade. And having our config files directly on the image, we don't need to reconfigure everything or copy all files from backup, which is specially difficult when default network configs don't work with our router's interfaces or it doesn't start with correct IP address. In many cases, OpenWrt will be back fully working on first boot after upgrading.

Another advantage for building a custom image is when the default rootfs partition size is too small to store all packages and we need to resize it. Note that, when following above procedures of installing then resizing partition and upgrading by writing partition image or extracting rootfs.tar.gz, we don't need to build the image with the final size of the partition. Doing so would result on a img file too big and would require enough RAM to store the whole file during building. It's recommended to use on the image just enough size to store all packages plus a small amount of free space.

Use the Image Builder tutorial to setup the building environment. There is one openwrt-imagebuilder-VERSION-x86-64.Linux-x86_64.tar.xz for each version, it's downloaded on the same page we download default images. In example, file openwrt-imagebuilder-19.07.7-x86-64.Linux-x86_64.tar.xz is downloaded on https://downloads.openwrt.org/releases/19.07.7/targets/x86/64/.

Once the building environment is setup, we use the make image commnand to build an image, which results on a set of files with the types of images described on this page. They are saved on bin/targets/x86/64 inside the building folder.

Because x86 hardware doesn't have profiles, we don't need to use the PROFILE parameter. With PACKAGES parameter we set all packages we want to add to or remove from default list. The command make info lists default packages list. FILES parameter is used to add custom config and script files to be added to the image, it points to a folder which represents root folder when OpenWrt is running.

For changing default partition sizes use parameters CONFIG_TARGET_KERNEL_PARTSIZE and CONFIG_TARGET_ROOTFS_PARTSIZE. We can either edit .config file on building folder or pass them directly to make image. Example CONFIG_TARGET_KERNEL_PARTSIZE=128 CONFIG_TARGET_ROOTFS_PARTSIZE=512.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2021/05/12 04:14
  • by vgaetera