Make my OpenWRT config permanent by 'first boot' script?

I have two Linksys EA8300 both running OpenWRT v24.10.2 & both configured almost identically as LAN Access Points (except for their LAN IP address obviously). One of the EA8300 is rock-solid, the other seems to have some kind of issue (possibly hardware fault) that causes it to ‘factory reset’ itself back to the original OpenWRT v24.10.2 image that I flashed (all custom config wiped out). This happens randomly & regardless of which partition I use for OpenWRT + config.

Is there a way to take my custom config & make it ‘permanent’ so in the event that the device factory-resets itself, it starts up with the custom config & is basically back to working normally on my LAN? Can the OpenWRT ‘Firmware Selector’ be used to do this with a ‘first boot script’? What exactly do I put in the ‘first boot script’ edit box?

I looked at the docs on OpenWRT custom ‘image builder’ but concluded that compiling custom images from source is beyond my skill level.

Is it possible to put uci scripts in /files/etc/uci-defaults after having flashed firmware? Or will I have to rebuild my firmware with relevant packages & ‘first boot' uci scripts and then re-flash the new firmware to the router?

Will the included ‘first boot’ scripts be applied EVERY time the device is factory-reset? (I'm assuming if I flash a completely new image in future then, unless I re-include my ‘first boot’ scripts, then I'll have a clean OpenWRT install with all the standard default settings?)

Does the process of restoring settings from a .tar.gz backup do something similar? It just puts the relevant files into /files/etc/uci-defaults and boots? Oh - thinking about it, it can't do that or you'd end up with the same config every time you boot the router - silly me!

Image builder is not about compiling from sources, it is about packaging pre-compiled packages and takes under 10 minutes. With some basic Linux and shell scripting knowledge, you can achieve what you want. I do this for a few years now by re-spinning a new image with a few custom scripts, which get executed on the first boot and then removed so that they are not run again. My script does a full router provisioning in a few seconds, so I do not have to do anything at all after flashing a new image.

Yes and reboot the router to executed them, but that does not do what you need: putting scripts there is an extra step, which you have to do.

Only if they are present in the image, old or new.

2 Likes

So if I understand what you're saying:

The directory /files/etc/uci-defaults will not survive a factory-reset, so any scripts that were copied in there will be wiped out in the event the router resets itself.

With regard to creating an OpenWRT image & including some config scripts that are executed immediately on boot, I am confused by the difference between the Image Builder and the Firmware Selector with ‘first boot’ script?

It sounds like they both achieved the same thing?? Obviously, from my point of view, the Firmware Selector is by far the easier option. I guess I'll have to figure out how to create a ‘first boot’ script that will successfully do all my config (IP address, DNS, radios, channels, SSID’s, passwords etc etc) each time a ‘factory-reset’ is performed (whether voluntary or otherwise).

If the scripts there are included in the firmware, they will survive factory reset.

But adding them afterward makes them normal overlay files, which will not survive.

Likely the quite same end result. Files are included in the build as "custom files" embedded into image.
(Both actually use imagebuilder as the back-end. Firmware selector just uses a cloud-based imagebuilder, so that you do not need to build locally.)

2 Likes

You need to understand how OpenWrt is using file systems. Your firmware is intact in a r/o partition mounted as /rom. Then an overlay filesystem is mounted which makes /rom/etc/uci-defaults/ available as /etc/uci-defaults/. Files removed from overlay are marked as deleted, but they still live under /rom and cannot be removed form there. You can then re-set the router in place and the same firmware will do a first boot sequence and re-play your scripts.

The same thing: Firmware Selector is just a wrapper around Image Builder.

Check out exampled at the bottom of https://openwrt.org/docs/guide-developer/uci-defaults

1 Like

And it's probably useful to mention that the .../files/ version lives on the image build host and not on the router. It's just the place where you put the files initially in order to get them built into the image.

1 Like

BTW - A quick test of e.g. altering the default LAN IP and testing backup configs, etc. would've provided verifiable results.

From your reply, I wasn't sure if you still had questions. Glad you figured it out!

Not exactly “figured it out” as yet. I need to rummage through my OpenWRT router config files & figure out how to cut & paste the right commands into the Firmware Selector ‘first boot script’ edit-box without making any errors, as presumably once I've created & downloaded the OpenWRT image file, if there's any errors in there, it's going to fail when I flash the image & it tries to apply the config. And presumably if it fails to apply the first boot config correctly, that means going back to the Firmware Selector and repeating the whole process??

It's perhaps more trouble than it's worth & I would be better binning the EA8300 and look on eBay for an alternative.

If a script fails, the error will be ignored and first boot will complete: the file fill not be removed in this case. Your script can leave a config mess, that is possible.

