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 C191118D17; Fri, 28 Nov 2025 20:44:57 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 1972218CC8; Fri, 28 Nov 2025 20:44:54 +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 fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) by atuin.qyliss.net (Postfix) with ESMTPS id 0A36218CC7 for ; Fri, 28 Nov 2025 20:44:53 +0000 (UTC) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 8C0627A0736; Fri, 28 Nov 2025 15:44:50 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Fri, 28 Nov 2025 15:44:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1764362690; x=1764449090; bh=cchbIKPq9k iWQezNjIbRU9Kj2Jz/mnBcPzqX4Cg6jCc=; b=Arlc4OkSRrB0NlcDAmzd2hBzjO BdWf0YRFFpvh7z46cabuCIeOW4WAc3i93RRg8aKM8jXr1pS+G7t6PthiZxgptclW zP6dJ3ylaZSzJBN9a/KV2c58jLKTc8yqeaV11hBID26louiVPgnA726QPalcb10o M+d8y6ilxDK1y1sHoafyl6ZTTmAuH+mhQ87k+RyQ7/N4f1yauUByIPulfXu0M7je nkr9qopAR8tjsXqbHX5ovq0vCIZkgoYY27C7bS0h6CcmUGdvMwJTKmudNO1y6yVe KtDJW1k9AZMo2y8Zs1x7Bp9FUSGFC7iQrhmpuYQXFbMlXNNc2RNBLdWcPcDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1764362690; x=1764449090; bh=cchbIKPq9kiWQezNjIbRU9Kj2Jz/mnBcPzq X4Cg6jCc=; b=DBiri70gPHw8Arw6sBnUW0BpT8B4lI+lrIHwB4n2Yf1Q4h7BdDJ nwmg5wuDyQuDYXJf/v4lmPBeDko3tQJc++wuO2o9y0r0pwOQjkiHkR+QOHLTGkW2 akuVHQSITATWxPlCR00GW7p8N3vl+azLfg7BwCSYnp4SvLrsXHwjpVEKSbmMxjut EIEqJwYcUOEK8qxzSsxTShfPFNClUnmDoVvi4q58xj9MCdDhVETaVIKW1oXru9qW yFIz7QNZcCIdN/Pw8eL18q6NMh8cOs0EP5hhoCV93wKpuFMahFalGfekM2P9JEZD OS730qli6WR9h8GmWrYX/iyebzj95wxkcMg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvhedtkedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhephffvufgjfhffkfggtgesghdtreertddtjeenucfhrhhomheptehlhihsshgrucft ohhsshcuoehhihesrghlhihsshgrrdhisheqnecuggftrfgrthhtvghrnhepveehkeetke ffuddthfefffdtledtkeetgedtvdetvdfhleevudeludelfedtgfefnecuffhomhgrihhn pehsphgvtghtrhhumhdqohhsrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomhephhhisegrlhihshhsrgdrihhspdhnsggprhgtphhtthho pedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeguvghmihhosggvnhhouhhrse hgmhgrihhlrdgtohhmpdhrtghpthhtohepuggvvhgvlhesshhpvggtthhruhhmqdhoshdr ohhrgh X-ME-Proxy: Feedback-ID: i12284293:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 28 Nov 2025 15:44:49 -0500 (EST) Received: by fw12.qyliss.net (Postfix, from userid 1000) id BD7002DB2B15; Fri, 28 Nov 2025 21:44:33 +0100 (CET) From: Alyssa Ross To: Demi Marie Obenour , devel@spectrum-os.org Subject: Re: [PATCH] scripts/make-gpt.sh: allow setting partition size In-Reply-To: <09f9e834-9af4-41a7-b171-2641a7d6637f@gmail.com> References: <20251127174054.2056835-2-hi@alyssa.is> <09f9e834-9af4-41a7-b171-2641a7d6637f@gmail.com> Date: Fri, 28 Nov 2025 21:44:31 +0100 Message-ID: <87sedxopjk.fsf@alyssa.is> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Message-ID-Hash: 4BR7WQOWRR5ONAAHONELKMMPJL42TFC5 X-Message-ID-Hash: 4BR7WQOWRR5ONAAHONELKMMPJL42TFC5 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 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: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Demi Marie Obenour writes: > On 11/27/25 12:40, Alyssa Ross wrote: >> 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. >>=20 >> 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. >>=20 >> Signed-off-by: Alyssa Ross >> --- >> This is an alternative to Demi's implementation[1], which required Bash >> features. >>=20 >> [1]: https://spectrum-os.org/lists/archives/spectrum-devel/20251126-upda= tes-v5-3-fd746748febd@gmail.com/ >>=20 >> scripts/make-gpt.sh | 28 +++++++++++++++------------- >> scripts/sfdisk-field.awk | 22 +++++++++++++++++----- >> 2 files changed, 32 insertions(+), 18 deletions(-) >>=20 >> diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh >> index 96f0d2c..07eac50 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[:PARTM= iB]]]... >>=20=20 >> ONE_MiB=3D1048576 >>=20=20 >> @@ -28,7 +28,8 @@ fillPartition() { >> lseek -S 1 "$start" cat "$3" 1<>"$1" >> } >>=20=20 >> -# Prints the partition path from a PATH:PARTTYPE[:PARTUUID[:PARTLABEL]]= string. >> +# Prints the partition path from a >> +# PATH:PARTTYPE[:PARTUUID[:PARTLABEL[:PARTMiB]]] string. >> partitionPath() { >> awk -F: '{print $1}' <> $1 >> @@ -40,21 +41,22 @@ scriptsDir=3D"$(dirname "$0")" >> out=3D"$1" >> shift >>=20=20 >> -nl=3D' >> -' >> -table=3D"label: gpt" >> +table=3D$(for partition; do >> + awk -f "$scriptsDir/sfdisk-field.awk" \ >> + -v partition=3D"$partition" \ >> + -v size=3D"$(sizeMiB "$(partitionPath "$partition")")" >> +done) >>=20=20 >> # Keep 1MiB free at the start, and 1MiB free at the end. >> -gptBytes=3D$((ONE_MiB * 2)) >> -for partition; do >> - sizeMiB=3D"$(sizeMiB "$(partitionPath "$partition")")" >> - table=3D"$table${nl}size=3D${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-= field.awk" -v partition=3D"$partition")" >> - gptBytes=3D"$((gptBytes + sizeMiB * ONE_MiB))" >> -done >> +# Here we rely on sfdisk-field.awk always putting size last >> +gptMiB=3D$(printf "%s\n" "$table" | awk -F=3D '{size +=3D $NF} END {pri= nt size + 2}') > > Needs -o pipefail, though I believe this will be in the next revision > of POSIX if it isn't already. You can avoid that with some awk magic > but the script gets harder to read. It is now POSIX! Will add. >> rm -f "$out" >> -truncate -s "$gptBytes" "$out" >> +truncate -s "${gptMiB}M" "$out" >> + >> sfdisk --no-reread --no-tell-kernel "$out" <> +label: gpt >> +sector-size: $ONE_MiB > > I'm concerned about this line. GPT sector sizes aren't just used > to compute partition sizes. They are part of the on-disk format, > and moving an image from a disk to a different disk with a different > sector size requires fixing on-disk data structures. I wrote a > tool to do this for Qubes OS, but it is also possible to generate > a polyglot GPT that works for both 512-byte and 4096-byte sectors. > I recommend we use this for the installer eventually. > > That said, if the installer boots with this it should not have a problem. sfdisk is explicitly documented to only consider this for computing partition size, as I understand it. The actual sector size used will always be 512, 1024, 2048, or 4096: --sector-size sectorsize Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096. The kernel is aware of the sector size for regul= ar block devices. Use this option only on very old kernels, when working with disk images, or to override the kernel=E2=80=99s de= fault sector size. Since util-linux-2.17, fdisk distinguishes between logical= and physical sector size. This option changes both sector sizes to t= he specified sectorsize. =E2=80=A6 sector-size Specifies the sector size used in the input. sfdisk always internally uses the device sector size provided by the kernel for the block device, or as specified by the user on the command line (see --sector-size). Starting with version 2.39, sfdisk recalcul= ates sizes from the input if the sector-size header and device sector size are different. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQQGoGac7QfI+H5ZtFCZddwkt31pFQUCaSoJsAAKCRCZddwkt31p FWanAP42monf5kh2SZAZGRQObhkDDL49cVcz0Xr/vYAxBP860wD/cLj8DgDI+bUl q3YGVwAWwcg+QEC9y9guFjC0x2o1Bwo= =SRXU -----END PGP SIGNATURE----- --=-=-=--