From 205dc2171862078d4a8ff4ee44ff807153f6a947 Mon Sep 17 00:00:00 2001 From: Diederik de Haas Date: Sun, 6 Nov 2022 20:17:27 +0100 Subject: [PATCH 1/3] Document and complete rpi-resizerootfs hook The main trigger was a missing program in the initramfs, which probably everyone assumed was there ... but wasn't. (See next commit ...) So instead list every program that we need/call, so that we *know* that that program is included in the initramfs. Also document this new 'policy'. Also group the programs by the package which has them and sort the list alphabetically by the package names. --- .../initramfs-tools/hooks/rpi-resizerootfs | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs b/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs index f4776aa..76df689 100755 --- a/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs +++ b/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs @@ -13,11 +13,32 @@ esac . /usr/share/initramfs-tools/hook-functions -# XXX: tail and realpath are included by default, right? -#copy_exec /usr/bin/realpath -#copy_exec /usr/bin/tail -copy_exec /sbin/blkid -copy_exec /bin/lsblk +# List ALL the programs we need, because we explicitly call them +# Don't *assume* it will be included! +# The update-initramfs script will figure out any dependencies +# that also need to be included, so lets not do that +# +# Find the path as used by the package itself; usrmerge may not be used + +# from coreutils +copy_exec /usr/bin/realpath +copy_exec /usr/bin/tail +copy_exec /usr/bin/test + +# from e2fsprogs +copy_exec /sbin/resize2fs + +# from grep +copy_exec /bin/grep + +# from mount +copy_exec /bin/mount +copy_exec /bin/umount + +# from parted copy_exec /sbin/parted copy_exec /sbin/partprobe -copy_exec /sbin/resize2fs + +# from util-linux +copy_exec /bin/lsblk +copy_exec /sbin/blkid From 82dfcf25ff708269c3ff2c4c8f3e094ae6505b39 Mon Sep 17 00:00:00 2001 From: Diederik de Haas Date: Sun, 6 Nov 2022 23:06:05 +0100 Subject: [PATCH 2/3] Explicitly copy 'fsck*' into the initramfs While fsck.ext4 and fsck.vfat are part of the initramfs, it turns out that fsck itself isn't! While it normally gets included in the initramfs, for some reason that doesn't happen with our image creation, so it isn't available on first boot, so explicitly copy 'fsck' so that it will be included. For that to work, 'logsave' is needed too, so include that as well. During boot up, initramfs wants to check the filesystems and it does so via `fsck`, which then (presumably) checks the filesystem being used and calls the appropriate fsck.* to do the actual checking. But when `fsck` itself isn't available you get the following warning: "Warning: fsck not present, so skipping root file system" When it is available, you'll get a message like this: "Begin: Will now check root file system ... fsck from util-linux 2.38.1" Let's also follow our own advise and not *assume* the needed fsck programs are present in initramfs, but add them explicitly. Now we can start the resize operations while knowing the current filesystem is in a proper/clean state. --- rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs b/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs index 76df689..35e67fc 100755 --- a/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs +++ b/rootfs/etc/initramfs-tools/hooks/rpi-resizerootfs @@ -25,12 +25,19 @@ copy_exec /usr/bin/realpath copy_exec /usr/bin/tail copy_exec /usr/bin/test +# from dosfstools +copy_exec /sbin/fsck.vfat + # from e2fsprogs copy_exec /sbin/resize2fs +copy_exec /sbin/fsck.ext4 # from grep copy_exec /bin/grep +# from logsave +copy_exec /sbin/logsave + # from mount copy_exec /bin/mount copy_exec /bin/umount @@ -42,3 +49,4 @@ copy_exec /sbin/partprobe # from util-linux copy_exec /bin/lsblk copy_exec /sbin/blkid +copy_exec /sbin/fsck From 8fbe0ac9e3d11dbf4132ff1034a24fcedcc4d00d Mon Sep 17 00:00:00 2001 From: Diederik de Haas Date: Tue, 15 Nov 2022 17:25:59 +0100 Subject: [PATCH 3/3] Recheck the root filesystem after expanding it. Checking the root filesystem before mounting it is always a good idea. But after changing the root filesystem, it is especially important to (re-)check it to ensure everything went fine. So add that check. --- .../etc/initramfs-tools/scripts/local-bottom/rpi-resizerootfs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rootfs/etc/initramfs-tools/scripts/local-bottom/rpi-resizerootfs b/rootfs/etc/initramfs-tools/scripts/local-bottom/rpi-resizerootfs index 64b4dee..3826847 100755 --- a/rootfs/etc/initramfs-tools/scripts/local-bottom/rpi-resizerootfs +++ b/rootfs/etc/initramfs-tools/scripts/local-bottom/rpi-resizerootfs @@ -45,6 +45,9 @@ wait_for_udev 5 partprobe "$rootdev" resize2fs "$rootpart" +# After resizing, (re)check the root partition's filesystem +fsck "$rootpart" + # Remount root # Don't quote ${ROOTFLAGS} as that results in an extra (empty) argument # to 'mount', which in turn causes a boot failure