RAM 512 DDR4, ROM 128 FLASH NAND, and extroot on ext4, usb disk 16Gb, openwrt 25.12.6.
I want everything to be persistent (/var), but /var -> /tmp
Google AI mode says:
It is not recommended to replace the /var symlink with a regular directory in an attempt to ensure that logs or data persist after a reboot.
Many services and packages in OpenWrt treat the paths /var/run and /tmp/run as interchangeable.
is that true?
Also GAI recommended configuring each service separately. (Really?)
I want to persist /var/cache/apk/APKINDEX.*
GAI did not recommend using apk.conf since it is unstable (What?)
instead, he recommended using bind mounts /var/cache/apk -> /opt/data/apk (Really?)
There may be some valid reasons to want this, but also many reasons why this is not a good idea and thus why OpenWrt does not write data to a persistent (i.e. flash based) /var directory.
In this case, the information you got is correct in that it is not recommended to make /var persistent. The core reason that OpenWrt stores /var in RAM is because of the number of writes that will occur here -- it will quickly ruin the embedded flash memory of many standard routers, especially those designed with flash chips that have relatively limited write cycles.
But, if you have specific reasons for wanting this, there may be other approaches you can use to make this safe and reasonable.
which doesn't constitute a "big machine" despite the fact that you have plenty of ("easily replaceable") flash storage. Writing the /var directory to flash storage will still wear out a usb flash drive, although obviously it has a longer life than older or lower-end embedded flash memory, but it may still cause it to fail over time. However, moving /var to the USB disk may not work as expected because (AIUI) the directory is needed before the extroot storage is mounted.
But back to the fundamental question -- why? What are you trying to do that requires persistent /var. To be clear, I'm asking to better understand your scenario so that we can arrive at a working solution for your needs.
The embedded flash memory is used 'only' at boot, but the boot process actually needs to write some stuff to /var before it gets to the phase in the boot cycle where it mounts other storage. As such, moving /var to external storage may have unpredictable results if the external storage is not yet mounted when the system is trying to write to it initially.
This is what I wanted to know....
You can specifically store your collectd statistics and other data on external storage without needing to move the entire /var to an external storage device.
note that you can change the BaseDirto reflect your mounted extroot partition.
i know, but
what if add big green button in system settings "MakeVarPersistAgain" and when user press it then new dialog appear where ask "Are you sure have good root?" and when user press YES, router reboots and make VarPersistAgain. Is that good idea for feature request?
Given that your intent is to store long-term collectd data to an external device, you probably don't actually need/want extroot. To be clear, extroot is kind of a hack -- extremely useful if you need more storage for OpenWrt + packages -- but it is not intended for situations where the system+packages can fit on the internal storage and the only reason for the external storage is for general data.
Instead, you really just want to have a plain ext4 formatted blank USB drive for this purpose. All you need to do is mount it (in your fstab file) and then point collectd to that location to write your data.
Your current approach is akin to dismantling the entire engine just to do an oil change.
This is actually a very bad idea, as it will quickly damage many devices (and/or consume the extremely limited internal storage space). "Are you sure you have a good root" is not something that I expect means much to most people, and they will end up in a bad situation.
extroot is not a common configuration method and is generally only used in situations where the hardware itself is extremely limited on flash storage. With that in mind, the usefulness of such a user-facing option -- even when considering extroot environments -- is rather limited and certainly the risks outweigh the rewards.
No, but there is no reason to expose a setting that has the potential for such harm when it is generally not needed on most supported devices.
As I pointed out, there is a best-practice option (i.e. write collectd data directly to a USB disk, leave everything else alone) that is known to work well and does not have any downsides.
If an expert wants to adjust the configuration to really keep a persistent /var, they can compile their own image as described.
recompiling not option, since i want /var->/tmp on nand and persisted var on extroot, i thing it good idea to activate persisted var on extroot by default, since extroot to nor, nand is nosence
That feature doesn't currently exist as a user option. Changing the configuration at the very low level (i.e. in the source code) would be required. Thus, recompiling is necessary.
Because it is a feature that you seem to think is worth developing, you should go ahead and make the changes, test it, and then create a PR for it.