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..."