diff options
author | John Klug <john.klug@multitech.com> | 2021-07-26 12:16:16 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2021-07-26 12:16:16 -0500 |
commit | 2b59bd9b74423fb8a26efc5d64b6950b73b87bf9 (patch) | |
tree | 8bfff83db3ffd9aad75ee99f7f9cddeb2605d211 /recipes-core/multitech/overlayfs-init/overlayfs.init | |
parent | 0142be7731c3c5eba56c3b67c04235c519d7fd72 (diff) | |
download | meta-mlinux-2b59bd9b74423fb8a26efc5d64b6950b73b87bf9.tar.gz meta-mlinux-2b59bd9b74423fb8a26efc5d64b6950b73b87bf9.tar.bz2 meta-mlinux-2b59bd9b74423fb8a26efc5d64b6950b73b87bf9.zip |
overlayfs for mtcap3
Diffstat (limited to 'recipes-core/multitech/overlayfs-init/overlayfs.init')
-rw-r--r-- | recipes-core/multitech/overlayfs-init/overlayfs.init | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/recipes-core/multitech/overlayfs-init/overlayfs.init b/recipes-core/multitech/overlayfs-init/overlayfs.init new file mode 100644 index 0000000..4da6217 --- /dev/null +++ b/recipes-core/multitech/overlayfs-init/overlayfs.init @@ -0,0 +1,88 @@ +#!/bin/bash + +MNT_USER="/mnt/user" +OVERLAY="$MNT_USER/overlay" +WORKDIR="$MNT_USER/work" +UPPERDIR="$MNT_USER/upper" +LOWERDIR="/" +USER_ORIG="$UPPERDIR/orig" +USER_PARTITION="/dev/mtdblock9" +DO_ERASE_USERDATA_FILE="/mnt/user/.persistent/mts_do_erase_userdata" + +loginfo() { logger -s -t overlayfs "info: $@" 1>&2 ; } + +mnt_user() { + mkdir -p $MNT_USER + mount -t jffs2 $USER_PARTITION $MNT_USER +} + +switch_root() { + NEW_ROOT=$1 + mount -o noatime,move --bind /run $NEW_ROOT/run + mount -o noatime,move --bind /dev $NEW_ROOT/dev + mount -o noatime,move --bind /proc $NEW_ROOT/proc + mount -o noatime,move --bind /sys $NEW_ROOT/sys + /sbin/pivot_root $NEW_ROOT $NEW_ROOT/orig +} + +# remove old hidden and non-hidden files and folders +do_remove_old() { + 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 + + 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" + done +} + +do_rw_mount() { + loginfo "Starting RW overlayfs" + mount -t tmpfs inittemp /mnt + mnt_user + + do_remove_old + + if u-boot printenv default_reset_f; then + do_select_old + do_remove_old + u-boot setenv default_reset_f + fi + + mkdir -p $UPPERDIR $WORKDIR $OVERLAY $USER_ORIG ${MNT_USER}/.persistent + loginfo "Mounting..." + mount -o noatime,lowerdir=$LOWERDIR,upperdir=$UPPERDIR,workdir=$WORKDIR -t overlay overlay $OVERLAY + + mkdir -p ${OVERLAY}/var/persistent + mount --bind ${MNT_USER}/.persistent ${OVERLAY}/var/persistent + + switch_root $OVERLAY +} + +do_start() { + do_rw_mount +} + +case $1 in +start) + do_start +;; +*) + echo "Usage: $0 {start}" +;; +esac |