The Raspberry Pi Foundation has recently added this feature to the base Raspian OS image.
First, upgrade your packages:
sudo apt update sudo apt full-upgrade sudo reboot
You can then configure a read-only file system by going to Preferences–>Raspberry Pi Configuration–>Performance–>Overlay File System–Configure…
The following procedure can be used to boot with a read-only file system. All modifications to the file system are done in RAM, and therefore, discarded between boots.
This can be useful to reduce wear on the SD card and also ensure a more reliable system, as file system corruption is less likely when it is read-only
sudo apt-get purge dphys-swapfile sudo apt-get autoremove
sudo cp overlayRoot.sh /sbin/ sudo chmod +x /sbin/overlayRoot.sh
When the system reboots the filesystem will be read-only. To revert to a read-write file system, simply insert the SD card in a PC and remove
Note that since file system changes are stored in RAM, one must avoid running programs that will write excessively to the file system, as, over time, it will exhaust all available RAM.