From 3fbd62309878f93e98fcb2d98dfa848dca240779 Mon Sep 17 00:00:00 2001 From: Rhys Oxenham Date: Wed, 12 Jun 2024 12:07:04 +0100 Subject: [PATCH 1/3] Adding aarch64 support --- Dockerfile | 18 ++++++++++++++++-- pkg/build/templates/modify-raw-image.sh.tpl | 13 ++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index dfee46f3..3a414458 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,7 @@ FROM opensuse/leap:15.5 # 4. RPM resolution logic # 5. Embedded artefact registry # 6. Network configuration +# 7. RAW image modification on aarch64 RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:EdgeImageBuilder/SLE-15-SP5/isv:SUSE:Edge:EdgeImageBuilder.repo && \ zypper --gpg-auto-import-keys refresh && \ zypper install -y \ @@ -35,8 +36,21 @@ RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:Edge podman \ createrepo_c \ helm hauler \ - nm-configurator && \ - zypper clean -a + nm-configurator + +# Make adjustments for running guestfish and image modifications on aarch64 +# guestfish looks for very specific locations on the filesystem for UEFI firmware +# and also expects the boot kernel to be a portable executable (PE), not ELF. +RUN if [[ $(uname -m) == "aarch64" ]]; then \ + zypper install -y qemu-uefi-aarch64; \ + mkdir -p /usr/share/edk2/aarch64; \ + cp /usr/share/qemu/aavmf-aarch64-code.bin /usr/share/edk2/aarch64/QEMU_EFI-pflash.raw; \ + cp /usr/share/qemu/aavmf-aarch64-vars.bin /usr/share/edk2/aarch64/vars-template-pflash.raw; \ + mv /boot/vmlinux* /boot/backup-vmlinux; \ +fi + +# Clean up the repos to reduce size +RUN zypper clean -a COPY --from=0 /src/eib /bin/eib diff --git a/pkg/build/templates/modify-raw-image.sh.tpl b/pkg/build/templates/modify-raw-image.sh.tpl index a5fb7c1a..293d6a6a 100644 --- a/pkg/build/templates/modify-raw-image.sh.tpl +++ b/pkg/build/templates/modify-raw-image.sh.tpl @@ -13,6 +13,17 @@ set -euo pipefail # # Guestfish Command Documentation: https://libguestfs.org/guestfish.1.html +# In x86_64, the default root partition is the third partition +ROOT_PART=/dev/sda3 + +# Make the necessarry adaptations for aarch64 +if [[ $(uname -m) == "aarch64" ]]; then + if ! test -f /dev/kvm; then + export LIBGUESTFS_BACKEND_SETTINGS=force_tcg + fi + ROOT_PART=/dev/sda2 +fi + # Test the block size of the base image and adapt to suit either 512/4096 byte images BLOCKSIZE=512 if ! guestfish -i --blocksize=$BLOCKSIZE -a {{.ImagePath}} echo "[INFO] 512 byte sector check successful."; then @@ -26,7 +37,7 @@ fi {{ if ne .DiskSize "" -}} truncate -r {{.ImagePath}} {{.ImagePath}}.expanded truncate -s {{.DiskSize}} {{.ImagePath}}.expanded -virt-resize --expand /dev/sda3 {{.ImagePath}} {{.ImagePath}}.expanded +virt-resize --expand $ROOT_PART {{.ImagePath}} {{.ImagePath}}.expanded cp {{.ImagePath}}.expanded {{.ImagePath}} rm -f {{.ImagePath}}.expanded {{ end }} From d0bec6f410e37f09b70249324837491e7303d88a Mon Sep 17 00:00:00 2001 From: Rhys Oxenham Date: Wed, 12 Jun 2024 12:20:36 +0100 Subject: [PATCH 2/3] fixing tests --- pkg/build/raw_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/build/raw_test.go b/pkg/build/raw_test.go index a40648be..e54b29e6 100644 --- a/pkg/build/raw_test.go +++ b/pkg/build/raw_test.go @@ -78,7 +78,7 @@ func TestWriteModifyScript(t *testing.T) { "btrfs filesystem label / INSTALL", "sed -i '/ignition.platform/ s/$/ alpha beta /' /tmp/grub.cfg", "truncate -s 64G", - "virt-resize --expand /dev/sda3", + "virt-resize --expand $ROOT_PART", }, expectedMissing: []string{}, }, From c60b36b77750cbc1fb25332373e4985ce57ba0e0 Mon Sep 17 00:00:00 2001 From: Rhys Oxenham Date: Thu, 13 Jun 2024 15:03:23 +0100 Subject: [PATCH 3/3] Fixing rpm resolution stuff and Dockerfile changes --- Dockerfile | 8 +++----- pkg/rpm/resolver/templates/prepare-tarball.sh.tpl | 5 +++++ pkg/rpm/resolver/templates/rpm-resolution.sh.tpl | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a414458..fe5f8b57 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,6 @@ FROM opensuse/leap:15.5 # 4. RPM resolution logic # 5. Embedded artefact registry # 6. Network configuration -# 7. RAW image modification on aarch64 RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:EdgeImageBuilder/SLE-15-SP5/isv:SUSE:Edge:EdgeImageBuilder.repo && \ zypper --gpg-auto-import-keys refresh && \ zypper install -y \ @@ -36,7 +35,8 @@ RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:Edge podman \ createrepo_c \ helm hauler \ - nm-configurator + nm-configurator && \ + zypper clean -a # Make adjustments for running guestfish and image modifications on aarch64 # guestfish looks for very specific locations on the filesystem for UEFI firmware @@ -47,11 +47,9 @@ RUN if [[ $(uname -m) == "aarch64" ]]; then \ cp /usr/share/qemu/aavmf-aarch64-code.bin /usr/share/edk2/aarch64/QEMU_EFI-pflash.raw; \ cp /usr/share/qemu/aavmf-aarch64-vars.bin /usr/share/edk2/aarch64/vars-template-pflash.raw; \ mv /boot/vmlinux* /boot/backup-vmlinux; \ + zypper clean -a; \ fi -# Clean up the repos to reduce size -RUN zypper clean -a - COPY --from=0 /src/eib /bin/eib ENTRYPOINT ["/bin/eib"] diff --git a/pkg/rpm/resolver/templates/prepare-tarball.sh.tpl b/pkg/rpm/resolver/templates/prepare-tarball.sh.tpl index acf97d5c..bd3b3315 100644 --- a/pkg/rpm/resolver/templates/prepare-tarball.sh.tpl +++ b/pkg/rpm/resolver/templates/prepare-tarball.sh.tpl @@ -10,6 +10,11 @@ set -euo pipefail WORK_DIR={{.WorkDir}} IMG_PATH={{.ImgPath}} +# Make the necessarry adaptations for aarch64 +if [[ $(uname -m) == "aarch64" ]]; then + export LIBGUESTFS_BACKEND_SETTINGS=force_tcg +fi + {{ if eq .ImgType "iso" -}} xorriso -osirrox on -indev $IMG_PATH extract / $WORK_DIR/iso-root/ diff --git a/pkg/rpm/resolver/templates/rpm-resolution.sh.tpl b/pkg/rpm/resolver/templates/rpm-resolution.sh.tpl index 99bcb210..a646a74e 100644 --- a/pkg/rpm/resolver/templates/rpm-resolution.sh.tpl +++ b/pkg/rpm/resolver/templates/rpm-resolution.sh.tpl @@ -12,7 +12,7 @@ set -euo pipefail {{ if ne .RegCode "" }} suseconnect -r {{ .RegCode }} -SLE_SP=$(cat /etc/rpm/macros.sle | awk '/sle/ {print $2};' | cut -c4) && suseconnect -p PackageHub/15.$SLE_SP/x86_64 +SLE_SP=$(cat /etc/rpm/macros.sle | awk '/sle/ {print $2};' | cut -c4) && suseconnect -p PackageHub/15.$SLE_SP/$(uname -m) zypper ref trap "suseconnect -d" EXIT {{ end -}} @@ -51,4 +51,4 @@ zypper \ --allow-vendor-change \ -n {{.PKGList}} {{.LocalRPMList}} -touch {{.CacheDir}}/zypper-success \ No newline at end of file +touch {{.CacheDir}}/zypper-success