1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

Merge pull request #3337 from holta/expand-rootfs-resilience

Straw Man 1-prep/templates/iiab-expand-rootfs.service based on 2020's PR #2522 + /usr/sbin/iiab-expand-rootfs "bash -xe" exit-on-error (to defer deleting /.expand-rootfs)
This commit is contained in:
A Holt 2022-09-26 10:47:23 -04:00 committed by GitHub
commit 7bb5e1bfda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -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

View file

@ -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