Cannot flash an image of OpenWrt inside a LXC on x86/64 host

I created an OpenWrt x86/64 install within a linux container for testing purposes as follows:

lxc-create -n openwrt3 -t download -- -d openwrt -a amd64 -r snapshot

I'm not able to flash an image to this containerized install. Even if I force the process, the new image is not written, the container seems to reboot but none of the packages I compiled into the image are present suggesting that the image is not actually getting written. What am I missing?

# sysupgrade -i -F openwrt-x86-64-generic-ext4-combined-efi.img.gz
Wed Jan 29 18:17:06 GMT 2025 upgrade: Image not in /tmp, copying...
Wed Jan 29 18:17:06 GMT 2025 upgrade: Image metadata not present
Wed Jan 29 18:17:06 GMT 2025 upgrade: Unable to determine upgrade device
Image check failed but --force given - will update anyway!
Keep config files over reflash (Y/n): y
Edit config file list (y/N): n
Wed Jan 29 18:17:12 GMT 2025 upgrade: Saving config files...
Wed Jan 29 18:17:12 GMT 2025 upgrade: Commencing upgrade. Closing all shell sessions.

So it seems you have to extract the image manually for a containerized install.

# unzip and mount the image
gunzip -c openwrt-x86-64-generic-ext4-combined-efi.img.gz > here.img

fdisk -l here.img
GPT PMBR size mismatch (1114655 != 1114686) will be corrected by write.
The backup GPT table is corrupt, but the primary appears OK, so that will be used.
The backup GPT table is not on the end of the device.
Disk here.img: 544.28 MiB, 570719744 bytes, 1114687 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: gpt
Disk identifier: CDDD8B3C-8804-E3FA-EBCB-397FAABEC900
Device      Start     End Sectors  Size Type
here.img1     512   66047   65536   32M Linux filesystem
here.img2   66048 1114623 1048576  512M Linux filesystem
here.img128    34     511     478  239K BIOS boot
Partition table entries are not in disk order.

mkdir ok
mount -o loop,offset=$((512 * 66048)) here.img ok

# backup configs
cp -a /var/lib/lxc/openwrt/rootfs/etc/config ./backup
cp -a /var/lib/lxc/openwrt/rootfs/root ./backup-root

# wipe old image and replace with new and restore configs
rm -rf /var/lib/lxc/openwrt/rootfs/*

cp -a ./ok/* /var/lib/lxc/openwrt/rootfs/
cp backup/* /var/lib/lxc/openwrt/rootfs/etc/config
cp backup-root/* /var/lib/lxc/openwrt/rootfs/root
cp backup-root/.* /var/lib/lxc/openwrt/rootfs/root

One of the many (but not the most serious) reasons why running OpenWrt in a container is not a supported configuration.

1 Like

I understand. Hopefully this thread will help someone in the future wanting a containerized version for testing/development not actual routing :stuck_out_tongue:

1 Like

OpenWrt interacts heavily with the kernel and containers use the host kernel. Modules cannot be added to it, and even if the functionality you need is in the host kernel, it is likely to have a version incompatibiltiy. One really should not even try to run OpenWrt in a container. Use a full VM or a bare-metal installation.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.