From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id CB7B516965; Fri, 28 Nov 2025 13:24:05 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 334B11695D; Fri, 28 Nov 2025 13:24:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_MISSING,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=4.0.1 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) by atuin.qyliss.net (Postfix) with ESMTPS id 1C3891695A for ; Fri, 28 Nov 2025 13:24:01 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id A6A38EC0490; Fri, 28 Nov 2025 08:23:58 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Fri, 28 Nov 2025 08:23:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm3; t=1764336238; x=1764422638; bh=qxwJJqIZ7eVNPpYjrrNzF sWVytiDOBCYw3jU00ahDRA=; b=MRh7e+FYnIAXXatnkESQU1PGo9Y0MtHCBwbAs 57iiowHDiy+TdDxIJpkNE5dB4EwIfRtMgkmv2AplNmr5VFd4X9IaCmBhjIFVQ2iW sRMumwCmm2VgW91hK2nbl+B6JW8vChTdJlpolKEIYjqa/s9l6t1whEOXfePMEpND 8ujNbfjNAhWItgmRoumFW8/c7MAJfmKjpS8LdCHhF2ia/B02Cz3ouQknOVwf5IvC OcxUCNe/hR0SsEgiQ36MUAb7lMdeUv6APaa/JMTndP3eXrwJXAL4isK5BeK2dMwt XvymOdg2aCYLovbdfWKX7iBGj9A18EXZwIJkL+6+5DQ/Ka3EA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1764336238; x=1764422638; bh=qxwJJqIZ7eVNPpYjrrNzFsWVytiDOBCYw3j U00ahDRA=; b=vY7HmmedNH1Gj3kaj2JcqAjH3HV4V4CWKI7IKrCbgy1wDLdpiAE kbapdZcUP/5y2EdJw6gubML8L8gLGuyp/KV7R9tCLj339DFQpHp6lkbTf8R/1iYK u4FPLQQVkos74EdocrPRY7TDnYW/cdeKnIKAkdZYVPmgKTvXRH0D5N9qSfKyhFju cQB+BmH8C00KMXDPsQA/9/E/LDktMNrlDXhReJbZx5vZoS4Y1NItJ9gdhvx6dL19 NiWiI8Dz3sxavj6abtPGRZDzwPJihs4K/7ftx9i3wJYYeDVBh8Ww8ON9a0oWCmd7 LoiEvLK1rkK09jWgjkW29OB4hdu42xq0KMw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvgeelleelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomheptehlhihsshgrucft ohhsshcuoehhihesrghlhihsshgrrdhisheqnecuggftrfgrthhtvghrnhepkedugfekfe efvdeihedtheevjeetueejhffhuddtueffhfeikeevteffheefgeevnecuffhomhgrihhn pehsphgvtghtrhhumhdqohhsrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhephhhisegrlhihshhsrgdrihhspdhnsggprhgtphhtthho pedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeguvghmihhosggvnhhouhhrse hgmhgrihhlrdgtohhmpdhrtghpthhtohepuggvvhgvlhesshhpvggtthhruhhmqdhoshdr ohhrgh X-ME-Proxy: Feedback-ID: i12284293:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 28 Nov 2025 08:23:57 -0500 (EST) Received: by fw12.qyliss.net (Postfix, from userid 1000) id 89DEE2BE564E; Fri, 28 Nov 2025 14:23:36 +0100 (CET) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH v2] scripts/make-gpt.sh: allow setting partition size Date: Fri, 28 Nov 2025 14:22:28 +0100 Message-ID: <20251128132227.243596-2-hi@alyssa.is> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: J6W2ZCEBZGDZEBZST34CDWEWB3YNU7V3 X-Message-ID-Hash: J6W2ZCEBZGDZEBZST34CDWEWB3YNU7V3 X-MailFrom: hi@alyssa.is X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; header-match-devel.spectrum-os.org-3; header-match-devel.spectrum-os.org-4; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Demi Marie Obenour X-Mailman-Version: 3.3.9 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We want non-minimally-sized partitions to leave space for updates. All such partitions will also be labelled, so we can just add another optional field at the end. Since we don't parse partition specifications in sh, we can't keep a running total any more, so instead we just go through the table at the end and add up all the sizes, taking advantage of our knowledge that the size will always be the last thing in each line in our tables. Signed-off-by: Alyssa Ross Message-ID: <20251127174054.2056835-2-hi@alyssa.is> --- v2: fix conflicts after applying Demi's optimization, and avoid awk to sum partition sizes, taking inspiration from the same. v1: https://spectrum-os.org/lists/archives/spectrum-devel/20251127174054.2056835-2-hi@alyssa.is/ scripts/make-gpt.sh | 30 ++++++++++++++++++------------ scripts/sfdisk-field.awk | 22 +++++++++++++++++----- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh index 3cae441..cb19868 100755 --- a/scripts/make-gpt.sh +++ b/scripts/make-gpt.sh @@ -1,10 +1,10 @@ #!/bin/sh -eu # -# SPDX-FileCopyrightText: 2021-2023 Alyssa Ross +# SPDX-FileCopyrightText: 2021-2023, 2025 Alyssa Ross # SPDX-FileCopyrightText: 2022 Unikie # SPDX-License-Identifier: EUPL-1.2+ # -# usage: make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID[:PARTLABEL]]... +# usage: make-gpt.sh GPT_PATH PATH:PARTTYPE[:PARTUUID[:PARTLABEL[:PARTMiB]]]... ONE_MiB=1048576 @@ -33,21 +33,27 @@ scriptsDir="$(dirname "$0")" out="$1" shift -nl=' -' -table="label: gpt" +table=$(for partition; do + awk -f "$scriptsDir/sfdisk-field.awk" \ + -v partition="$partition" \ + -v size="$(sizeMiB "${partition%%:*}")" +done) # Keep 1MiB free at the start, and 1MiB free at the end. -gptBytes=$((ONE_MiB * 2)) -for partition; do - sizeMiB="$(sizeMiB "${partition%%:*}")" - table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")" - gptBytes="$((gptBytes + sizeMiB * ONE_MiB))" -done +gptMiB=2 +while read -r partition; do + # Here we rely on sfdisk-field.awk always putting size last. + : $((gptMiB += ${partition##*=})) +done < +# SPDX-FileCopyrightText: 2022, 2024-2025 Alyssa Ross BEGIN { types["root.aarch64"] = "b921b045-1df0-41c3-af44-4c6f280d3fae" @@ -9,12 +9,11 @@ BEGIN { types["verity.aarch64"] = "df3300ce-d69f-4c92-978c-9bfb0f38d820" types["verity.x86_64"] = "2c7357ed-ebd2-46d9-aec1-23d437ec2bf5" - # Field #1 is the partition path, which make-gpt.sh will turn into - # the size field. Since it's handled elsewhere, we skip that - # first field. + # Field #1 is the partition path, which is read by make-gpt.sh + # but not relevant for running sfdisk, so skip it. skip=1 - split("type uuid name", keys) + split("type uuid name size", keys) split(partition, fields, ":") arch = ENVIRON["ARCH"] @@ -31,8 +30,21 @@ BEGIN { if (keys[n - skip] == "type") { if (uuid = types[fields[n] "." arch]) fields[n] = uuid + } else if (keys[n - skip] == "size") { + if (fields[n] < size) { + printf "%s MiB partition content is too big for %s MiB partition\n", + size, fields[n] > "/dev/stderr" + exit 1 + } + + size = fields[n] + continue # Handled at the end. } printf "%s=%s,", keys[n - skip], fields[n] } + + # Always output a size field, either supplied in input or + # default value of the size variable. + printf "size=%s\n", size } base-commit: 1970f432152730ec19bf97a8db4613a591ee00be -- 2.51.0