diff options
-rwxr-xr-x | squashfu | 46 | ||||
-rw-r--r-- | squashfu.conf | 4 |
2 files changed, 37 insertions, 13 deletions
@@ -95,33 +95,53 @@ mount_squash () { } mount_union_with_bins () { -# Arguments: numbers of bins to be mounted (variable number) -# Returns: 0 on successful mount, non-zero on failure - info "Mounting union" + # Args: Nummern der zu mountenden Bins (erster = upperdir/rw, Rest = lowerdirs/ro) + info "Mounting union (overlayfs)" debug "Requested to mount bins: $*" - # Mount first as rw, shift, and mount the rest ro - local branches="br=${BINS_DIR}/$1=rw:"; shift - if [[ -n $1 ]]; then - for bin in $*; do - branches="$branches$BINS_DIR/$bin=ro:" - done + local upperdir workdir lowerdirs + + if [[ -z "$1" ]]; then + # Kein Bin angegeben -> nur Seed sichtbar machen (rw-Schicht temporär & leer) + upperdir="$TMP_UPPER" + workdir="$TMP_WORKDIR" + mkdir -p "$upperdir" "$workdir" + lowerdirs="$SQUASH_MOUNT" + else + local upper_bin="$1"; shift + upperdir="$BINS_DIR/$upper_bin" + workdir="$WORK_DIR/$upper_bin.work" + mkdir -p "$upperdir" "$workdir" + + # Reihenfolge in overlayfs: links = „näher oben“ (neuer), rechts = „tiefer“ (älter) + # Wir wollen: ältere Bins unterhalb, ganz unten der Seed + lowerdirs="" + if [[ $# -gt 0 ]]; then + for bin in "$@"; do + lowerdirs+="$BINS_DIR/$bin:" + done + fi + lowerdirs+="$SQUASH_MOUNT" fi - branches="${branches}${SQUASH_MOUNT}=ro" - mount -t aufs none "$UNION_MOUNT" -o udba=reval,$branches + # Overlay mounten + # Hinweis: upperdir & workdir müssen auf gleichem FS liegen; workdir muss leer sein. + mount -t overlay overlay \ + -o "lowerdir=$lowerdirs,upperdir=$upperdir,workdir=$workdir" \ + "$UNION_MOUNT" return $? } # Unmounting functions unmount_union () { -# Args: none -# Returns: return code from umount info "Unmounting union" umount "$UNION_MOUNT" 2>/dev/null local ret=$? sleep .5 + + # temporäre Upper/Work-Dirs (nur wenn leer) aufräumen + rmdir "$TMP_WORKDIR" "$TMP_UPPER" 2>/dev/null || true return $ret } diff --git a/squashfu.conf b/squashfu.conf index f15b83d..cfd6da1 100644 --- a/squashfu.conf +++ b/squashfu.conf @@ -20,6 +20,10 @@ BINS_DIR="${BKUP_ROOT}/.bins" SQUASH_MOUNT="${BKUP_ROOT}/ro" UNION_MOUNT="${BKUP_ROOT}/rw" +WORK_DIR="${WORK_DIR:-$BINS_DIR/.work}" +TMP_UPPER="${BINS_DIR}/.tmp_upper" +TMP_WORKDIR="${WORK_DIR}/.tmp_work" + # Cheezy name, important file. This is a catalog of your incrementals. # Bad things will happen if this file is corrupted or lost. BINVENTORY="/var/lib/squashfu.inv" |