You do not need to build a new image every time. Flush your router with the latest image and do not preserve config. Then make a copy of /etc/config/ and run your script. Review the results, restore the original config into /etc/config/,and execute your script again. The process is tedious for sure.

Once happy, restore config, place script into /etc/uci-defaults/, and reboot the router: it will execute every script found there on each reboot and will delete the files if successful. If a script fails, it does not get deleted so you can put exit 1at the end of your script to make it fail every time for debugging. KEEP COPIES of your script outside the router, though. Easy to lose them this way.

You can use Luci to configure the router the way you want, download config files, reset the router, and work on your script until the config by Luci matches config made by your script.

Your device dualboots.

Did you know that?
Do you know how to force the 'other' partition to take a 'known good' snapshot?

Yes, I know the EA8300 dual boots. I’ve used the Advanced Reboot package in Luci to boot between both partitions & have OpenWRT v24.10.2 on both partitions. But it doesn't help though - for whatever reason (I suspect some kind of hardware/memory fault) if I apply my network config to the partition 1 setup or partition 2 setup, the device will still randomly factory-reset itself every 4 or 5 weeks or so.

I suspect it has some kind of hardware/memory fault, because when I was first setting up the device for OpenWRT, at one stage I reset it back to Linksys firmware using:

mtd erase kernel
mtd write /tmp/FW_EA8300_1.1.4.191539_prod.img kernel

and although this succeeded, it reported several bad memory blocks (I forget the exact details). Whereas the other identical EA8300 had absolutely no issues & has been rock solid on OpenWRT v24.10.2.

With regard to preparing & setting up the Firmware Selector ‘first boot script’, I’m assuming this script is applied ‘cumulatively’ to a standard/default setup, so I only need to include in my script the changes I want to apply?

So if I don't include any changes to DHCP or Firewall or WAN etc etc, then these will still receive the standard/default configuration?

Set it up, and then do, another, firmware update.

That will push the 'known good' into the default.

You/we don't know what is causing the device to return to 'default'; it's most likely because the 'known good' has no settings.

At the least, it will tell you where it is getting the default settings from.
OpenWRT does not just erase itself.

*edit
See, it should phone home to the 'known good' if it detects an issue, not erase settings.

I'm not sure I understood your last post.

I can flash OpenWRT 24.10.2 twice & it writes to the ‘non-current’ partition each time, so doing it twice ensures a clean OpenWRT v24.10.2 ends up on both partitions.

No, OpenWRT isn’t “erasing itself”, it's factory-resetting itself. So the EA8300 will reboot to a clean image of the original image I flashed it with (ie. before I applied any configuration changes such as LAN IP, radios, SSID’s, passwords etc). So then I have to hook up my laptop to it again, and manually make all my changes over again (or just restore a backup .tar.gz file).

UPDATE: If I understand correctly, it ends up back at a clean OpenWRT image, because the config is stored in volatile ‘overlay’ storage, which gets wiped during a factory-reset. Hence the reason I was looking for a way to ‘bake’ into the image my config so it gets reapplied after the device factory-resets itself (so I don't need to hook-up my laptop & manually make configuration changes).

Then you know it is using that, 'known good' partition, because it failed to boot 5 times?

That partition is not intended to be virgin; in fact it is designed to have all 'known good' settings, in case you toggle something you should not have.

That it is there for more advanced use is, a plus, but it was added for idiots so they can screw up the settings but get back in before their mistakes.
You, bypassing it's, intended, use is fine but it is, evidently, not helping. If it could just default to known good, you would not know until the next time you went in.

And, it lets you make one change at a time, wait and see if it is that change that triggers your 'default'.

But if you prefer editing cli... have at it.

I'm not making any changes to trigger the factory-reset. It happens mostly during the night when I'm asleep & there's nothing much happening on my LAN (there's not even any cron/scheduled jobs that run on the device). It could be overheating or something - I don't know what triggers it.

I just thought an easy solution would be to ‘bake’ my fairly simple config into the image (using the first-boot script), so that if it factory-resets itself, it will at least apply my config & be back working on my LAN without me having to get my laptop hooked up again.

If this doesn't work, this EA8300 will be going in the bin.

I presume this/that.

I did, skim, the thread,
It is still, without your input, having an issue, getting no reply on the lan side, waited, gave up, rebooted 5 times...

Then went to 'known good'.
or
It's pixies with stolen fairy dust squirting water on gremlins. And I want that video system log.

Well, it is until you wont...
amiright?

But, I'd 'bake' that one setting at a time over a couple days; that way when it runs home, you are attending it.

1 Like

I've re read the thread.
There is no a or b partition. There is the one in use and the one known good.

Setting that straight so, going forward, you are not confused with the partitioning of the partitions.
They are just chunks of the same storage.

If you save the config from the 'good' boy, and put it on bad boy, what happens?