solo-io / packer-plugin-arm-image

Packer plugin for ARM images
Apache License 2.0
425 stars 104 forks source link

arm-image: chroot: failed to run command '/bin/sh': Exec format error #139

Closed jseparovic closed 2 years ago

jseparovic commented 2 years ago

I'm getting the following error when trying to build the arm64 pi image using gitlab-ci with docker in docker:

$ docker run --rm --privileged -v /dev:/dev -v /images:/images -v `pwd`:/build:ro -v `pwd`/packer_cache:/build/packer_cache -v `pwd`/output-arm-image:/build/output-arm-image ghcr.io/solo-io/packer-plugin-arm-image build pi.json
running /bin/packer
arm-image: output will be in this color.
==> arm-image: Image type: raspberrypi
==> arm-image: Retrieving Image
==> arm-image: Trying /images/2022-04-04-raspios-bullseye-arm64-lite.img
==> arm-image: Trying /images/2022-04-04-raspios-bullseye-arm64-lite.img?checksum=sha256%3Ab3ac783cecc9fc5445e164eca4d27b87a7cb461ade4618943624ed9984db0088
==> arm-image: /images/2022-04-04-raspios-bullseye-arm64-lite.img?checksum=sha256%3Ab3ac783cecc9fc5445e164eca4d27b87a7cb461ade4618943624ed9984db0088 => /images/2022-04-04-raspios-bullseye-arm64-lite.img
==> arm-image: Copying source image.
==> arm-image: Growing partition to 4096 M (4294967296 bytes)
    arm-image: mapping output-arm-image/image
==> arm-image: losetup --show -f -P output-arm-image/image
==> arm-image: partitions: [/dev/loop4p1 /dev/loop4p2]
==> arm-image: partitions: [/dev/loop4p1 /dev/loop4p2]
    arm-image: Mounting: /dev/loop4p2
    arm-image: Mounting: /dev/loop4p1
==> arm-image: Mounting additional paths within the chroot...
    arm-image: Mounting: /proc
    arm-image: Mounting: /sys
    arm-image: Mounting: /dev
    arm-image: Mounting: /dev/pts
    arm-image: Mounting: /proc/sys/fs/binfmt_misc
==> arm-image: Installing qemu-user-static (/usr/bin/qemu-arm-static) in the chroot
==> arm-image: Registering /qemu-arm-static with binfmt_misc
==> arm-image: Uploading ./files/ => /
==> arm-image: Provisioning with shell script: /tmp/packer-shell4203057374
==> arm-image: chroot: failed to run command '/bin/sh': Exec format error

I don't see this issue when building the 32bit version.

Any ideas what to check?

jseparovic commented 2 years ago

I just tried to run it without the gitlab runner, directly on the VM and get the same issue. It's a Centos 7.9 VM.

I also tried running it directly on a Centos 8 host, and it works fine.

Is there a limitation on a KVM Virtual Machine?

jseparovic commented 2 years ago

Thinking more about this now, it doesn't make much sense to run the gitlab-ci runner inside a VM, when it's a docker container anyway. I'll just run it directly on the Hypervisor.