Persist data in a snap between install and run modes

We’d like to have our device run in install mode while in the factory for provisioning so that we can have manufacturing snaps exposing a manufacturing API that aren’t exposed in a customer site. When provisioning is done, there would be an API to switch to run mode for regular customer use. We have already worked out how to switch these modes via a gadget install-device hook. However, we ran into a snag where a “device identity” snap that provisions a device in install mode, stores that info as files in SNAP_COMMON, and then accesses that data in run mode does not have that data available.

We attempted for a snap to write data to SNAP_DATA, SNAP_COMMON and SNAP_SAVE_DATA (ubuntu-save partition - this is the preferred location) but when then snap starts up in run mode, those locations are empty.

So what is the appropriate way for a snap running in install mode to persist data somewhere so that the snap running in run mode can access that data?

Sorry, this is a cross-post from device - I accidently put it there and can’t delete.

Thanks in advance!

1 Like

If you want to write persistent data while in install mode you could use the install-device hook and write files to /run/mnt/ubuntu-save/snap/<snap name>. The places where you are trying to write at the moment are ephemeral locations and not backed by disk.

Thanks @abeato , this was one of the options were were considering. Can we assume that only the install-device hook can do this and not a regular app snap that runs in both install and run run modes?