From 892d5bb14f8f0ea4dcbf39c93ee6309827aeeb5c Mon Sep 17 00:00:00 2001 From: Stephan Gerhold Date: Mon, 25 Nov 2024 16:48:38 +0100 Subject: [PATCH] main/postmarketos-initramfs: always resize rootfs during boot (MR 5844) At the moment, the root file system is only resized to span the entire partition if we previously also resized the partition itself. However, if a rootfs image without subpartitions is flashed to a pre-existing partition this means that the installation only has very limited space available without manual resizing. Such a setup is used for devices using the "fastboot-bootpart" flasher (e.g. asus-me176c), where boot and root images are flashed to two separate partitions and the device boots directly from the boot partition. Avoid this problem on these devices by always resizing the root file system on each boot. All the resize tools exit early if the file system is already expanded to the maximum size. It's faster to call resize2fs unconditionally instead of manually checking if the file system needs resizing before. Similar tooling like systemd-growfs also resizes unconditionally. --- .../init_functions_2nd.sh | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/main/postmarketos-initramfs/init_functions_2nd.sh b/main/postmarketos-initramfs/init_functions_2nd.sh index 97f2a5336..93278fd4c 100644 --- a/main/postmarketos-initramfs/init_functions_2nd.sh +++ b/main/postmarketos-initramfs/init_functions_2nd.sh @@ -3,8 +3,6 @@ # Functions are notated with the reason they're only in # initramfs-extra -ROOT_PARTITION_RESIZED=0 - # udevd is too big setup_udev() { if ! command -v udevd > /dev/null || ! command -v udevadm > /dev/null; then @@ -49,7 +47,6 @@ resize_root_partition() { kpartx -d "$partition" parted -f -s "$partition_dev" resizepart 2 100% kpartx -afs "$partition_dev" - ROOT_PARTITION_RESIZED=1 else echo "Not resizing root partition ($partition): no free space left" fi @@ -64,7 +61,6 @@ resize_root_partition() { echo "Resize root partition ($partition)" parted -f -s "$partition_dev" resizepart 2 100% partprobe - ROOT_PARTITION_RESIZED=1 else echo "Not resizing root partition ($partition): no free space left" fi @@ -81,7 +77,6 @@ resize_root_partition() { echo "Resize root partition ($partition)" parted -f -s "$partition_dev" resizepart 3 100% partprobe - ROOT_PARTITION_RESIZED=1 else echo "Not resizing root partition ($partition): no free space left" fi @@ -93,33 +88,31 @@ resize_root_partition() { # resize2fs and resize.f2fs are too big resize_root_filesystem() { - if [ "$ROOT_PARTITION_RESIZED" = 1 ]; then - show_splash "Resizing filesystem during initial boot..." - partition="$(find_root_partition)" - touch /etc/mtab # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673323 - type="$(get_partition_type "$partition")" - case "$type" in - ext4) - echo "Resize 'ext4' root filesystem ($partition)" - modprobe ext4 - resize2fs -f "$partition" - ;; - f2fs) - echo "Resize 'f2fs' root filesystem ($partition)" - modprobe f2fs - resize.f2fs "$partition" - ;; - btrfs) - echo "Resize 'btrfs' root filesystem ($partition)" - modprobe btrfs - resize_root_filesystem_tmp_btrfs="$(mktemp -d)" - mount -t btrfs "$partition" "$resize_root_filesystem_tmp_btrfs" - btrfs filesystem resize max "$resize_root_filesystem_tmp_btrfs" - umount "$resize_root_filesystem_tmp_btrfs" - unset resize_root_filesystem_tmp_btrfs - ;; - *) echo "WARNING: Can not resize '$type' filesystem ($partition)." ;; - esac - show_splash "Loading..." - fi + show_splash "Resizing filesystem during initial boot..." + partition="$(find_root_partition)" + touch /etc/mtab # see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=673323 + type="$(get_partition_type "$partition")" + case "$type" in + ext4) + echo "Resize 'ext4' root filesystem ($partition)" + modprobe ext4 + resize2fs -f "$partition" + ;; + f2fs) + echo "Resize 'f2fs' root filesystem ($partition)" + modprobe f2fs + resize.f2fs "$partition" + ;; + btrfs) + echo "Resize 'btrfs' root filesystem ($partition)" + modprobe btrfs + resize_root_filesystem_tmp_btrfs="$(mktemp -d)" + mount -t btrfs "$partition" "$resize_root_filesystem_tmp_btrfs" + btrfs filesystem resize max "$resize_root_filesystem_tmp_btrfs" + umount "$resize_root_filesystem_tmp_btrfs" + unset resize_root_filesystem_tmp_btrfs + ;; + *) echo "WARNING: Can not resize '$type' filesystem ($partition)." ;; + esac + show_splash "Loading..." }