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:
commit
7bb5e1bfda
2 changed files with 20 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash -x
|
#!/bin/bash -xe
|
||||||
|
|
||||||
# Expand rootfs partition to its maximum size, if /.expand-rootfs exists.
|
# Expand rootfs partition to its maximum size, if /.expand-rootfs exists.
|
||||||
# Used by /etc/systemd/system/iiab-expand-rootfs.service on IIAB boot.
|
# 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:
|
# 2022-02-17: Uses do_expand_rootfs() from:
|
||||||
# https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config
|
# https://github.com/RPi-Distro/raspi-config/blob/master/raspi-config
|
||||||
raspi-config --expand-rootfs # REQUIRES A REBOOT
|
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)
|
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()
|
# 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
|
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
|
fi
|
||||||
|
|
||||||
# Expand partition
|
# 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
|
resize2fs $ROOT_PART
|
||||||
|
rc=$? # Make RC visible (as above)
|
||||||
|
|
||||||
# 2022-03-15: Legacy code below worked with Raspberry Pi microSD cards
|
# 2022-03-15: Legacy code below worked with Raspberry Pi microSD cards
|
||||||
# but *not* with USB boot drives, internal spinning disks/SSD's, etc.
|
# 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
|
# # Resize partition
|
||||||
# growpart /dev/$root_dev $root_part_no
|
# growpart /dev/$root_dev $root_part_no
|
||||||
# resize2fs /dev/$root_part
|
# resize2fs /dev/$root_part
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f /.expand-rootfs /.resize-rootfs
|
rm -f /.expand-rootfs /.resize-rootfs
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,14 +1,24 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Root Filesystem Auto-Expander
|
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]
|
[Service]
|
||||||
Environment=TERM=linux
|
Environment=TERM=linux
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/usr/sbin/iiab-expand-rootfs
|
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"
|
# "Standard output type syslog is obsolete"
|
||||||
# StandardError=syslog
|
# StandardError=syslog
|
||||||
# WHEREAS StandardError=journal is the default, per https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=
|
# WHEREAS StandardError=journal is the default, per https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=
|
||||||
RemainAfterExit=no
|
RemainAfterExit=yes
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=local-fs.target
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue