diff options
| -rw-r--r-- | fstab.sh | 90 |
1 files changed, 57 insertions, 33 deletions
@@ -151,7 +151,6 @@ is_mounted() { grep -qs " $mp " /proc/mounts return $? fi - return 1 } @@ -164,16 +163,9 @@ is_swap_active() { awk 'NR>1{print $1}' /proc/swaps | grep -Fxq "$spec" && return 0 awk 'NR>1{n=$1; sub(".*/","",n); print n}' /proc/swaps | grep -Fxq "$base" && return 0 fi - return 1 } -exists_root() { - p="$1" - # shellcheck disable=SC2086 - su $su_options -c "test -e $(shell_quote "$p")" -} - log "$0 $args" # --- process each fstab line --- @@ -225,7 +217,7 @@ while IFS= read -r rawline || [ -n "$rawline" ]; do continue fi - # --- bindfs filesystem mounts --- + # --- bindfs filesystem mounts (first try, then mkdir+retry) --- if [ "$fs_vfstype" = "bindfs" ]; then if is_mounted "$fs_file"; then log "Line $line_no: $fs_file already mounted — skipped." @@ -235,66 +227,98 @@ while IFS= read -r rawline || [ -n "$rawline" ]; do err "Line $line_no: bindfs not available but requested (vfstype=bindfs)." continue fi - if ! exists_root "$fs_file"; then - log "Line $line_no: Creating mountpoint $fs_file" - run_root mkdir -p "$fs_file" || { - err "Line $line_no: mkdir failed for $fs_file" + + # 1. Versuch: direkt mounten (ohne mkdir) + if [ "$fs_mntops" = "-" ]; then + log "Line $line_no: bindfs mount: $fs_spec -> $fs_file" + if run_root bindfs "$fs_spec" "$fs_file"; then + continue + fi + else + log "Line $line_no: bindfs mount: $fs_spec -> $fs_file (opts=$fs_mntops)" + if run_root bindfs -o "$fs_mntops" "$fs_spec" "$fs_file"; then continue - } + fi + fi + + # 2. Fallback: Mountpoint anlegen und 1x retry + log "Line $line_no: first bindfs attempt failed — creating mountpoint and retrying" + if ! run_root mkdir -p "$fs_file"; then + err "Line $line_no: mkdir failed for $fs_file" + continue fi + if [ "$fs_mntops" = "-" ]; then - log "Line $line_no: bindfs mount: $fs_spec -> $fs_file" run_root bindfs "$fs_spec" "$fs_file" || true else - # bindfs versteht FUSE-Optionen via -o "<opts>" - log "Line $line_no: bindfs mount: $fs_spec -> $fs_file (opts=$fs_mntops)" run_root bindfs -o "$fs_mntops" "$fs_spec" "$fs_file" || true fi continue fi - # --- bind / rbind mounts --- + # --- bind / rbind mounts (first try, then mkdir+retry) --- echo "$fs_mntops" | grep -q bind && { if is_mounted "$fs_file"; then log "Line $line_no: $fs_file already mounted — skipped." continue fi - if ! exists_root "$fs_file"; then - log "Line $line_no: Creating mountpoint $fs_file" - run_root mkdir -p "$fs_file" || { - err "Line $line_no: mkdir failed for $fs_file" + + # 1. Versuch ohne mkdir + if echo "$fs_mntops" | grep -qw rbind; then + log "Line $line_no: rbind mount: $fs_spec -> $fs_file" + if run_root mount --rbind "$fs_spec" "$fs_file"; then continue - } + fi + else + log "Line $line_no: bind mount: $fs_spec -> $fs_file" + if run_root mount --bind "$fs_spec" "$fs_file"; then + continue + fi + fi + + # 2. Fallback mit mkdir + Retry + log "Line $line_no: first bind/rbind attempt failed — creating mountpoint and retrying" + if ! run_root mkdir -p "$fs_file"; then + err "Line $line_no: mkdir failed for $fs_file" + continue fi if echo "$fs_mntops" | grep -qw rbind; then - log "Line $line_no: rbind mount: $fs_spec -> $fs_file" run_root mount --rbind "$fs_spec" "$fs_file" || true else - log "Line $line_no: bind mount: $fs_spec -> $fs_file" run_root mount --bind "$fs_spec" "$fs_file" || true fi continue } - # --- regular filesystem mounts --- + # --- regular filesystem mounts (first try, then mkdir+retry) --- if is_mounted "$fs_file"; then log "Line $line_no: $fs_file already mounted — skipped." continue fi - if ! exists_root "$fs_file"; then - log "Line $line_no: Creating mountpoint $fs_file" - run_root mkdir -p "$fs_file" || { - err "Line $line_no: mkdir failed" + # 1. Versuch: direkt mounten + if [ "$fs_mntops" = "-" ]; then + log "Line $line_no: Mounting $fs_spec -> $fs_file (type=$fs_vfstype)" + if run_root mount -t "$fs_vfstype" "$fs_spec" "$fs_file"; then continue - } + fi + else + log "Line $line_no: Mounting $fs_spec -> $fs_file (type=$fs_vfstype, opts=$fs_mntops)" + if run_root mount -t "$fs_vfstype" -o "$fs_mntops" "$fs_spec" "$fs_file"; then + continue + fi + fi + + # 2. Fallback: mkdir + Retry + log "Line $line_no: first mount attempt failed — creating mountpoint and retrying" + if ! run_root mkdir -p "$fs_file"; then + err "Line $line_no: mkdir failed" + continue fi if [ "$fs_mntops" = "-" ]; then - log "Line $line_no: Mounting $fs_spec -> $fs_file (type=$fs_vfstype)" run_root mount -t "$fs_vfstype" "$fs_spec" "$fs_file" || true else - log "Line $line_no: Mounting $fs_spec -> $fs_file (type=$fs_vfstype, opts=$fs_mntops)" run_root mount -t "$fs_vfstype" -o "$fs_mntops" "$fs_spec" "$fs_file" || true fi done <"$FSTAB_FILE" |
