summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--recipes-core/multitech/overlayfs-init-ubi/overlayfs.init44
1 files changed, 31 insertions, 13 deletions
diff --git a/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init b/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init
index 72a6217..4b97968 100644
--- a/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init
+++ b/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init
@@ -1,8 +1,4 @@
#!/bin/bash
-# To turn on systemd debug:
-# setenv bootargs "systemd.log_level=debug console=ttymxc0,115200 ubi.mtd=nandubi root=ubi0:rootfs rootfstype=ubifs ro
-# rootflags=chk_data_crc mtdparts=gpmi-nand:4m(nandboot),-(nandubi)"
-
# Command to erase user data file system
# Modified for ubifs, secure boot (no U-Boot access)
@@ -19,7 +15,14 @@ DO_CLEAR_USERDATA_FILE="/mnt/user/.persistent/mts_do_clear_userdata"
pid=$$
prefix="<3>overlayrootfs-generator[${pid}]: "
loginfo() { echo "${prefix}$@" >/dev/kmsg ; }
-logpipe() { cat <(echo -n "${prefix}") - >/dev/kmsg ; }
+logpipe() {
+ OIFS="${IFS}"
+ IFS=$'\n'
+ while read ln ; do
+ echo -n "${prefix}${ln}" >/dev/kmsg
+ done
+ IFS="${OIFS}"
+}
mnt_user() {
mkdir -p $MNT_USER
@@ -32,8 +35,8 @@ fs="/run /dev /proc /sys /sys/kernel/security /dev/shm /dev/pts /run /sys/fs/cgr
my_switch_root() {
NEW_ROOT=$1
- echo mountinfo >&2
- cat /proc/mounts >&2
+ loginfo mountinfo
+ cat /proc/mounts | logpipe
mount --make-rprivate /
for f in $fs ; do
mount -o noatime,move --bind $f $NEW_ROOT/$f
@@ -43,9 +46,25 @@ my_switch_root() {
# remove old hidden and non-hidden files and folders
do_remove_old() {
- shopt -s dotglob
- rm -rf $MNT_USER/*.old
- shopt -u dotglob
+ if [[ -f $DO_ERASE_USERDATA_FILE ]] ; then
+ do_clear_old
+ else
+ shopt -s dotglob
+ rm -rf $MNT_USER/*.old
+ shopt -u dotglob
+ fi
+}
+
+# Most efficient way to clear UBIFS file system
+do_clear_old() {
+ umount -l $MNT_USER
+ ubiattach -m 1 || true
+ [[ $(ubinfo -d 0 -N user-data | grep 'Volume ID') =~ .*[[:space:]]+([0-9]+) ]]
+ DEV="/dev/ubi_${BASH_REMATCH[1]}"
+ loginfo "Erase user-data partition $DEV"
+ # Would be nice if ubiupdatevol took volume names instead of numbers
+ ubiupdatevol ${DEV} -t
+ mnt_user
}
# select files for deletion
@@ -81,9 +100,8 @@ do_rw_mount() {
mkdir -p $UPPERDIR $WORKDIR $OVERLAY $USER_ORIG ${MNT_USER}/.persistent
loginfo "Mounting..."
- set -x
mount -o noatime,lowerdir=$LOWERDIR,upperdir=$UPPERDIR,workdir=$WORKDIR,rw -t overlay overlay $OVERLAY
- loginfo "JAK: What does overlay look like in /proc/mounts?"
+ loginfo "/proc/mounts:"
cat /proc/mounts | grep overlay | logpipe
mkdir -p ${OVERLAY}/var/persistent
@@ -91,7 +109,7 @@ do_rw_mount() {
mount --bind ${MNT_USER}/.persistent ${OVERLAY}/var/persistent
loginfo "Switch root to $OVERLAY"
my_switch_root $OVERLAY
- cat /proc/mounts | grep overlay >&2
+ cat /proc/mounts | grep overlay | logpipe
mount -o remount,rw /
cat /proc/mounts | grep overlay | logpipe
cat /proc/mounts | grep tmp | logpipe