public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Cc: Nishanth Menon <nm@ti.com>
Subject: [PATCH v2 09/11] expand-on-first-boot: Preserve MBR on expansion of GPT disks
Date: Sun, 14 Jan 2024 14:39:32 +0100	[thread overview]
Message-ID: <7dfba7df31dc420bab90708cf81f56c0c3114563.1705239574.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1705239574.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

In order to keep potential hybrid partition setups intact, preserve the
legacy MBR when a GPT disk is being expanded. This is needed because we
rewrite the partitioning via sfdisk which overwrites the MBR. In the
hypbrid setup, the legacy MBR plays no role regarding the expanded
partition, thus can be simply left untouched.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 .../files/expand-last-partition.sh                     | 10 ++++++++++
 1 file changed, 10 insertions(+)

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 7d658864..e6dbd62e 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
@@ -38,6 +38,11 @@ if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then
 	exit 0
 fi
 
+IS_GPT="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | grep -q "label: gpt" && echo 1)"
+if [ "$IS_GPT" = "1" ]; then
+	dd if="${BOOT_DEV}" of=/dev/shm/__mbr__.bak count=1
+fi
+
 LAST_PART="$(sfdisk -d "${BOOT_DEV}" 2>/dev/null | tail -1 | cut -d ' ' -f 1)"
 
 # Transform the partition table as follows:
@@ -54,6 +59,11 @@ sfdisk -d "${BOOT_DEV}" 2>/dev/null | \
 	sed 's|^\('"${LAST_PART}"' .*, \)size=[^,]*, |\1|' | \
 	sfdisk --force "${BOOT_DEV}"
 
+if [ "$IS_GPT" = "1" ]; then
+	dd if=/dev/shm/__mbr__.bak of="${BOOT_DEV}"
+	rm /dev/shm/__mbr__.bak
+fi
+
 # Inform the kernel about the partitioning change
 partx -u "${LAST_PART}"
 
-- 
2.35.3


  parent reply	other threads:[~2024-01-14 13:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-14 13:39 [PATCH v2 00/11] Add support for BeaglePlay Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 01/11] meta-isar: linux-mainline: Update to 6.6.11 Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 02/11] optee-os: Switch default binary to tee-raw.bin Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 03/11] u-boot-custom: Allow to set BL31 and TEE from recipes Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 04/11] u-boot-custom: Allow to define different installation binaries Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 05/11] beagleplay: Add TF-A recipe Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 06/11] beagleplay: Add OP-TEE recipe Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 07/11] beagleplay: Add U-Boot recipe Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 08/11] wic: Add hybrid-boot bootloader source plugin Jan Kiszka
2024-01-14 13:39 ` Jan Kiszka [this message]
2024-01-14 13:39 ` [PATCH v2 10/11] Add support for the BeaglePlay board Jan Kiszka
2024-01-14 13:39 ` [PATCH v2 11/11] ci: Add beagleplay to full CI test Jan Kiszka
2024-03-20 15:17 ` [PATCH v2 00/11] Add support for BeaglePlay Uladzimir Bely

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=7dfba7df31dc420bab90708cf81f56c0c3114563.1705239574.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=isar-users@googlegroups.com \
    --cc=nm@ti.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