From 0e776cc153ef90d76d1a428c41c3d2bf0f64a304 Mon Sep 17 00:00:00 2001 From: Serge Schneider Date: Fri, 15 May 2020 11:10:26 +0100 Subject: [PATCH] Fix up resize scripts --- debian/changelog | 6 +++--- raspi-config | 30 ++++++++++++----------------- usr/lib/raspi-config/init_resize.sh | 13 ++++++++----- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/debian/changelog b/debian/changelog index 551849e..19ff9e2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,10 +1,10 @@ -raspi-config (20200514) buster; urgency=medium +raspi-config (20200515) buster; urgency=medium * Update initial resize script - Change disk ID to avoid clashes - * Add boot order selector + * Add support for USB resize - -- Serge Schneider Thu, 14 May 2020 06:33:23 +0100 + -- Serge Schneider Fri, 15 May 2020 08:47:17 +0100 raspi-config (20200504) buster; urgency=medium diff --git a/raspi-config b/raspi-config index 66df6b5..d2c1230 100755 --- a/raspi-config +++ b/raspi-config @@ -122,21 +122,18 @@ you have heavily customised your installation.\ } get_can_expand() { - ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p') + ROOT_PART="$(findmnt / -o source -n)" + ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")" - PART_NUM=${ROOT_PART#mmcblk0p} - if [ "$PART_NUM" = "$ROOT_PART" ]; then - echo 1 - exit - fi + PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")" if [ "$PART_NUM" -ne 2 ]; then echo 1 exit fi - LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:) - if [ $LAST_PART_NUM -ne $PART_NUM ]; then + LAST_PART_NUM=$(parted "ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:) + if [ "$LAST_PART_NUM" -ne "$PART_NUM" ]; then echo 1 exit fi @@ -144,13 +141,10 @@ get_can_expand() { } do_expand_rootfs() { - ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p') + ROOT_PART="$(findmnt / -o source -n)" + ROOT_DEV="/dev/$(lsblk -no pkname "$ROOT_PART")" - PART_NUM=${ROOT_PART#mmcblk0p} - if [ "$PART_NUM" = "$ROOT_PART" ]; then - whiptail --msgbox "$ROOT_PART is not an SD card. Don't know how to expand" 20 60 2 - return 0 - fi + PART_NUM="$(echo "$ROOT_PART" | grep -o "[[:digit:]]*$")" # NOTE: the NOOBS partition layout confuses parted. For now, let's only # agree to work with a sufficiently simple partition layout @@ -159,18 +153,18 @@ do_expand_rootfs() { return 0 fi - LAST_PART_NUM=$(parted /dev/mmcblk0 -ms unit s p | tail -n 1 | cut -f 1 -d:) + LAST_PART_NUM=$(parted "$ROOT_DEV" -ms unit s p | tail -n 1 | cut -f 1 -d:) if [ $LAST_PART_NUM -ne $PART_NUM ]; then whiptail --msgbox "$ROOT_PART is not the last partition. Don't know how to expand" 20 60 2 return 0 fi # Get the starting offset of the root partition - PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g') + PART_START=$(parted "$ROOT_DEV" -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g') [ "$PART_START" ] || return 1 # Return value will likely be error for fdisk as it fails to reload the # partition table because the root fs is mounted - fdisk /dev/mmcblk0 < /etc/init.d/resize2fs_once && case "\$1" in start) log_daemon_msg "Starting resize2fs_once" && - resize2fs /dev/$ROOT_PART && + resize2fs "$ROOT_PART" && update-rc.d resize2fs_once remove && rm /etc/init.d/resize2fs_once && log_end_msg \$? diff --git a/usr/lib/raspi-config/init_resize.sh b/usr/lib/raspi-config/init_resize.sh index 4a93089..36dbef1 100755 --- a/usr/lib/raspi-config/init_resize.sh +++ b/usr/lib/raspi-config/init_resize.sh @@ -22,7 +22,7 @@ check_commands () { sleep 5 return 1 fi - for COMMAND in grep cut sed parted fdisk findmnt partprobe; do + for COMMAND in grep cut sed parted fdisk findmnt; do if ! command -v $COMMAND > /dev/null; then FAIL_REASON="$COMMAND not found" return 1 @@ -78,18 +78,21 @@ fix_partuuid() { mount -o remount,rw "$ROOT_PART_DEV" mount -o remount,rw "$BOOT_PART_DEV" DISKID="$(tr -dc 'a-f0-9' < /dev/hwrng | dd bs=1 count=8 2>/dev/null)" - fdisk "$ROOT_DEV" < /dev/null <