summaryrefslogtreecommitdiff
path: root/recipes-core/multitech
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2021-08-17 15:05:23 -0500
committerJohn Klug <john.klug@multitech.com>2021-08-17 15:05:23 -0500
commit06c091d9b4afcb18cd442eb927f08ebc371f38cc (patch)
tree174dea50115afaac8b281bf6fef9624fb1607bef /recipes-core/multitech
parent426b1a7f7619e863ae0b25c6dd92ea0cee806854 (diff)
downloadmeta-mlinux-06c091d9b4afcb18cd442eb927f08ebc371f38cc.tar.gz
meta-mlinux-06c091d9b4afcb18cd442eb927f08ebc371f38cc.tar.bz2
meta-mlinux-06c091d9b4afcb18cd442eb927f08ebc371f38cc.zip
Eliminate messages about non-existent file systems, and fix erase function
Diffstat (limited to 'recipes-core/multitech')
-rw-r--r--recipes-core/multitech/overlayfs-init-ubi/overlayfs.init93
1 files changed, 49 insertions, 44 deletions
diff --git a/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init b/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init
index 4b97968..0000f29 100644
--- a/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init
+++ b/recipes-core/multitech/overlayfs-init-ubi/overlayfs.init
@@ -9,8 +9,10 @@ UPPERDIR="$MNT_USER/upper"
LOWERDIR="/"
USER_ORIG="$UPPERDIR/orig"
USER_PARTITION="ubi0:user-data"
-DO_ERASE_USERDATA_FILE="/mnt/user/.persistent/mts_do_erase_userdata"
-DO_CLEAR_USERDATA_FILE="/mnt/user/.persistent/mts_do_clear_userdata"
+# Erase the file system
+DO_ERASE_PERSISTENT="/mnt/user/.persistent/mts_do_erase_persistent"
+# Remove files not hidden
+DO_CLEAR_PERSISTENT="/mnt/user/.persistent/mts_do_clear_persistent"
pid=$$
prefix="<3>overlayrootfs-generator[${pid}]: "
@@ -36,66 +38,69 @@ fs="/run /dev /proc /sys /sys/kernel/security /dev/shm /dev/pts /run /sys/fs/cgr
my_switch_root() {
NEW_ROOT=$1
loginfo mountinfo
- cat /proc/mounts | logpipe
mount --make-rprivate /
+ loginfo "my_switch_root: Mount file systems"
for f in $fs ; do
- mount -o noatime,move --bind $f $NEW_ROOT/$f
+ if [[ -d $NEW_ROOT/$f ]] ; then
+ loginfo "my_switch_root: mount -o noatime,move --bind $f $NEW_ROOT/$f"
+ mount -o noatime,move --bind $f $NEW_ROOT/$f
+ else
+ # loginfo "my_switch_root: Skipping $NEW_ROOT/$f"
+ :
+ fi
done
/sbin/pivot_root $NEW_ROOT $NEW_ROOT/orig
}
-# remove old hidden and non-hidden files and folders
do_remove_old() {
- 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
+ shopt -s dotglob
+ rm -rf $MNT_USER/*.old
+ shopt -u dotglob
}
# select files for deletion
-do_select_old() {
- if [[ -f $DO_ERASE_USERDATA_FILE ]]; then
- # when "erase user data" is requested - mark all hidden and non-hidden files for deletion
- shopt -s dotglob
- trap "shopt -u dotglob" RETURN
- loginfo "Erasing user data"
- else
- # when "clear user data" is requested - mark all non-hidden files for deletion
- loginfo "Clearing user data"
- fi
+do_clear_old() {
+ # when "clear user data" is requested - mark all non-hidden files for deletion
+ loginfo "Clearing user data. Persistent data will be left "
for FILE_PATH in "$MNT_USER"/*; do
FILE_NAME=$(basename "$FILE_PATH")
# rename all files and folders that exist in /mnt/user
- mv "$FILE_PATH" "$MNT_USER/$FILE_NAME.old"
+ mv "$FILE_PATH" "$MNT_USER/$FILE_NAME.old" 2>&1 | logpipe
done
+ do_remove_old
+ rm -f $DO_CLEAR_PERSISTENT
+}
+
+# Most efficient way to clear UBIFS file system
+do_erase_old() {
+ loginfo "Erasing user data"
+ # Sys must be mounted to use ubifs utilities
+ mount -t sysfs sysfs /sys
+
+ ubiattach -m 1 >/dev/null 2>&1 || true
+ ubinfo -d 0 -N user-data | logpipe
+ [[ $(ubinfo -d 0 -N user-data | grep 'Volume ID') =~ .*[[:space:]]+([0-9]+) ]]
+ DEV=/dev/ubi0_"${BASH_REMATCH[1]}"
+ umount -l $MNT_USER
+ loginfo "Erase user-data partition $DEV"
+ # Would be nice if ubiupdatevol took volume names instead of numbers
+ ubiupdatevol ${DEV} -t 2>&1 | logpipe
+
+ mnt_user
}
do_rw_mount() {
loginfo "Starting RW overlayfs"
mount -t tmpfs inittemp /mnt
- mnt_user
+ mnt_user # user_data is now accessible
do_remove_old
- if [[ -f $DO_CLEAR_USERDATA_FILE ]] || [[ -f $DO_ERASE_USERDATA_FILE ]] ; then
- do_select_old
- do_remove_old
- rm -f $DO_CLEAR_USERDATA_FILE
+
+ if [[ -f $DO_ERASE_PERSISTENT ]] ; then
+ do_erase_old
+ elif [[ -f $DO_CLEAR_PERSISTENT ]] ; then
+ do_clear_old
fi
mkdir -p $UPPERDIR $WORKDIR $OVERLAY $USER_ORIG ${MNT_USER}/.persistent
@@ -113,12 +118,12 @@ do_rw_mount() {
mount -o remount,rw /
cat /proc/mounts | grep overlay | logpipe
cat /proc/mounts | grep tmp | logpipe
- umount -l /tmp
- umount -l /var/volatile
+ umount -l /tmp >/dev/null 2>&1
+ umount -l /var/volatile >/dev/null 2>&1
cgroupmnts=$(sed -r -e 's/[^[:space:]]*[[:space:]]//' -e 's/[[:space:]]+.*//g' /proc/mounts | grep '^/orig')
for mp in ${cgroupmnts} ; do
- if [[ $mp != /orig ]] ; then
- umount -l $mp
+ if [[ $mp != /orig ]] && [[ -d $mp ]] ; then
+ umount -l $mp >/dev/null 2>&1
fi
done
}