I'm working on a hotplug script for adblock-lean and I'm thinking how to minimize flash writes when that script needs to later be removed and/or re-added.
My current assumption is that moving that file (say from /etc/hotplug.d/block/99-abl-hotplug.sh to /etc/hotplug.d/block/.99-abl-hotplug.sh) and later moving it back writes less bytes to flash than deleting the file and later creating it again.
Is this assumption correct?
The question is mainly addressed to people who know the inner workings of overlayfs. Please only informed answers.
Well I'm not deeply steeped in the inner workings of overlayfs, but I have been doing similar and not encountered flash wear issues.
In my opinion, the answer to your question is yes, your assumption is correct IF:
You created the file, in the first place, directly onto overlay (ie you did not build it into rom with Imagebuilder, firmware-selector et al)
You use the mv command ( NOT the cp command followed by a delete - yes, obvious for Linux-ers, but not necessarily for Windows-ers).
mv just updates the directory entries as long as the original is on overlay and not rom. If it is on rom, it will up-write the entire file from rom to overlay... I think.
I read a doc about overlayfs in the meantime and looks like this is correct. Moreover, to my understanding, once the file migrates from the 'lower' into the 'upper' filesystem, further mvs will only update the filesystem entry as well. Still not 100% sure as none of that is written explicitly.
Neither am I, but I have not seen an issue - at least not yet (some old systems still running that do the mv once every restart, so very little writing, 3 or 4 times per year most likely.
Later versions keep the file on /tmp using ln to create a link, so no longer an issue for that use case.
?
What happens if the file on /tmp/ is removed but the symlink remains? Does the hotplug system tolerate this? Does it just skip the symlink file when it can't be resolved?
It would be the other way round: ln -s /tmp/actual-99-smth-file.sh /etc/hotplug.d/block/99-smth.sh
ie it makes a link from /tmp/actual-99-smth-file.sh to /etc/hotplug.d/block/99-smth.sh
What I was doing was creating the file on /tmp with the package startup script.
The symlink stays as a link file on flash. The link is valid if the /tmp file is present, or gives "No such file or directory" if it doesn't.
I don't know how this will fit into your use case.... but once the link file is created, there are no more writes to flash.
I'm trying adblock-lean on a device with very limited resources (a mikrotik hex lite)
It seems to be working, but then I restarted the router and it wasn't working anymore.
So I checked via SSH and saw that the service was “enabled” but “stopped.”
I tried restarting the service, and after a while Adblock-Lean was up and running again.
I’ve only been using OpenWRT for a few days, so I don’t know much about it yet. I’ve read that, in theory, if the router is slow, the service might try to start before all its dependencies have finished loading, and I’ve also read about hotplug.
Could that be the case?
Moreover I know that some init managers start services in alphabetical order, and adblock_lean, with its name, is the first of the list.
P.S. Also the restart is failing now and the stop and start too...
Maybe I have other problems...
If it has 64MiB of RAM indeed then it's going to be tough for you to get anything working, especially on a modern'ish OpenWrt version, as newer OpenWrt versions consume more memory.
The startup issues you are describing are most likely the consequence of the system running out of memory. Unlikely to be caused by anything else. You can use the command logread to see what's going on with the system.
In general, if you want to do anything with this device, you will need to make a custom build and remove basically everything that loads into memory and is removable.
Frankly, it's a bit of a miracle that 24.10 occasionally boots on this device at all with default packages. There are a few things you could try:
Use OpenWrt 23.05 (earliest OpenWrt version supported by adblock-lean)
Use zram-swap
Customize your build via the firmware selector. Probably add zram-swap and remove luci (if removing luci, you will need to configure the device via the terminal, either by issuing uci commands or by editing the config files under /etc/config/). I'm not sure what else you can remove there but maybe someone else knows.
Any combination of the above.
Edit: you could also try including zstd in the package list in Firmware selector, and changing the adblock-lean options:
No problem. To make it easier for you: open the firmware selector link and search for "hex" - there is only one device matching this keyword. On the right side, you can select the desired OpenWrt version. Then click on Customize installed packages and/or first boot script. This will show you the packages which will be included in the generated firmware. I mentioned the packages luci, zram-swap, zstd. luci is included by default - you can remove it to make some more free memory but then you lose the web interface to configure OpenWrt. So it's your choice. In the same field, you can add the packages I suggested: zram-swap and zstd.
Edit: to clarify, personally I've never used zram-swap, so I'm not sure whether just installing the package is enough. Maybe you need to change some config option to make it actually work. You'll need to look it up.