1

There are number of articles about mounting SD card read-only, but I only found info, that if needed to write something, first of all you have to remount file system as readwrite. My question is there any way to mount SD card read only AND have file system in RAM, so that everything would look usual (like readwrite), it would be possible to save files without restrictions and after reboot everything would be like before with any changes saved. Like in micro-controllers where ROM does not change. Maybe like in this unclear instructions approach: https://www.monocilindro.com/2017/02/18/how-to-make-raspberry-pi-3-with-raspbian-jessie-read-only/
https://www.monocilindro.com/wp-content/uploads/2017/02/Raspberry_Pi_3_Jessie_read_only.pdf by using smth "boot=overlay" on which I cannot find any info.

Also, I am kind of newbie when it comes to Linux low level background. But I am interested in how Linux manages file systems. For example, if SD card is mounted regularly (read/write), what data of it, of file system is on RAM? Also, when editing files, some sort of buffer is allocated for that, but what if I open a file, which is larger than my total RAM space? And one more thing: like in my first question in this post, if file system will be only read/write on RAM and readonly on SD card, what would be loaded on RAM: all files from entire file system? What if there isn't enough of RAM? Or maybe only used/changed files will be loaded?

Sorry for kind of inappropriate questions, but if you can provide useful links on these topics, I would appreciate them a lot

Thanks in advance

  • Seems what you are looking for is Ramdisk. A ramdisk emulates a diskdrive within the Ram of the computer. This probably isn't going to work effectively on the Pi to emulate the complete SD card as there's not enough RAM for that. – Charemer Sep 25 '17 at 12:45
  • I confirm that I too couldn't find any documentation regarding "boot=overlay" option, and I doubt this option alone can create a RAM overlay on top of read-only root FS. You don't even get to tell how much RAM you want to sacrifice. – Dmitry Grigoryev Sep 25 '17 at 16:59
  • You asked about "read-only" but "after reboot everything would be like before with any changes saved". Did you mean "without any changes saved"? Data in RAM is lost on a reboot. – Chad Farmer Oct 2 '17 at 22:04
  • If you want to create a custom SD image, look at Linux's Overlay FS. You can create a system (SD), like a "Live DVD", that has a large "read-only" component and an overlayfs that holds writes in RAM. Reads automatically return the modified data or unmodified date from read-only storage. On a reboot, you are back to having empty RAM storage (nothing modified). This approach can be desirable for long-running applications because a reboot returns the system to its original state (like a factory reset). – Chad Farmer Oct 2 '17 at 22:15
  • If you are doing a custom SD, you can add a small read-write partition to hold configuration/customization data, so everything is not lost on reboot. – Chad Farmer Oct 2 '17 at 22:20
0

This may be a little bit too late, but putting it here for future explorers:
Check out https://cattlepi.com/
Among other things, it gives your a root file-system that is an overlay file-system. The bottom is rapsbian (as a ro squashfs) and the top is a tmpfs.

0

I have created a package for the Raspberry Pi Arch Linux distibution that solves exactly this problem:

During the boot process, a directory /new_root with the "soon to be root partition" is created, after which my script is run. It then

  1. removes /new_root
  2. creates an empty tmpfs partition (a partition that only lives in RAM)
  3. mounts an OverlayFS partition under the name /new_root

OverlayFS lets you create a overlayed stack of file systems, in which you see all files from the bottom file system, but all changes are written in the top file system.

The bottom file system is taken to be the SD card, and the top file system is taken from tmpfs. This means we see the SD card, but any changes we do end up in RAM, and are forgotten upon reboot.

A few little tweaks here and there to make the SD card FS readonly, and you have exactly the solution you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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