* [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions
@ 2020-06-15 10:10 Harald Seiler
2020-06-15 10:27 ` Jan Kiszka
2020-11-26 16:02 ` Anton Mikanovich
0 siblings, 2 replies; 4+ messages in thread
From: Harald Seiler @ 2020-06-15 10:10 UTC (permalink / raw)
To: isar-users; +Cc: Harald Seiler, Jan Kiszka
Extended partitions cannot be resized like primary partitions because
both the last logical partition and the EBR primary partition containing
it need to be expanded.
To do this, add a second SED directive for removing the parition size of
the EBR partition. This part is detected by having either type `f` (Win
95 Ext') or `5` (Extended).
Signed-off-by: Harald Seiler <hws@denx.de>
---
Notes:
Changes in v2:
- Keep a type `f` EBR as type `f`.
- Update comment to better explain what is done.
I've built myself a little test-suite to see how this script
behaves when given different layouts. It seems to work just fine
now for the following cases:
- Expanding last partition of a GPT.
- Expanding last partition of an MBR without extended partitions.
- Expanding last (logical) partition of an MBR when the last
primary partition is the EBR.
Having the EBR somewhere in the middle is *not* supported. The
script will fail with an error message, without accidentally
ruining the layout. I think such a case is too rare to be worth
supporting.
.../files/expand-last-partition.sh | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
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 08c69db30529..7175dfd38b7e 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
@@ -17,12 +17,20 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
exit 1
fi
-LAST_PART="$(sfdisk -d ${BOOT_DEV} 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
+LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
-# Remove all hints to the current medium (last-lba) and last partition size,
-# then ask sfdisk to recreate the partitioning
-sfdisk -d "${BOOT_DEV}" 2>/dev/null | grep -v last-lba | \
- sed 's|\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
+# Transform the partition table as follows:
+#
+# - Remove any 'last-lba' header so sfdisk uses the entire available space.
+# - If this partition table is MBR and an extended partition container (EBR)
+# exists, we assume this needs to be expanded as well; remove its size
+# field so sfdisk expands it.
+# - For the previously fetched last partition, also remove the size field so
+# sfdisk expands it.
+sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
+ grep -v last-lba | \
+ sed 's|^\(.*, \)size=[^,]*, \(type=[f5]\)$|\1\2|' | \
+ sed 's|^\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
sfdisk --force "${BOOT_DEV}"
# Inform the kernel about the partitioning change
--
2.25.4
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions
2020-06-15 10:10 [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions Harald Seiler
@ 2020-06-15 10:27 ` Jan Kiszka
2020-10-13 10:18 ` Jan Kiszka
2020-11-26 16:02 ` Anton Mikanovich
1 sibling, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2020-06-15 10:27 UTC (permalink / raw)
To: Harald Seiler, isar-users
On 15.06.20 12:10, Harald Seiler wrote:
> Extended partitions cannot be resized like primary partitions because
> both the last logical partition and the EBR primary partition containing
> it need to be expanded.
>
> To do this, add a second SED directive for removing the parition size of
> the EBR partition. This part is detected by having either type `f` (Win
> 95 Ext') or `5` (Extended).
>
> Signed-off-by: Harald Seiler <hws@denx.de>
> ---
>
> Notes:
> Changes in v2:
> - Keep a type `f` EBR as type `f`.
> - Update comment to better explain what is done.
>
> I've built myself a little test-suite to see how this script
> behaves when given different layouts. It seems to work just fine
> now for the following cases:
>
> - Expanding last partition of a GPT.
> - Expanding last partition of an MBR without extended partitions.
> - Expanding last (logical) partition of an MBR when the last
> primary partition is the EBR.
>
> Having the EBR somewhere in the middle is *not* supported. The
> script will fail with an error message, without accidentally
> ruining the layout. I think such a case is too rare to be worth
> supporting.
Ack.
>
> .../files/expand-last-partition.sh | 18 +++++++++++++-----
> 1 file changed, 13 insertions(+), 5 deletions(-)
>
> 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 08c69db30529..7175dfd38b7e 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
> @@ -17,12 +17,20 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
> exit 1
> fi
>
> -LAST_PART="$(sfdisk -d ${BOOT_DEV} 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
> +LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
>
> -# Remove all hints to the current medium (last-lba) and last partition size,
> -# then ask sfdisk to recreate the partitioning
> -sfdisk -d "${BOOT_DEV}" 2>/dev/null | grep -v last-lba | \
> - sed 's|\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
> +# Transform the partition table as follows:
> +#
> +# - Remove any 'last-lba' header so sfdisk uses the entire available space.
> +# - If this partition table is MBR and an extended partition container (EBR)
> +# exists, we assume this needs to be expanded as well; remove its size
> +# field so sfdisk expands it.
> +# - For the previously fetched last partition, also remove the size field so
> +# sfdisk expands it.
Very nice.
> +sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
> + grep -v last-lba | \
> + sed 's|^\(.*, \)size=[^,]*, \(type=[f5]\)$|\1\2|' | \
> + sed 's|^\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
> sfdisk --force "${BOOT_DEV}"
>
> # Inform the kernel about the partitioning change
>
LGTM.
Jan
--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions
2020-06-15 10:27 ` Jan Kiszka
@ 2020-10-13 10:18 ` Jan Kiszka
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2020-10-13 10:18 UTC (permalink / raw)
To: Baurzhan Ismagulov; +Cc: Harald Seiler, isar-users
On 15.06.20 12:27, [ext] Jan Kiszka wrote:
> On 15.06.20 12:10, Harald Seiler wrote:
>> Extended partitions cannot be resized like primary partitions because
>> both the last logical partition and the EBR primary partition containing
>> it need to be expanded.
>>
>> To do this, add a second SED directive for removing the parition size of
>> the EBR partition. This part is detected by having either type `f` (Win
>> 95 Ext') or `5` (Extended).
>>
>> Signed-off-by: Harald Seiler <hws@denx.de>
>> ---
>>
>> Notes:
>> Changes in v2:
>> - Keep a type `f` EBR as type `f`.
>> - Update comment to better explain what is done.
>>
>> I've built myself a little test-suite to see how this script
>> behaves when given different layouts. It seems to work just fine
>> now for the following cases:
>>
>> - Expanding last partition of a GPT.
>> - Expanding last partition of an MBR without extended partitions.
>> - Expanding last (logical) partition of an MBR when the last
>> primary partition is the EBR.
>>
>> Having the EBR somewhere in the middle is *not* supported. The
>> script will fail with an error message, without accidentally
>> ruining the layout. I think such a case is too rare to be worth
>> supporting.
>
> Ack.
>
>>
>> .../files/expand-last-partition.sh | 18 +++++++++++++-----
>> 1 file changed, 13 insertions(+), 5 deletions(-)
>>
>> 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 08c69db30529..7175dfd38b7e 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
>> @@ -17,12 +17,20 @@ if [ "${ROOT_DEV}" = "${BOOT_DEV}" ]; then
>> exit 1
>> fi
>>
>> -LAST_PART="$(sfdisk -d ${BOOT_DEV} 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
>> +LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
>>
>> -# Remove all hints to the current medium (last-lba) and last partition size,
>> -# then ask sfdisk to recreate the partitioning
>> -sfdisk -d "${BOOT_DEV}" 2>/dev/null | grep -v last-lba | \
>> - sed 's|\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
>> +# Transform the partition table as follows:
>> +#
>> +# - Remove any 'last-lba' header so sfdisk uses the entire available space.
>> +# - If this partition table is MBR and an extended partition container (EBR)
>> +# exists, we assume this needs to be expanded as well; remove its size
>> +# field so sfdisk expands it.
>> +# - For the previously fetched last partition, also remove the size field so
>> +# sfdisk expands it.
>
> Very nice.
>
>> +sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
>> + grep -v last-lba | \
>> + sed 's|^\(.*, \)size=[^,]*, \(type=[f5]\)$|\1\2|' | \
>> + sed 's|^\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
>> sfdisk --force "${BOOT_DEV}"
>>
>> # Inform the kernel about the partitioning change
>>
>
> LGTM.
>
> Jan
>
Baurzhan, this is overdue.
Jan
--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions
2020-06-15 10:10 [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions Harald Seiler
2020-06-15 10:27 ` Jan Kiszka
@ 2020-11-26 16:02 ` Anton Mikanovich
1 sibling, 0 replies; 4+ messages in thread
From: Anton Mikanovich @ 2020-11-26 16:02 UTC (permalink / raw)
To: isar-users
15.06.2020 13:10, Harald Seiler wrote:
> Extended partitions cannot be resized like primary partitions because
> both the last logical partition and the EBR primary partition containing
> it need to be expanded.
>
> To do this, add a second SED directive for removing the parition size of
> the EBR partition. This part is detected by having either type `f` (Win
> 95 Ext') or `5` (Extended).
>
> Signed-off-by: Harald Seiler <hws@denx.de>
Applied to next, thanks.
--
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-11-26 16:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 10:10 [PATCH v2] expand-on-first-boot: Allow expanding extended MBR partitions Harald Seiler
2020-06-15 10:27 ` Jan Kiszka
2020-10-13 10:18 ` Jan Kiszka
2020-11-26 16:02 ` Anton Mikanovich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox