Best practice for data storage in custom package?

I am assembling a new package for a service I use, and I plan to submit it to the openwrt package feed for consideration. The service needs a path where it can read and write a sqlite database.

From my understanding users are expected to plug in and mount a USB for such packages. Is there a standard path the USB is mounted to (/mnt/sda1) so it can coexist with other services? Perhaps the writable storage path is auto-detectable is someway?

I apologize if this is already specified, or if there is a better way than mounting a USB. Thanks for your help.

Not really - and according to FHS, /mnt/ is exclusively at the courtesy of the system administrator (so mustn't be used by default).

The normal approach would be to use (a subdirectory of-) /tmp/ and to suggest users to change that to a persistent location of their choosing, after all you have no idea what they may have mounted where.

2 Likes

Thanks for the response. Is the general approach then to have the service reference /tmp/(appname) for persistent storage, and then require the user/admin to mount the USB to that location?

No, that would be just to get the default configuration working, without damaging the flash (yes, that means data loss after the next reboot). The user would then be advised to mount persistent/ removable storage 'somewhere' and to change the configuration to use that instead.

It is imperative that this is NOT on the router's flash memory, because if it is, it will, sooner or later, wear out that flash memory, basically destroying the router.

The default for read write storage is as @slh said, is to use the "ramdisk" provided by /tmp

Of course /tmp is reinitiallised on reboot (everything is thrown away).
In addition, writing to /tmp consumes RAM, so writing lots of data to /tmp can lead to OOM problems and crash the router.

The solution is to use some form of "external" storage, as you said.

This can be a usb stick, an SSD, a network drive on some other device - anything you can mount onto OpenWrt.

For this you would create a mount point, best placed in /tmp, for example /tmp/mydatabase
This will use only a tiny amount of RAM as the "mydatabase" folder is just a mountpoint.

Usually, a package would have an external mountpoint defined in its config file.

Your package can automate this as it starts up.

Okay, this solution of a user mounting to /tmp/mydatabase makes sense for me.

I feel like I was missing some critical piece of information with regards to the package configuration. Since it can be distributed as a precompiled package, the configuration would need to live on the device, but then we're at the chicken/egg problem. How do you persist a configuration change without already having some persistent storage?

Thank you for your responses!

Well now you are not at the point of a chicken/egg problem, more at a "How do OpenWrt packages work?" point in the proceedings. :wink:

Packages keep their config in the flash memory - written to once when being set up and very rarely after when persistent config changes are necessary.

You could start by reading:

and

3 Likes

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