From: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
To: devel@spectrum-os.org
Cc: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
Subject: [PATCH] scripts/make-gpt.sh: make GPT offset configurable
Date: Wed, 28 Sep 2022 17:02:39 +0300 [thread overview]
Message-ID: <20220928140239.2380361-1-ivan.nikolaenko@unikie.com> (raw)
These changes can be used in an external configuration layer as
follows:
overlays = [
(self: super:
{
gptOffset = 9437184;
})
];
Signed-off-by: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
---
This patch is not a solution but just a proposal about how things can be done.
There is at least one another way of doing this (having our own make-gpt.sh script),
but I thought that editing of the current one is better way.
Also I don't know should we also consider other images and rootfs be fixed this way.
img/live/Makefile | 3 ++-
img/live/default.nix | 1 +
scripts/make-gpt.sh | 22 ++++++++++++++++++++--
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/img/live/Makefile b/img/live/Makefile
index 9815c88..5a29156 100644
--- a/img/live/Makefile
+++ b/img/live/Makefile
@@ -19,7 +19,8 @@ build/live.img: $(SCRIPTS)/format-uuid.sh $(SCRIPTS)/make-gpt.sh build/boot.fat
build/boot.fat:c12a7328-f81f-11d2-ba4b-00a0c93ec93b \
build/rootfs.verity.superblock:2c7357ed-ebd2-46d9-aec1-23d437ec2bf5:$$($(SCRIPTS)/format-uuid.sh "$$(dd if=build/rootfs.verity.roothash bs=32 skip=1 count=1 status=none)") \
$(ROOT_FS):4f68bce3-e8cd-4db1-96e7-fbcaf984b709:$$($(SCRIPTS)/format-uuid.sh "$$(head -c 32 build/rootfs.verity.roothash)") \
- $(EXT_FS):9293e1ff-cee4-4658-88be-898ec863944f
+ $(EXT_FS):9293e1ff-cee4-4658-88be-898ec863944f \
+ --gptoffset=$(GPT_OFFSET)
mv $@.tmp $@
build/spectrum.conf: build/rootfs.verity.roothash
diff --git a/img/live/default.nix b/img/live/default.nix
index 5461384..c529206 100644
--- a/img/live/default.nix
+++ b/img/live/default.nix
@@ -34,6 +34,7 @@ stdenvNoCC.mkDerivation {
KERNEL = "${rootfs.kernel}/${stdenv.hostPlatform.linux-kernel.target}";
ROOT_FS = rootfs;
SYSTEMD_BOOT_EFI = "${systemd}/lib/systemd/boot/efi/systemd-bootx64.efi";
+ GPT_OFFSET=pkgs.gptOffset or null;
buildFlags = [ "build/live.img" ];
makeFlags = [ "SCRIPTS=${scripts}" ];
diff --git a/scripts/make-gpt.sh b/scripts/make-gpt.sh
index 56076d3..e8dd067 100755
--- a/scripts/make-gpt.sh
+++ b/scripts/make-gpt.sh
@@ -41,8 +41,25 @@ shift
nl=$'\n'
table="label: gpt"
-# Keep 1MiB free at the start, and 1MiB free at the end.
-gptBytes=$TWO_MiB
+TEMP=`getopt -o g:: --long gptoffset:: -- "$@"`
+eval set -- "$TEMP"
+
+while true ; do
+ case "$1" in
+ -g|--gptoffset)
+ gptBytes=$2 ; shift 2 ;;
+ --) shift ; break ;;
+ *) break ;;
+ esac
+done
+
+if [ -z "$gptBytes" ]
+then
+ gptBytes=${TWO_MiB}
+fi
+
+FIRST_LBA="$(expr ${gptBytes} / 1024)"
+
for partition; do
sizeMiB="$(sizeMiB "$(partitionPath "$partition")")"
table="$table${nl}size=${sizeMiB}MiB,$(awk -f "$scriptsDir/sfdisk-field.awk" -v partition="$partition")"
@@ -52,6 +69,7 @@ done
rm -f "$out"
truncate -s "$gptBytes" "$out"
sfdisk "$out" <<EOF
+first-lba: ${FIRST_LBA}
$table
EOF
--
2.25.1
next reply other threads:[~2022-09-28 14:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 14:02 Ivan Nikolaenko [this message]
2022-09-29 10:22 ` [PATCH] scripts/make-gpt.sh: make GPT offset configurable Alyssa Ross
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=20220928140239.2380361-1-ivan.nikolaenko@unikie.com \
--to=ivan.nikolaenko@unikie.com \
--cc=devel@spectrum-os.org \
/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.
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).