diff options
Diffstat (limited to 'recipes-core')
-rw-r--r-- | recipes-core/multitech/overlayfs-init/overlayfs.init | 88 | ||||
-rw-r--r-- | recipes-core/multitech/overlayfs-init_0.1.bb | 22 |
2 files changed, 110 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 diff --git a/recipes-core/multitech/overlayfs-init_0.1.bb b/recipes-core/multitech/overlayfs-init_0.1.bb new file mode 100644 index 0000000..a14ed2e --- /dev/null +++ b/recipes-core/multitech/overlayfs-init_0.1.bb @@ -0,0 +1,22 @@ +DESCRIPTION = "OverlayFS init" +HOMEPAGE = "http://www.multitech.com/" +LICENSE = "MIT" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" +PACKAGE_ARCH = "all" +PR = "r5" +RDEPENDS_${PN} += "bash" + +SRC_URI = " \ + file://overlayfs.init \ +" + +inherit allarch +inherit update-rc.d + +INITSCRIPT_NAME = "overlayfs" +INITSCRIPT_PARAMS = "start 01 S ." + +do_install() { + install -d ${D}/${sysconfdir}/init.d + install -m 0755 ${WORKDIR}/overlayfs.init ${D}/${sysconfdir}/init.d/overlayfs +} |