* [PATCH v2] scripts/make-gpt.sh: allow setting partition size
@ 2025-11-28 13:22 Alyssa Ross
2025-11-28 20:57 ` Demi Marie Obenour
0 siblings, 1 reply; 8+ messages in thread
From: Alyssa Ross @ 2025-11-28 13:22 UTC (permalink / raw)
To: devel; +Cc: Demi Marie Obenour
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 <hi@alyssa.is>
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 <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2021-2023, 2025 Alyssa Ross <hi@alyssa.is>
# 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 <<EOF
+$table
+EOF
rm -f "$out"
-truncate -s "$gptBytes" "$out"
+truncate -s "${gptMiB}M" "$out"
+
sfdisk --no-reread --no-tell-kernel "$out" <<EOF
+label: gpt
+sector-size: $ONE_MiB
$table
EOF
diff --git a/scripts/sfdisk-field.awk b/scripts/sfdisk-field.awk
index e13c86d..78b438e 100644
--- a/scripts/sfdisk-field.awk
+++ b/scripts/sfdisk-field.awk
@@ -1,7 +1,7 @@
#!/usr/bin/awk -f
#
# SPDX-License-Identifier: EUPL-1.2+
-# SPDX-FileCopyrightText: 2022, 2024 Alyssa Ross <hi@alyssa.is>
+# SPDX-FileCopyrightText: 2022, 2024-2025 Alyssa Ross <hi@alyssa.is>
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
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 13:22 [PATCH v2] scripts/make-gpt.sh: allow setting partition size Alyssa Ross
@ 2025-11-28 20:57 ` Demi Marie Obenour
2025-11-28 21:14 ` Alyssa Ross
0 siblings, 1 reply; 8+ messages in thread
From: Demi Marie Obenour @ 2025-11-28 20:57 UTC (permalink / raw)
To: Alyssa Ross, devel
[-- Attachment #1.1.1: Type: text/plain, Size: 4667 bytes --]
On 11/28/25 08:22, 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.
>
> 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 <hi@alyssa.is>
> 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 <hi@alyssa.is>
> +# SPDX-FileCopyrightText: 2021-2023, 2025 Alyssa Ross <hi@alyssa.is>
> # 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)
$(sizeMiB) should be moved into a separate command. Shellcheck can
catch this if you enable SC2312.
> # 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 <<EOF
> +$table
> +EOF
Nit: should ${partition##*=} be in double quotes?
> rm -f "$out"
> -truncate -s "$gptBytes" "$out"
> +truncate -s "${gptMiB}M" "$out"
> +
> sfdisk --no-reread --no-tell-kernel "$out" <<EOF
> +label: gpt
> +sector-size: $ONE_MiB
> $table
> EOF
>
> diff --git a/scripts/sfdisk-field.awk b/scripts/sfdisk-field.awk
> index e13c86d..78b438e 100644
> --- a/scripts/sfdisk-field.awk
> +++ b/scripts/sfdisk-field.awk
> @@ -1,7 +1,7 @@
> #!/usr/bin/awk -f
> #
> # SPDX-License-Identifier: EUPL-1.2+
> -# SPDX-FileCopyrightText: 2022, 2024 Alyssa Ross <hi@alyssa.is>
> +# SPDX-FileCopyrightText: 2022, 2024-2025 Alyssa Ross <hi@alyssa.is>
>
> 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
--
Sincerely,
Demi Marie Obenour (she/her/hers)
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 20:57 ` Demi Marie Obenour
@ 2025-11-28 21:14 ` Alyssa Ross
2025-11-28 21:15 ` Demi Marie Obenour
0 siblings, 1 reply; 8+ messages in thread
From: Alyssa Ross @ 2025-11-28 21:14 UTC (permalink / raw)
To: Demi Marie Obenour; +Cc: devel
[-- Attachment #1: Type: text/plain, Size: 3079 bytes --]
Demi Marie Obenour <demiobenour@gmail.com> writes:
> On 11/28/25 08:22, 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.
>>
>> 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 <hi@alyssa.is>
>> 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 <hi@alyssa.is>
>> +# SPDX-FileCopyrightText: 2021-2023, 2025 Alyssa Ross <hi@alyssa.is>
>> # 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)
>
> $(sizeMiB) should be moved into a separate command. Shellcheck can
> catch this if you enable SC2312.
Good catch, thanks. Feel free to suggest other optional shellcheck
things we should enable. (Although I've just noticed
release/checks/shellcheck.nix doesn't seem to be reading the
.shellcheckrc file properly so don't use that for testing.)
>> # 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 <<EOF
>> +$table
>> +EOF
>
> Nit: should ${partition##*=} be in double quotes?
I tried changing it, but it is apparently an "arithmetic syntax error"
to use double quotes here.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 21:14 ` Alyssa Ross
@ 2025-11-28 21:15 ` Demi Marie Obenour
2025-11-28 21:26 ` Alyssa Ross
0 siblings, 1 reply; 8+ messages in thread
From: Demi Marie Obenour @ 2025-11-28 21:15 UTC (permalink / raw)
To: Alyssa Ross; +Cc: devel
[-- Attachment #1.1.1: Type: text/plain, Size: 3310 bytes --]
On 11/28/25 16:14, Alyssa Ross wrote:
> Demi Marie Obenour <demiobenour@gmail.com> writes:
>
>> On 11/28/25 08:22, 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.
>>>
>>> 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 <hi@alyssa.is>
>>> 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 <hi@alyssa.is>
>>> +# SPDX-FileCopyrightText: 2021-2023, 2025 Alyssa Ross <hi@alyssa.is>
>>> # 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)
>>
>> $(sizeMiB) should be moved into a separate command. Shellcheck can
>> catch this if you enable SC2312.
>
> Good catch, thanks. Feel free to suggest other optional shellcheck
> things we should enable. (Although I've just noticed
> release/checks/shellcheck.nix doesn't seem to be reading the
> .shellcheckrc file properly so don't use that for testing.)
I'll look later.
>>> # 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 <<EOF
>>> +$table
>>> +EOF
>>
>> Nit: should ${partition##*=} be in double quotes?
>
> I tried changing it, but it is apparently an "arithmetic syntax error"
> to use double quotes here.
I'd use a separate variable then.
--
Sincerely,
Demi Marie Obenour (she/her/hers)
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 21:15 ` Demi Marie Obenour
@ 2025-11-28 21:26 ` Alyssa Ross
2025-11-28 21:31 ` Demi Marie Obenour
0 siblings, 1 reply; 8+ messages in thread
From: Alyssa Ross @ 2025-11-28 21:26 UTC (permalink / raw)
To: Demi Marie Obenour; +Cc: devel
[-- Attachment #1: Type: text/plain, Size: 3831 bytes --]
Demi Marie Obenour <demiobenour@gmail.com> writes:
> On 11/28/25 16:14, Alyssa Ross wrote:
>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>
>>> On 11/28/25 08:22, 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.
>>>>
>>>> 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 <hi@alyssa.is>
>>>> 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 <hi@alyssa.is>
>>>> +# SPDX-FileCopyrightText: 2021-2023, 2025 Alyssa Ross <hi@alyssa.is>
>>>> # 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)
>>>
>>> $(sizeMiB) should be moved into a separate command. Shellcheck can
>>> catch this if you enable SC2312.
>>
>> Good catch, thanks. Feel free to suggest other optional shellcheck
>> things we should enable. (Although I've just noticed
>> release/checks/shellcheck.nix doesn't seem to be reading the
>> .shellcheckrc file properly so don't use that for testing.)
>
> I'll look later.
>
>>>> # 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 <<EOF
>>>> +$table
>>>> +EOF
>>>
>>> Nit: should ${partition##*=} be in double quotes?
>>
>> I tried changing it, but it is apparently an "arithmetic syntax error"
>> to use double quotes here.
>
> I'd use a separate variable then.
Doesn't seem to make a difference. As an experiment:
partition="size=2 + 3"
size=${partition##*=}
printf "%s\n" $(($size))
This prints 5 even though a separate variable is used. It doesn't seem
to be possible to get $(( … )) *not* to interpret arithmetic in
variables.
In bash, but not busybox ash as used in Nix builds, it is possible to
use double quotes like you suggested, but $(("$size")) is /still/ 5.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 21:26 ` Alyssa Ross
@ 2025-11-28 21:31 ` Demi Marie Obenour
2025-11-28 21:35 ` Alyssa Ross
0 siblings, 1 reply; 8+ messages in thread
From: Demi Marie Obenour @ 2025-11-28 21:31 UTC (permalink / raw)
To: Alyssa Ross; +Cc: devel
[-- Attachment #1.1.1: Type: text/plain, Size: 2260 bytes --]
On 11/28/25 16:26, Alyssa Ross wrote:
> Demi Marie Obenour <demiobenour@gmail.com> writes:
>
>> On 11/28/25 16:14, Alyssa Ross wrote:
>>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>>
>>>> On 11/28/25 08:22, 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.
>>>>>
>>>>> 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 <hi@alyssa.is>
>>>>> Message-ID: <20251127174054.2056835-2-hi@alyssa.is>
(snip)
>>>>> # 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 <<EOF
>>>>> +$table
>>>>> +EOF
>>>>
>>>> Nit: should ${partition##*=} be in double quotes?
>>>
>>> I tried changing it, but it is apparently an "arithmetic syntax error"
>>> to use double quotes here.
>>
>> I'd use a separate variable then.
>
> Doesn't seem to make a difference. As an experiment:
>
> partition="size=2 + 3"
> size=${partition##*=}
> printf "%s\n" $(($size))
>
> This prints 5 even though a separate variable is used. It doesn't seem
> to be possible to get $(( … )) *not* to interpret arithmetic in
> variables.
>
> In bash, but not busybox ash as used in Nix builds, it is possible to
> use double quotes like you suggested, but $(("$size")) is /still/ 5.
That's actually required by POSIX. What about:
size=${partition##*=}
: $((gptMiB += size))
?
--
Sincerely,
Demi Marie Obenour (she/her/hers)
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 21:31 ` Demi Marie Obenour
@ 2025-11-28 21:35 ` Alyssa Ross
2025-11-28 21:39 ` Demi Marie Obenour
0 siblings, 1 reply; 8+ messages in thread
From: Alyssa Ross @ 2025-11-28 21:35 UTC (permalink / raw)
To: Demi Marie Obenour; +Cc: devel
[-- Attachment #1: Type: text/plain, Size: 2556 bytes --]
On Fri, Nov 28, 2025 at 04:31:21PM -0500, Demi Marie Obenour wrote:
> On 11/28/25 16:26, Alyssa Ross wrote:
> > Demi Marie Obenour <demiobenour@gmail.com> writes:
> >
> >> On 11/28/25 16:14, Alyssa Ross wrote:
> >>> Demi Marie Obenour <demiobenour@gmail.com> writes:
> >>>
> >>>> On 11/28/25 08:22, 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.
> >>>>>
> >>>>> 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 <hi@alyssa.is>
> >>>>> Message-ID: <20251127174054.2056835-2-hi@alyssa.is>
>
> (snip)
>
> >>>>> # 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 <<EOF
> >>>>> +$table
> >>>>> +EOF
> >>>>
> >>>> Nit: should ${partition##*=} be in double quotes?
> >>>
> >>> I tried changing it, but it is apparently an "arithmetic syntax error"
> >>> to use double quotes here.
> >>
> >> I'd use a separate variable then.
> >
> > Doesn't seem to make a difference. As an experiment:
> >
> > partition="size=2 + 3"
> > size=${partition##*=}
> > printf "%s\n" $(($size))
> >
> > This prints 5 even though a separate variable is used. It doesn't seem
> > to be possible to get $(( … )) *not* to interpret arithmetic in
> > variables.
> >
> > In bash, but not busybox ash as used in Nix builds, it is possible to
> > use double quotes like you suggested, but $(("$size")) is /still/ 5.
>
> That's actually required by POSIX. What about:
>
> size=${partition##*=}
> : $((gptMiB += size))
How's that better? Arithmetic will still be expanded inside size —
or do you have some other concern with the parameter expansion inside
the arithmetic expansion?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH v2] scripts/make-gpt.sh: allow setting partition size
2025-11-28 21:35 ` Alyssa Ross
@ 2025-11-28 21:39 ` Demi Marie Obenour
0 siblings, 0 replies; 8+ messages in thread
From: Demi Marie Obenour @ 2025-11-28 21:39 UTC (permalink / raw)
To: Alyssa Ross; +Cc: devel
[-- Attachment #1.1.1: Type: text/plain, Size: 2862 bytes --]
On 11/28/25 16:35, Alyssa Ross wrote:
> On Fri, Nov 28, 2025 at 04:31:21PM -0500, Demi Marie Obenour wrote:
>> On 11/28/25 16:26, Alyssa Ross wrote:
>>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>>
>>>> On 11/28/25 16:14, Alyssa Ross wrote:
>>>>> Demi Marie Obenour <demiobenour@gmail.com> writes:
>>>>>
>>>>>> On 11/28/25 08:22, 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.
>>>>>>>
>>>>>>> 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 <hi@alyssa.is>
>>>>>>> Message-ID: <20251127174054.2056835-2-hi@alyssa.is>
>>
>> (snip)
>>
>>>>>>> # 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 <<EOF
>>>>>>> +$table
>>>>>>> +EOF
>>>>>>
>>>>>> Nit: should ${partition##*=} be in double quotes?
>>>>>
>>>>> I tried changing it, but it is apparently an "arithmetic syntax error"
>>>>> to use double quotes here.
>>>>
>>>> I'd use a separate variable then.
>>>
>>> Doesn't seem to make a difference. As an experiment:
>>>
>>> partition="size=2 + 3"
>>> size=${partition##*=}
>>> printf "%s\n" $(($size))
>>>
>>> This prints 5 even though a separate variable is used. It doesn't seem
>>> to be possible to get $(( … )) *not* to interpret arithmetic in
>>> variables.
>>>
>>> In bash, but not busybox ash as used in Nix builds, it is possible to
>>> use double quotes like you suggested, but $(("$size")) is /still/ 5.
>>
>> That's actually required by POSIX. What about:
>>
>> size=${partition##*=}
>> : $((gptMiB += size))
>
> How's that better? Arithmetic will still be expanded inside size —
> or do you have some other concern with the parameter expansion inside
> the arithmetic expansion?
Nevermind. The only way it would be better is if the input was
explicitly validated, which might not be worthwile. In bash, bad
$size even allows code execution in at least the default mode.
--
Sincerely,
Demi Marie Obenour (she/her/hers)
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 7253 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-11-28 21:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-28 13:22 [PATCH v2] scripts/make-gpt.sh: allow setting partition size Alyssa Ross
2025-11-28 20:57 ` Demi Marie Obenour
2025-11-28 21:14 ` Alyssa Ross
2025-11-28 21:15 ` Demi Marie Obenour
2025-11-28 21:26 ` Alyssa Ross
2025-11-28 21:31 ` Demi Marie Obenour
2025-11-28 21:35 ` Alyssa Ross
2025-11-28 21:39 ` Demi Marie Obenour
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).