From be2a961a1f6bae4d9e5ed8c00089a512520abdee05c2523ef3239dd82630f1d7 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Tue, 8 Jun 2021 13:14:14 +0000 Subject: [PATCH] Accepting request 898426 from home:lnussel:usrmove - early exit in case of overlayfs (boo#1187027) OBS-URL: https://build.opensuse.org/request/show/898426 OBS-URL: https://build.opensuse.org/package/show/Base:System/compat-usrmerge?expand=0&rev=17 --- compat-usrmerge.changes | 5 +++++ convertfs | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/compat-usrmerge.changes b/compat-usrmerge.changes index a873f68..94eb82c 100644 --- a/compat-usrmerge.changes +++ b/compat-usrmerge.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Tue Jun 8 12:03:52 UTC 2021 - Ludwig Nussel + +- early exit in case of overlayfs (boo#1187027) + ------------------------------------------------------------------- Tue Jun 8 07:37:33 UTC 2021 - Fabian Vogt diff --git a/convertfs b/convertfs index 01cc310..e82a95d 100644 --- a/convertfs +++ b/convertfs @@ -3,6 +3,19 @@ ROOT= +is_usrmerged() { + local r=1 + for dir in bin sbin lib lib64; do + [ -d "$ROOT/$dir" ] || continue + [ -L "$ROOT/$dir" ] || return 1 + r=0 + done + return "$r" +} + +# check if there's anything to do +is_usrmerged && exit 0 + # the package is installed with AutoReq off, so no guarantee that # coreutils actually works if ! { cp --help && find --help; } > /dev/null; then @@ -12,7 +25,7 @@ fi # clean up after ourselves no matter how we die. cleanup() { - echo "Something failed, cleaning up" + echo "UsrMerge conversion failed, cleaning up" for dir in bin sbin lib lib64; do rm -rf -- "$ROOT/usr/${dir}.usrmerge" done @@ -26,10 +39,16 @@ trap 'exit 1;' SIGINT set -e -usrismountpoint= +if [ "$(stat -f -c %T "${ROOT:-/}")" = "overlayfs" ]; then + echo "UsrMerge conversion does not work on overlayfs" + exit 1 +fi + +CP_HARDLINK="-l" while read dev mp other; do - [ "$mp" = "/usr" ] && usrismountpoint=1 + [ "$mp" = "$ROOT/usr" ] && CP_HARDLINK="" for dir in bin sbin lib lib64; do + [ -d "$ROOT/$dir" ] || continue if [ "${mp#$ROOT/$dir}" != "$mp" ] || [ "${mp#$ROOT/usr/$dir}" != "$mp" ]; then echo "Please unmount $mp before the conversion" exit 1 @@ -37,8 +56,6 @@ while read dev mp other; do done done < /proc/mounts -[ -n "$usrismountpoint" ] || CP_HARDLINK="-l" - # merge / and /usr in new dir in /usr for dir in bin sbin lib lib64; do rm -rf -- "$ROOT/usr/${dir}.usrmerge"