X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=mount-latest-subvol;h=e1d4d1a74d56f4830d2de8319155cbfc51846ec5;hb=94fb80d967f107cbde4a3920dededbb406b2443b;hp=bf5ec9c844e27221d0a91548dfc834f16fdb6b05;hpb=b38f62582694bd678baa77bfeab627feefbc6a40;p=distro-setup diff --git a/mount-latest-subvol b/mount-latest-subvol index bf5ec9c..e1d4d1a 100644 --- a/mount-latest-subvol +++ b/mount-latest-subvol @@ -14,7 +14,11 @@ # limitations under the License. # usage: mount-latest-subvol +# +# Note, at source location, intentionally not executable, run and read +# install-my-scripts. +cd / [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" errcatch() { @@ -81,6 +85,17 @@ fstab() { tu /etc/fstab <<<"$l" done } +pid-check() { + for p in ${pids}; do + for m in ${my_pids[@]}; do + if (( p == m )); then + echo "$0: error: pids to kill includes our pid or a parent. ps output:" >&2 + ps -f -p $p + exit 1 + fi + done + done +} kill-dir() { for sig; do echo kill-dir $sig @@ -88,11 +103,13 @@ kill-dir() { if pids=$(timeout 4 lsof -t $dir); then found_pids=true timeout 4 lsof -w $dir + pid-check kill -$sig $pids fi # fuser will find open sockets that lsof won't, for example from gpg-agent. # note: -v shows kernel processes, which then doesn't return true when we want - if timeout 4 fuser -m $dir &>/dev/null; then + if pids=$(timeout 4 fuser -m $dir 2>/dev/null); then + pid-check found_pids=true fuser -$sig -mvk $dir fi @@ -112,9 +129,25 @@ fi ret=0 ##### begin setup fstab for subvols we care about ###### -first_root_crypt=$(awk '$2 == "/" {print $1}' /etc/mtab) +root_dev=$(awk '$2 == "/" {print $1}' /etc/mtab) + + +if cryptsetup status $root_dev &>/dev/null; then + crypt_dev=$root_dev +else # if we are in a recovery boot, find the next best crypt device + noauto=,noauto + for dev in $(dmsetup ls --target crypt | awk '{print $1}'); do + dev=/dev/mapper/$dev + if awk '{print $1}' /etc/mtab | grep -Fx $dev &>/dev/null; then + crypt_dev=$dev + break + fi + done +fi + + fstab </dev/null; then @@ -172,7 +219,9 @@ for vol in q a o i; do # if latest is already mounted, make sure binds are mounted and move on - if e check-subvol-stale $d; then + e check-subvol-stale $d + # populated by check-subvol-stale if stale + if ! fresh_snap=$(