diff --git a/roles/1-prep/templates/iiab-expand-rootfs b/roles/1-prep/templates/iiab-expand-rootfs index 2cd28de46..a1fd06772 100644 --- a/roles/1-prep/templates/iiab-expand-rootfs +++ b/roles/1-prep/templates/iiab-expand-rootfs @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash -xe # Expand rootfs partition to its maximum size, if /.expand-rootfs exists. # Used by /etc/systemd/system/iiab-expand-rootfs.service on IIAB boot. @@ -15,6 +15,8 @@ if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then # 2022-02-17: Uses do_expand_rootfs() from: # https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config raspi-config --expand-rootfs # REQUIRES A REBOOT + rm -f /.expand-rootfs /.resize-rootfs + reboot # In future, we might warn interactive users that a reboot is coming? else # REQUIRES NO REBOOT; BEWARE iiab-expand-rootfs.service RACE CONDITION WITH fsck (PR #2522 & #3325) # 2022-03-15: Borrows from above raspi-config URL's do_expand_rootfs() ROOT_PART="$(findmnt / -o SOURCE -n)" # e.g. /dev/sda2 or /dev/mmcblk0p2 @@ -30,8 +32,10 @@ if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then fi # Expand partition - growpart $ROOT_DEV $ROOT_PART_NUM # raspi-config instead uses fdisk + growpart $ROOT_DEV $ROOT_PART_NUM || true # raspi-config instead uses fdisk. WARNING: growpart RC 2 is more severe than RC 1, and should possibly be handled separately in future? + rc=$? # Make Return Code visible, for 'bash -x' resize2fs $ROOT_PART + rc=$? # Make RC visible (as above) # 2022-03-15: Legacy code below worked with Raspberry Pi microSD cards # but *not* with USB boot drives, internal spinning disks/SSD's, etc. @@ -53,7 +57,7 @@ if [ -f /.expand-rootfs ] || [ -f /.resize-rootfs ]; then # # Resize partition # growpart /dev/$root_dev $root_part_no # resize2fs /dev/$root_part + + rm -f /.expand-rootfs /.resize-rootfs fi - - rm -f /.expand-rootfs /.resize-rootfs fi diff --git a/roles/1-prep/templates/iiab-expand-rootfs.service b/roles/1-prep/templates/iiab-expand-rootfs.service index f7f68402c..91de4cc5b 100644 --- a/roles/1-prep/templates/iiab-expand-rootfs.service +++ b/roles/1-prep/templates/iiab-expand-rootfs.service @@ -1,14 +1,24 @@ [Unit] Description=Root Filesystem Auto-Expander +DefaultDependencies=no +# 2022-08-08: IIAB's 4 core OS's have 'After=systemd-fsck-root.service' WITHIN +# systemd-remount-fs.service, allowing us to avoid #3325 race condition w/ fsck +After=systemd-remount-fs.service +# 2022-08-08: While dphys-swapfile.service doesn't exist on Ubuntu, Mint +# and pure Debian, the following line may still serve a purpose on RasPiOS: +Before=dphys-swapfile.service [Service] Environment=TERM=linux Type=oneshot ExecStart=/usr/sbin/iiab-expand-rootfs +# 2022-08-08: By default, systemd dangerously kills rootfs expansion after just +# 90s (1TB microSD cards take ~8 min to expand). Let's remove the time limit: +TimeoutSec=infinity # "Standard output type syslog is obsolete" # StandardError=syslog # WHEREAS StandardError=journal is the default, per https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput= -RemainAfterExit=no +RemainAfterExit=yes [Install] -WantedBy=multi-user.target +WantedBy=local-fs.target