rusefi / web_backend

rusEFI Online backend code
https://rusefi.com/online/
GNU General Public License v3.0
4 stars 8 forks source link

SBC device: protect root FS from corruption on sudden power off #92

Open rusefillc opened 4 years ago

rusefillc commented 4 years ago

single board computers with SD card file systems are really brittle around unexpected power off shutdowns, a solution is needed

rusefillc commented 4 years ago

in case of Armbian:

Ubuntu ("Focal") has Overlayroot which might be relevant

See also https://forum.armbian.com/topic/3542-mounting-rw-partition-along-with-overlayroot/

rusefillc commented 4 years ago

balena creates a 1.3Gb partition leaving the rest of the card unallocated

Windows 7 seems to be unable to create volumes in free SD card space

Windows 10 allows to create new volumes in free space. Out of ~6gb of free space, I create two 3g volumes and then remove first volume - that case SD layout is

1g IMG | 3g unused | 3g FAT32 volume

rusefillc commented 4 years ago
Disk /dev/sdb: 7.37 GiB, 7902068736 bytes, 15433728 sectors
Disk model: STORAGE DEVICE  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x88a75e6e

Device     Boot   Start      End Sectors  Size Id Type
/dev/sdb1          8192  8386559 8378368    4G 83 Linux
/dev/sdb2       8386560 15433727 7047168  3.4G  5 Extended
/dev/sdb5       8388608 15433727 7045120  3.4G 83 Linux
ubuntu@ubunu2004:~$ sudo fsck /dev/sdb1
fsck from util-linux 2.34
e2fsck 1.45.5 (07-Jan-2020)
/dev/sdb1: clean, 37793/248832 files, 275001/1047296 blocks
ubuntu@ubunu2004:~$ sudo fsck /dev/sdb2
fsck from util-linux 2.34
e2fsck 1.45.5 (07-Jan-2020)
fsck.ext2: Attempt to read block from filesystem resulted in short read while trying to open /dev/sdb2
Could this be a zero-length partition?
ubuntu@ubunu2004:~$ sudo fsck /dev/sdb5
fsck from util-linux 2.34
e2fsck 1.45.5 (07-Jan-2020)
/dev/sdb5: clean, 11/220320 files, 31726/880640 blocks
ubuntu@ubunu2004:~$ 
rusefillc commented 4 years ago

https://yagrebu.net/unix/rpi-overlay.md

rusefillc commented 4 years ago

to check status:

to switch mode: overlayroot-chroot cd /boot cp cmdline.txt.overlay cmdline.txt reboot to enable

rm cmdline.txt reboot to disable

mount | grep ' on / ' to validate

rusefillc commented 4 years ago

@chuckwagoncomputing @ZHoob2004 open concern about overlayfs is how fast would RAM disk run out of space

chuckwagoncomputing commented 4 years ago

What all will be logged/"written to disc"? Looks like the Orange Pi Zero has 512MB of RAM. It might be tight, but I think it would be doable if we set up the image carefully, minimizing how much logging is done, as well as how much memory the system uses.

rusefillc commented 4 years ago

My idea was to have three partitions:

/ + /boot = overlayfs with RAM drive. only for boot and whatever needs /rw1 for less frequently modified files like rusEFI software /rw2 for more frequently modified files like logs to be uploaded etc

i.e. the only thing in RAM drive is linux magic, NOT anything rusEFI related

chuckwagoncomputing commented 4 years ago

Oh OK. I think 512MB will be plenty then.