public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "Schmidl, Tobias" <tobiasschmidl@siemens.com>
To: "Bezdeka, Florian" <florian.bezdeka@siemens.com>,
	"isar-users@googlegroups.com" <isar-users@googlegroups.com>
Cc: "jan.kiszka@siemens.com" <jan.kiszka@siemens.com>,
	"Moessbauer, Felix" <felix.moessbauer@siemens.com>,
	"Schild, Henning" <henning.schild@siemens.com>
Subject: Re: WARNING: expand-on-first boot might shrink your partition on Debian bookworm
Date: Fri, 8 Jul 2022 06:35:15 +0000	[thread overview]
Message-ID: <24d0a5bc8d7a8545bf9465a3bd54b0fce8942d01.camel@siemens.com> (raw)
In-Reply-To: <e015d316-30bd-e9f1-d477-bd97c8a4c9ed@siemens.com>

Am Donnerstag, dem 07.07.2022 um 09:48 +0200 schrieb Florian Bezdeka:
> Hi all,
> 
> here comes another Debian bookworm related problem. This time related to
> expand-on-first-boot, which destroys my image during the fist boot.
> 
> The linux-util packages has been updated and includes some changes
> related to partition alignment. See [1]. (Thanks Henning for pointing me
> here.) It might happen now that the last partition is shrinked instead
> of expanded.
> 
> […]
> 
> Booting up again stops in the initrd with the following error:
> 
> (initramfs) [    1.978569] EXT4-fs (sda2): bad geometry: block count
> 550586 exceeds size of device (550400 blocks)
> 
> resize2fs called from expand-last-partition.sh already throws a warning
> resize2fs: New size smaller than minimum (550586)
> 
> 


I might have a solution:


diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
index 31f1ae3..5da9f7a 100755
--- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
+++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh
@@ -22,6 +22,23 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
        exit 1
 fi
 
+# this value is purely speculative
+BUFFER_SIZE=16384
+BOOT_DEV_NAME=${BOOT_DEV##*/}
+DISK_SIZE="$(cat /sys/class/block/"${BOOT_DEV_NAME}"/size)"
+ALL_PARTS_SIZE=0
+for PARTITION in /sys/class/block/"${BOOT_DEV_NAME}"[1-9]*; do
+       PART_SIZE=$(cat "${PARTITION}"/size)
+       ALL_PARTS_SIZE=$((ALL_PARTS_SIZE + PART_SIZE))
+done
+echo "Disk ${BOOT_DEV}: ${DISK_SIZE}, all partitions combined: ${ALL_PARTS_SIZE}" >&2
+
+MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE))
+if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
+       echo "Disk is not big enough, won't resize. Current size: $DISK_SIZE, minimal size for resizing: $MINIMAL_SIZE" >&2
+       #exit 0
+fi
+
 LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
 
 # Transform the partition table as follows:


The problem is - the numbers don't really add up. We see a difference of
128 blocks - that IMHO isn't reflected anywhere in the code.

I would even opt for bigger numbers, maybe 32k blocks. If the difference
in size is so low, the benefit of resizing is marginal.

Kind regards,

Tobias

  parent reply	other threads:[~2022-07-08  6:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  7:48 Florian Bezdeka
2022-07-07  8:20 ` Schmidl, Tobias
2022-07-07  8:54 ` Henning Schild
2022-07-07 10:51   ` Bezdeka, Florian
2022-07-07 11:18     ` Henning Schild
2022-07-07  8:59 ` Henning Schild
2022-07-07  9:30   ` Schmidl, Tobias
2022-07-07  9:33     ` Henning Schild
2022-07-08  6:35 ` Schmidl, Tobias [this message]
2022-07-08  6:46   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24d0a5bc8d7a8545bf9465a3bd54b0fce8942d01.camel@siemens.com \
    --to=tobiasschmidl@siemens.com \
    --cc=felix.moessbauer@siemens.com \
    --cc=florian.bezdeka@siemens.com \
    --cc=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=jan.kiszka@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox