ycfunet
(Yuan Chia Fu)
April 26, 2025, 2:38am
1
Same as RaspberryPi, A read-only root filesystem can prevent sdcard corruption when the BPI suddenly loses power.
Read-only Root has many solutions, we use overlayRoot solution. The overlayRoot solution is the easiest solution to set up.
We use frank-w BPI-R4 Debian version.
Setup step:
Modify BPI-BOOT/uEnv.txt in SD
Add boot parameter as follows:
root=/dev/mmcblk0p6 init=/sbin/overlayRoot.sh rootfstype=ext4 rootwait
Download overlayRoot.sh and put into BPI-BOOT/sbin/overlayRoot.sh
We use fitu996’s overlayRoot.sh
Modify fstab and chmod overlayRoot.sh
/etc/fstab
Backup fstab as fstab.rw
Setup /boot parameter as ro
chmod 755 [BPI-ROOT]/sbin/overlayRoot.sh
Insert SD to boot or reboot
Boot from SD.
Normal Debian filesystem:
Read-Only Root Debian filesystem:
We can see some thing different.
First, / mount from /dev/root to overlayfs-root.
Second, /boot mount params as ro (read-only).
Now, we can touch file to /, mkdir folder to /.
When we reboot, all changes will disappear(all changes in ram).
1 Like
ycfunet
(Yuan Chia Fu)
April 26, 2025, 3:21am
2
How to modify data in Root?
We has 2 methods:
We can remount / to rw, and modify files, create folder.
We can mark root parameter in uEnv.txt.
The first method cannot install deb packages because package information is stored in /var, but it can modify/add system files and directory.
The second method can modify system and install deb packages, but it requires two reboots (the first time to apply the read-write system, the second time back to read-only system).
First method:
Mount /dev/mmcblk0p6 to /mnt and remount it to rw
mount /dev/mmcblk0p6 /mnt
mount -o remount,rw /mnt
Create directory
mkdir /mnt/A
ls /mnt/
Umount /mnt
Reboot and check /
Second method:
Remount rw /boot
Modify uEnv.txt
Check filesystem and reboot
After reboot, check filesystem
When we finish install packages, upgrade system.
We modify uEnv.txt and reboot back to read-only Root.
1 Like
ericwoud
(Eric W.)
April 26, 2025, 11:42am
3
Thanks for the instructions.
There are more ways to prevent corruption:
Use emmc instead of sd card. It is more resillient to wear.
Use f2fs or btrfs instead of ext4.
Or when really must use ext4 mount with options noatime and nodiratime. Format with correct alignment and setup a blocksize that fits the card.
Check sd card when in the the bananapi board:
bc -l <<<"$(cat /sys/block/mmcblk0/device/preferred_erase_size) /1024 /1024"
SD_BLOCK_SIZE_KB=16 # in kilo bytes
SD_ERASE_SIZE_MB=4 # in Mega bytes
Make sure the roots partition starts exactly in a multiple of SD_ERASE_SIZE_MB
stride=$(( $SD_BLOCK_SIZE_KB / $SD_BLOCK_SIZE_KB ))
stripe=$(( ($SD_ERASE_SIZE_MB * 1024) / $SD_BLOCK_SIZE_KB ))
mkfs.ext4 -v -b $(( $SD_BLOCK_SIZE_KB * 1024 )) -L ROOTFS_LABEL \
-E stride=$stride,stripe-width=$stripe /dev/mmcblk0pX
So really, it is easier to use f2fs or btrfs, you don’t neef to worry about all this and it is practically all automatic.
ycfunet
(Yuan Chia Fu)
April 26, 2025, 12:39pm
4
Thanks.
You are right, f2fs is optimized for Flash reading, writing, and data correctness.