Prevent disk writes

I have a pretty stable OpenWrt setup and want the changes that I do using various scripts to NOT be written to flash. (I do a lot of config changes and fear that they might wear out the flash)

Is there a way I can prevent the overlayFS from syncing with the disk? Basically, preventing disk writes all together?

You can use a initram image that has its rootfs as a ramdisk that doesn't use any write cycles of your flash.
You can flash this images like the sysupgrade image om most targets.

What device are you using?

Can you provide a little more details or maybe some source where I can learn how to do this? Sorry, I am a noob when it comes to system level stuff :sweat_smile:

I am on TP-Link WR740N (the cheapest router I could get :grinning:)

This are the images with rootfs in ram:

Thanks @juppin. I get the idea: these are special images that don't write to disk and run completely out of RAM.

Can I build these using the image builder? I would want the initram image to include my config and scripts otherwise I would have to configure it again after every boot.

You write this images once to your flash and after that the image is only read from flash.

I'm not sure if they are buildable with the image builder. If you build OpenWrt from source it's selected by default.

by the way isn't something like extroot will work better for this? write to some disposable usb to save settings and whatever

Yes, I think something like that would be the ideal middle ground if you have a USB port.

Unfortunately, I have a cheap router which doesn't include one.

In a build from source as well as Image Builder you can put any configs or other non-default files in the files/ tree under the buildroot. It does not exist by default, but will work if you add it.

Got it.

But in this case, I think I would have to necessarily build from source since there is no option to build an initram image in the image builder.

An alternative idea:

For applications that are configured via uci, you can issue the uci commands as usual, but leave out the final uci commit. The new config can still be activated with reload_config or by restarting the affected service, but is not written to flash.

For non-uci applications, you can move the config file to /tmp and replace it with a symlink to the new location. Configuration updates go to /tmp, which is located in RAM.
Rebooting the device must somehow create an initial config. This could be done with an init script.

Thanks @mpa for the suggestion.

I use this approach on my RPi, but there I have access to a screen in case anything goes wrong. I was a bit skeptical to use this on my router since I wanted to avoid the risk of losing access.

I also thought that since OpenWrt uses an /overlay, there might be some way to prevent it from syncing to disk. Apparently, not an option though. Nevertheless, thanks for mentioning this, would be a helpful reference for for people with similar constraints trying to find a solution in the future :slight_smile:

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

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