Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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) #3337

Merged
merged 11 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions roles/1-prep/templates/iiab-expand-rootfs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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
14 changes: 12 additions & 2 deletions roles/1-prep/templates/iiab-expand-rootfs.service
Original file line number Diff line number Diff line change
@@ -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