-1

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:

  1. 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.
  2. 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?

closed as off-topic by Ingo, Milliways, Fred, Darth Vader Sep 27 at 13:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – Ingo, Milliways, Fred, Darth Vader
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Linux can easily handle this with 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 at 0:29
  • @crasic It CAN be written to, and should remain writable as far as the system running from it is concerned. It can even be read back to verify that it has indeed been written to. Then it reverts when you cycle the power, just like an Immutable Virtual Hard Drive does in VirtualBox. So there is a use for it, and what I might call a "perfect" implementation of it...but that implementation is in a different context with different resources than what we have here. – AaronD Sep 24 at 2:07
  • 1
    For commodity memory this doesn't exist. Can you design one, that looks just like an SD card, sure. But if you want a solution that exists right now, write a script to handle the mounts. In any case this is not specific to the Pi, and is off topic, a better on topic question might be if you can use the pi to emulate being a memory back sd card for a usb slave device – crasic Sep 24 at 2:43
  • 1
    this is a hardware question. see electronics.stackexchange.com/questions/98285/… – user2497 Sep 24 at 11:30
2

Well, SD cards DO have a physical switch that can be used to make them immutable. But I'll assume you already tried that ;)

I thought crasic's suggestions were good, and the linked post he shared answers how you would really accomplish this.

To directly answer your question, "No, there is not a device that does this". Something cannot be both immutable and mutable at the same time. Any storage device that could accomplish this would be doing so via software (partitioning a disk, RAM Disk, etc) and it would be an illusion.

Also, even if reads/writes are non-perm they will still wear the memory devices. And corruption can happen even when the filesystem is not being altered by a user, just from environmental effects. So even if it did exist, it might not really accomplish what you're seeking.

The suggestions you made for how it might work would have to be based in software (an operating system). Consider that if the SD card is just willy-nilly sending data to RAM without the OS knowing, what is the OS going to do when it wants to use that bit of RAM? It won't have any clue whether it's being used by the SD Card because it just thinks it's a 'dumb' SD Card that takes read/write instructions. Talk about corruption!

The problems you're really trying to solve with this device are not something that should be solved with an immutable SD card. If you ask how to solve those problems directly you might find helpful suggestions.

Best of luck.

  • As I said originally, this RAM is NOT a part of the normal system RAM, but on the SD card itself and dedicated for this purpose. Everything works exactly like a normal SD card, including the OS having all of the normal RAM available and uncontested, and its ability to use the card freely...until it powers off and back on again. At that time, the card reverts to the "standard" (captured) image and so the system runs that again. – AaronD Sep 24 at 18:04
  • Kinda like having a backup image of the card and re-imaging it every time. Except that the card itself does that automatically. Now take that idea and rearrange the internals to do exactly the same thing but not wear out the flash cells with a ton of writes. This is where the on-card RAM comes in. Flash stores the backup, and then the card runs from its own dedicated on-card RAM. But that's not the only way to do it, only an example that I thought would be easy to envision. – AaronD Sep 24 at 18:12
  • You cannot answer the question with Raspberry Pi because that is explicitly not wanted. – Ingo Sep 25 at 17:04
  • @Ingo, not sure what you're referring to. This is an RPi forum, how could the RPi not be wanted here? I don't see that request in the original post, either – M. Mills Sep 25 at 19:23
  • @MattMills The OP asked for an external device (that can also be used on a RasPi) but nothing belongs to Raspberry Pi. This is explicitly excluded with quote: "So I don't want the immutability to depend on the operating system at all." Due to our policies this is off topic here. – Ingo Sep 25 at 19:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.