diff --git a/roles/1-prep/templates/iiab-rpi-max-rootfs.sh b/roles/1-prep/templates/iiab-rpi-max-rootfs.sh index d24788602..aa221bcf0 100644 --- a/roles/1-prep/templates/iiab-rpi-max-rootfs.sh +++ b/roles/1-prep/templates/iiab-rpi-max-rootfs.sh @@ -1,20 +1,32 @@ #!/bin/bash -x -# Resize rootfs and its partition on the rpi SD card to maximum size -# To be used by systemd service on boot -# Only resizes if /.resize-rootfs exists -# Assumes root is last partition -# Only works on F22 + where resizepart command exists -# Assumes sd card style partition name like p -if [ -f /.resize-rootfs ];then - echo "$0: maximizing rootfs partion" - # Calculate root partition - root_part=`lsblk -aP -o NAME,MOUNTPOINT|grep 'MOUNTPOINT="/"' |awk -F\" '{ print $2 }'` - root_dev=${root_part:0:-2} - root_part_no=${root_part: (-1)} +# Resize rootfs and its partition on the rpi SD card (or external USB +# disk if possible, e.g. with Raspberry Pi OS) to maximum size. - # Resize partition - growpart /dev/$root_dev $root_part_no - resize2fs /dev/$root_part - rm /.resize-rootfs +# To be used by /etc/systemd/system/iiab-rpi-root-resize.service on boot. +# Only resizes if /.resize-rootfs exists. +# Assumes root is last partition. + +if [ -f /.resize-rootfs ]; then + echo "$0: maximizing rootfs partion" + + if [ -x /usr/bin/raspi-config ]; then + # 2022-02-17: Works in many more situations, e.g. with USB disks (not + # just microSD cards). IF ONLY THIS ALSO WORKED ON Ubuntu/Mint/etc ! + raspi-config --expand-rootfs + else + # Assumes sd card style partition name like p + # Only works on F22 + where resizepart command exists + + # Calculate root partition + root_part=`lsblk -aP -o NAME,MOUNTPOINT | grep 'MOUNTPOINT="/"' | awk -F\" '{ print $2 }'` + root_dev=${root_part:0:-2} + root_part_no=${root_part: (-1)} + + # Resize partition + growpart /dev/$root_dev $root_part_no + resize2fs /dev/$root_part + fi + + rm /.resize-rootfs fi