Created
May 13, 2021 21:14
-
-
Save dmikushin/c410973a30b4cbd9bd99ca322a02a5ef to your computer and use it in GitHub Desktop.
FriendlyElec NanoPi Duo2 make SD card readonly with temporary ramdisk overlay, in order to avoid filesystem corruption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/scripts/local 2019-10-17 07:29:20.000000000 +0200 | |
+++ b/scripts/local 2021-05-12 20:30:38.000000000 +0200 | |
@@ -198,56 +198,10 @@ | |
local_mount_overlay() | |
{ | |
- # Test (mmc) block device | |
- [ -b "${USERDATA%p*}" ] && \ | |
- [ -b "${USERDATA}" ] || return | |
- | |
- local_device_setup "${USERDATA}" "userdata file system" | |
- DATA="${DEV}" | |
- RESIZE_STAT=${datamnt}/.ext4.resized | |
- | |
- if [ -z "${ROOTFSTYPE}" ]; then | |
- FSTYPE=$(get_fstype "${DATA}") | |
- else | |
- FSTYPE=${ROOTFSTYPE} | |
- fi | |
- | |
- if [ "$wipedata" = "y" ]; then | |
- roflag=-w | |
- remountopts= | |
- | |
- true ${FSTYPE:="ext4"} | |
- mkfs.${FSTYPE} -F -L userdata ${DATA} | |
- [ $? -eq 0 ] && :> ${RESIZE_STAT} && sync | |
- else | |
- roflag=-r | |
- remountopts="-o remount,rw" | |
- | |
- checkfs ${DATA} userdata "${FSTYPE}" | |
- fi | |
- | |
- mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${DATA} ${datamnt} | |
+ RW_SIZE=256m | |
+ mount -t tmpfs -o "size=${RW_SIZE}" overlay-rw ${datamnt} | |
mountoverlay_status="$?" | |
- # Resize userdata filesystem | |
- if [ -n "${remountopts}" ]; then | |
- if [ -f ${RESIZE_STAT} ]; then | |
- mount ${remountopts} ${datamnt} | |
- mountoverlay_status="$?" | |
- | |
- elif [ "${FSTYPE%[234]}" = "ext" ]; then | |
- umount ${datamnt} | |
- local_resize_ext4 ${DATA} | |
- | |
- mount -w ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${DATA} ${datamnt} | |
- mountoverlay_status="$?" | |
- | |
- if [ "$resizepart_status" -eq 0 ]; then | |
- :> ${RESIZE_STAT} && sync | |
- fi | |
- fi | |
- fi | |
- | |
[ "$mountoverlay_status" != 0 ] && return | |
# Prepare & mount overlayfs | |
@@ -300,25 +254,9 @@ | |
mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt} | |
mountroot_status="$?" | |
- # Resize root filesystem | |
if [ -n "${remountopts}" ]; then | |
- RESIZE_STAT=${rootmnt}/etc/fs.resized | |
- | |
- if [ -f ${RESIZE_STAT} ]; then | |
- mount ${remountopts} ${rootmnt} | |
- mountroot_status="$?" | |
- | |
- elif [ "${FSTYPE%[234]}" = "ext" ]; then | |
- umount ${rootmnt} | |
- local_resize_ext4 ${ROOT} | |
- | |
- mount -w ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt} | |
- mountroot_status="$?" | |
- | |
- if [ "$resizepart_status" -eq 0 ]; then | |
- :> ${RESIZE_STAT} && sync | |
- fi | |
- fi | |
+ mount ${remountopts} ${rootmnt} | |
+ mountroot_status="$?" | |
fi | |
if [ "$LOOP" ]; then |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment