Does there exist a device that goes in an SD card slot and behaves like a normal SD card, except that it can be made immutable?
I think it would have to have two modes:
- Initial Setup would be exactly like a normal SD card. Write to it, and it returns what was last written. Also retains the last-written data through a power loss. No different from the cards that we're all familiar with.
- Immutable would appear to be exactly like a normal SD card, from the running system's perspective. Write to it, and it returns what was last written. But it does not retain the last-written data through a power loss. Instead, it reverts to what it had when it was switched into this mode.
For a real-world example, see the Immutable flag for a Virtual Hard Drive in VirtualBox. That specific implementation can't be translated directly because we don't have all of its dependencies on a Pi, but it does demonstrate the idea.
And to be clear, I am NOT looking for a software solution that depends on the operating system working in a particular way. All of those that I've seen require a fair amount of work by the user to set up, which makes them appear brittle to me, and I've definitely had my fair share of things that worked for someone else but not for me because their solution was for a different version or a different branch of my OS, or depended on a non-default package that they had installed for an unrelated reason (and is therefore not documented as a dependency). But even if that were solvable, what happens if I want to run an entirely different system?
So I don't want the immutability to depend on the operating system at all.
I can see this being a wonderful way for a non-techie to:
- Avoid corruption from an improper shutdown, as the corrupted data is immediately replaced with the previous good data.
- Guarantee that it always starts the same way regardless of what anyone did to it.
Sure! Go ahead and overwrite that config file! Play with stuff you don't know what is! It'll all revert back on the next power-cycle. - Not require an expert to set up a RAM drive. This device effectively is a RAM drive, but it's entirely self-contained, independently of the operating system, and does not require a user to set it up or write a brittle script that only works on the development machine for who-knows-why. This implementation is entirely in hardware, with the only user-interaction being to tell it that it now has the desired data and to start reverting to that image on power loss.
- Not wear out a card with excessive writes, depending on how it's actually implemented. The possibility below is one such implementation.
One possible way that I see this working is to have an equal amount of RAM on the card itself as there is non-volatile flash:
- When power is applied, it automatically copies the flash into the on-card RAM. Then:
- In Initial Setup mode, all operations go to Flash, and the RAM is not used.
- In Immutable mode, all operations go to RAM, and the Flash is not used.
- In either mode, it appears to the outside world as a standard SD card. No need to change anything that uses SD cards.
Does such a device exist?
overlayfs
, simply mount the drive file system as read-only and overlay a local temporary file system for your temporary writes. This is more or less what docker does under the hood. Any hardware solution sounds like a custom module that is frankly, not that useful. If you need read only, you can make any SD card read only after you program it, permanently or temporarily. Having this shadow functionality is just a little weird and counterintuitive. I would expect something that can't be written to not accept a write. – crasic Sep 24 '19 at 0:29