Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing aarch64 image build capabilities #475

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ RUN zypper addrepo https://download.opensuse.org/repositories/isv:SUSE:Edge:Edge
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
# 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; \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much space does this package take up? If it's trivial, it may make sense to go ahead and install the aarch64 emulator in the x86 image as well to make working on cross complications easier in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we already do in the downstream builds.

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; \
zypper clean -a; \
fi

COPY --from=0 /src/eib /bin/eib

ENTRYPOINT ["/bin/eib"]
2 changes: 1 addition & 1 deletion pkg/build/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
Expand Down
13 changes: 12 additions & 1 deletion pkg/build/templates/modify-raw-image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the variable that’s set to the arch in the image definition file and then template it in as it allows us to remove this if check and just rely on a single variable which is a little bit safer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for doing this too - we should be able to simplify the script and move everything to Go code.

if ! test -f /dev/kvm; then
export LIBGUESTFS_BACKEND_SETTINGS=force_tcg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally believe that this should be the default behavior. Getting KVM to work in a container (in my experience) has been very error prone and while investigating the x86 EIB builds, I found that it resorts to “tcg” anyway so my opinion is that we just make use force_tcg as the default and avoid KVM.

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
Expand All @@ -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 }}
Expand Down
5 changes: 5 additions & 0 deletions pkg/rpm/resolver/templates/prepare-tarball.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
4 changes: 2 additions & 2 deletions pkg/rpm/resolver/templates/rpm-resolution.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down Expand Up @@ -51,4 +51,4 @@ zypper \
--allow-vendor-change \
-n {{.PKGList}} {{.LocalRPMList}}

touch {{.CacheDir}}/zypper-success
touch {{.CacheDir}}/zypper-success