From bf71540f66f655dc47f10053ab13e022b23099ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20unbrot=20P=C3=A4tzold?= Date: Mon, 27 Apr 2026 16:26:27 +0200 Subject: [PATCH] Fix btrfs resize: use online resize instead of unmount/remount btrfs supports live filesystem resize, so there is no need to unmount a mounted btrfs partition before shrinking it. This also avoids umount failures when the partition is busy (e.g. /home with an active SSH session). ext4 still requires offline resize. Co-Authored-By: Claude Sonnet 4.6 --- system_setup/install.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/system_setup/install.sh b/system_setup/install.sh index 658a156..bc95dd3 100755 --- a/system_setup/install.sh +++ b/system_setup/install.sh @@ -345,14 +345,14 @@ if [[ "$MODE" == "shrink" ]]; then echo " After shrink : ${CURR_START} MiB – ${NEW_END} MiB (filesystem: ${NEW_FS_MIB} MiB)" echo " New OEMDRV : ${OEMDRV_START} MiB – ${OEMDRV_END} MiB (${SHRINK_MIB} MiB)" - if [[ "$S_MNT" != "-" && -n "$S_MNT" ]]; then - info "Unmounting $S_DEV from $S_MNT..." - ORIG_MNT="$S_MNT" - umount "$S_DEV" || die "Cannot unmount $S_DEV. Close all open files and try again." - WAS_MOUNTED=1 - fi - if [[ "$S_FS" == "ext4" ]]; then + # ext4 requires offline resize — unmount first + if [[ "$S_MNT" != "-" && -n "$S_MNT" ]]; then + info "Unmounting $S_DEV from $S_MNT..." + ORIG_MNT="$S_MNT" + umount "$S_DEV" || die "Cannot unmount $S_DEV. Close all open files and try again." + WAS_MOUNTED=1 + fi info "Running e2fsck on $S_DEV..." e2fsck -f "$S_DEV" || die "e2fsck found errors on $S_DEV. Fix them before retrying." @@ -360,13 +360,20 @@ if [[ "$MODE" == "shrink" ]]; then resize2fs "$S_DEV" "${NEW_FS_MIB}M" || die "resize2fs failed." elif [[ "$S_FS" == "btrfs" ]]; then + # btrfs supports online resize — use existing mount point if available, + # otherwise mount temporarily info "Shrinking btrfs filesystem on $S_DEV to ${NEW_FS_MIB} MiB..." - TMP_MNT=$(mktemp -d /tmp/oemdrv_btrfs.XXXXXX) - mount "$S_DEV" "$TMP_MNT" || { rmdir "$TMP_MNT"; die "Cannot mount $S_DEV for btrfs resize."; } - btrfs filesystem resize "${NEW_FS_MIB}m" "$TMP_MNT" \ - || { umount "$TMP_MNT"; rmdir "$TMP_MNT"; die "btrfs filesystem resize failed."; } - sync - umount "$TMP_MNT" && rmdir "$TMP_MNT" + if [[ "$S_MNT" != "-" && -n "$S_MNT" ]]; then + btrfs filesystem resize "${NEW_FS_MIB}m" "$S_MNT" \ + || die "btrfs filesystem resize failed." + else + TMP_MNT=$(mktemp -d /tmp/oemdrv_btrfs.XXXXXX) + mount "$S_DEV" "$TMP_MNT" || { rmdir "$TMP_MNT"; die "Cannot mount $S_DEV for btrfs resize."; } + btrfs filesystem resize "${NEW_FS_MIB}m" "$TMP_MNT" \ + || { umount "$TMP_MNT"; rmdir "$TMP_MNT"; die "btrfs filesystem resize failed."; } + sync + umount "$TMP_MNT" && rmdir "$TMP_MNT" + fi fi info "Shrinking partition $S_PNUM to ${NEW_END} MiB in partition table..."