I know this has been discussed ad nauseum on previous issue, but I've seen enough requests that it's probably worth collecting thoughts in one place.
Background
The Raspberry Pi is not a traditional embedded system. It's a full Linux computer system on a very small board. Like all Linux systems, the Pi normally requires an orderly shutdown to prevent data loss and filesystem corruption. If the power is pulled in the middle of a write operation, bad things (tm) can happen, including a complete corruption of the system. This is always painful, but it is particularly painful in an avionics system.
Stratux Read Only Requirements
- Store DHCP lease information. This data does not need to be persistent between reboots.
- Store the stratux.conf configuration data. This data does need to be persistent between reboots.
- Store log files when logging is enabled. This data may need to be persistent between reboots.
[Please add other requirements here.]
Strategies For Read Only Operation
- Remove unnecessary stuff that tries to write to the filesystem:
- dphys-swapfile
- other packages?
- Replace the default syslog system with the BusyBox syslogd which writes to memory
- Use tmpfs (ramdisk) for:
- /tmp
- /var/tmp
- /var/log
- /var/lib/dhcp
- Disable fsck by appending "fastboot" to the /boot/cmdline.txt file
- Disable swap by appending "noswap" to the /boot/cmdline.txt file
- Force read-only file access by appending "ro" to the /boot/cmdline.txt file
- Add an "ro" and an "rw" script to "/usr/bin" to allow advanced users to easily switch between read-only and read/write modes.
That handles the basics. I've done some experiments with this and it seems to work with a small tweak to the isc-dhcp-server init file (have to add "touch /var/lib/dhcp/dhcp.leases" before you start up the server).
What this doesn't handle are:
- Creation of and edits to /etc/stratus.conf made by the UI
- Log file persistence
My personal thought on that is to create an additional small partition as part of the image. Something like 500 mb to 1 gb. Format it with something that can be read by any computer (i.e. FAT32). When Stratux boots up it checks to see if it can mount this partition. If so, great - it mounts it and uses it for the configuration file and for logging. If it can't mount / read / use the filesystem it uses the format command to recreate it. It then writes a default stratux.conf and alerts the user through the GUI that the configuration was recreated and needs some attention. (The stratux.conf config data can easily be cached on the browser in localStorage, making replacement trivial.)
A variation on this theme:
Mount the config / log partition read only at boot. Remount it read/write when necessary to update the configuration or to copy log data from memory to the filesystem. Have a log rotation feature built into Stratux that handles this so that every minute or so the log data gets saved. This minimizes the chance of data loss.
Experience
I've tested the first part of this scenario and it seems to work. I have yet to try the additional partition. I'm not sure how much complexity that adds to the spindle configuration that is currently being used to build images.
I will attach the scripts that I've been using to this issue in case anyone wants to try it out.