I'm developing an embedded Linux system that runs from compact flash and tmpfs. The flash is mounted read-only and should normally stay that way, but occasionally I need to write something to the flash.
What precautions should I take when writing to flash (through a PATA interface)? For reasons I can't recall, I'm using an ext4
filesystem mounted with barrier=1,data=ordered,nodelalloc,noatime,ro
Is any of that a horrible idea? The system needs to boot quickly with zero intervention. I'm tempted to do tune2fs -c 0 -i 0
. Is that an even worse idea?
Also, when I write something, I obviously need to remount the flash read-write, perform the write, then remount read-only. The problem is that there are several different processes (both c++ binary and shell scripts) that may need to do this. Clearly having each process indiscriminately remount the filesystem read-only when it's done is a bad idea.
What's the best way to coordinate this? flock
looks promising; is that the best way to go and what do I need to be worried about? I don't want a stale lock to block writes or leave the filesystem writable indefinitely.
To clarify: By "occasional" writing, I mean the system could go for years without needing to write anything. When something does get written, it's maybe a couple hundred bytes. In the mean time, the system needs to endure unpredictable power cycles without any intervention.