I have a raspberry pi with a readonly root filesystem. There is
a second partition mounted readwrite. /etc, /var, /home, and /srv
are bind mounts to the readwrite partition. This will probably work
with any linux.
I started with a raspberry pi image I downloaded from the internet. I wrote
the raspberry pi image to a sdcard. The raspberry pi image did not fill the
whole sdcard, so there was unused unformatted space at the end of the
sdcard. I expanded the root partition, then used the rest of the space to
create another ext4 partition. I made a few edits to /etc, like user
account, hostname, timezone, etc. I moved /etc/fstab to /fstab, and made
/etc/fstab a soft link to ../fstab. I copied /etc, /var, /home, and /srv to
the second partition. Then I changed /fstab to:
PARTUUID=19de2757-02 / ext4 ro,noatime 0 1
PARTUUID=19de2757-01 /boot vfat ro 0 2
PARTUUID=19de2757-03 /readwrite_partition ext4 defaults 0 2
/readwrite_partition/var /var none bind 0 0
/readwrite_partition/etc /etc none bind 0 0
/readwrite_partition/home /home none bind 0 0
/readwrite_partition/srv /srv none bind 0 0
This raspberry pi is turned off by disconnecting the power, without doing a
normal shutdown. I made the root partition readonly so there would be less
chance of data corruption from shutdown.
If there is some problem and it is unable to mount the readwrite partition,
it should use the versions of /etc, /home/, /srv, and /var from the readonly
partition, and should be able to run disk repair utilities on the readwrite
partition.
I have run this for two years and had no problems.
Other people make /var a seperate partition, and then /home a link to
/var/local/home.
For /etc, only some of the files need to be readwrite. I made all of /etc
readwrite because I was too lazy to figure out which files needed to be
readwrite and which files could be readonly.
I included /srv in the readwrite partition because other people suggested
it. But /srv is empty, so this does not matter.
I moved /etc/fstab to /fstab because I thought there might be problems if
there were two versions of /etc/fstab, one on the readonly partition and one
on the readwrite partition, and the two versions were different. The
readwrite partition is mounted according to /etc/fstab on the readonly
partition, but once the system is running, /etc/fstab on the readonly
partition is hidden by /readwrite_partition/etc/fstab, and /etc/fstab on the
readonly partition cannot be edited. I did not know if I would need to edit
/etc/fstab, so I moved /etc/fstab to /fstab so that I would be able to edit
/etc/fstab. If you are sure you will never need to edit /etc/fstab, then
there is no need to move /etc/fstab to /fstab.
The hardest part is deciding how much configuration and edits to /etc
you want to do before copying /etc from the readonly partition to the
readwrite partition.
Most linux distributions do some configuration the first time it is booted,
and also start making logs. You might want to do the first boot before
copying /etc, /var, /home, and /srv to the readwrite partition, or you might
want to copy the files before doing the first boot. The advantage of doing
first boot before copying is that both /etc will include the first boot
configuration. The advantage of copying before first boot is that the
readonly versions of /etc, /home, /var, and /srv will preserve the original
configuration and will not waste disk space on useless logs.
/etc) in RAM, and then having symlinks for editable files back into read/write flash. Could that approach work for you?/etc/passwd -> /writable-mount/etc/passwd. Same for any other file or directory in etc which should be changeable.