pbuilder 在针对 arm64 时出现 “exec format error” 错误。

huangapple go评论67阅读模式
英文:

pbuilder fails with "exec format error" when targeting arm64

问题

我想自定义一个 Debian 二进制包,用于 Ruby,以设置配置标志以启用某些功能。我想在仅支持 amd64 架构的免费 GitHub Actions 运行器内构建此二进制包,并希望还支持 arm64 架构,这意味着需要进行交叉编译。

我正在使用 Ubuntu 22.04(以获取最新工具)作为我的构建环境,目标是 focal、20.04,主要是为了保留对 OpenSSL 1.1 的访问。

我正在使用 Kubernetes 创建一个可重现的打包环境,以下是我的 Pod 定义(请注意,如果有需要尝试使用 qemu 的内容,我已启用特权模式):

apiVersion: v1
kind: Pod
metadata:
  name: ruby-ubuntu-build
  namespace: default
spec:
  containers:
  - args:
    - sleep
    - infinity
    image: ubuntu:22.04
    imagePullPolicy: Always
    name: ruby-debian-build
    resources:
        requests:
            memory: 2048Mi
        limits:
            memory: 2048Mi
    securityContext:
      privileged: true
  preemptionPolicy: PreemptLowerPriority
  priority: 1000
  restartPolicy: Always

当我进入这个环境时,我安装了所有我的工具:

apt-get update
apt-get install -y git-buildpackage vim git build-essential ruby devscripts qemubuilder qemu-user-static

总结一下我的环境:

# uname -a
Linux ruby-ubuntu-build 5.4.149-73.259.amzn2.x86_64 #1 SMP Mon Sep 27 12:48:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"

以及我的失败的 pbuilder chroot 环境创建:

# pbuilder create --distribution focal --architecture arm64 --mirror http://ports.ubuntu.com/ubuntu-ports/        
W: /root/.pbuilderrc does not exist
W: cgroups are not available on the host, not using them.
I: Distribution is focal.
I: Current time: Sat Feb 18 02:56:31 GMT 2023
I: pbuilder-time-stamp: 1676688991
I: Building the build environment
I: running debootstrap
/usr/sbin/debootstrap
I: Retrieving InRelease 
I: Checking Release signature
I: Valid Release signature (key id F6ECB3762474EDA9D21B7022871920D1991BC93C)
I: Retrieving Packages 
I: Validating Packages 
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://ports.ubuntu.com/ubuntu-ports...
I: Validating adduser 3.118ubuntu2
// 此处省略一部分内容
W: Failure trying to run: chroot "/var/cache/pbuilder/build/29550" /bin/true
W: See /var/cache/pbuilder/build/29550/debootstrap/debootstrap.log for details
E: debootstrap failed
E: Tail of debootstrap.log:
2023-02-18 02:56:31 URL:http://ports.ubuntu.com/ubuntu-ports/dists/focal/InRelease [264892/264892] -> "/var/cache/pbuilder/build/29550/var/lib/apt/lists/partial/ports.ubuntu.com_ubuntu-ports_dists_focal_InRelease" [1]
gpgv: Signature made Thu Apr 23 17:34:17 2020 GMT
gpgv: using RSA key 3B4FE6ACC0B21F32
gpgv: Good signature from "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>"
gpgv: Signature made Thu Apr 23 17:34:17 2020 GMT
gpgv: using RSA key 871920D1991BC93C
gpgv: Good signature from "Ubuntu Archive Automatic Signing Key (2018) <ftpmaster@ubuntu.com>"
2023-02-18 02:56:32 URL:http://ports.ubuntu.com/ubuntu-ports/dists/focal/main/binary-arm64/by-hash/SHA256/e014b241021d8c0cf16cb94f44f4cafb7746507769baf36b77845d3ae22e2c1b [940188/940188] -> "/var/cache/pbuilder/build/29550/var/lib/apt/lists/partial/ports.ubuntu.com_ubuntu-ports_dists_focal_main_binary-arm64_Packages.xz" [1]
chroot: failed to run command '/bin/true': Exec format error
E: End of debootstrap.log
W: Aborting with an error

为什么在文件系统创建过程中 chroot 环境尝试运行 /bin/true?如果这是在构建时出现问题,我可以更好地理解。

英文:

I want to customize a debian binary package for ruby to set config flags enabling certain features. I want to build this binary package inside of the free github actions runners which are only amd64 and I want to also support the arm64 architecture, which means cross compiling.

I am using Ubuntu 22.04 (to get the latest tools) as my build environment, targeting focal, 20.04, mostly to keep access to openssl 1.1.

I am spinning up a reproducible packaging environment with Kubernetes and this is my pod definition (note I have enabled privileged mode if anything wanted to try and use qemu):

apiVersion: v1
kind: Pod
metadata:
  name: ruby-ubuntu-build
  namespace: default
spec:
  containers:
  - args:
    - sleep
    - infinity
    image: ubuntu:22.04
    imagePullPolicy: Always
    name: ruby-debian-build
    resources:
        requests:
            memory: 2048Mi
        limits:
            memory: 2048Mi
    securityContext:
      privileged: true
  preemptionPolicy: PreemptLowerPriority
  priority: 1000
  restartPolicy: Always

When I get in to that environment I install all my tools:

apt-get update
apt-get install -y git-buildpackage vim git build-essential ruby devscripts qemubuilder qemu-user-static

To recap my environment:

# uname -a
Linux ruby-ubuntu-build 5.4.149-73.259.amzn2.x86_64 #1 SMP Mon Sep 27 12:48:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/os-release 
PRETTY_NAME=&quot;Ubuntu 22.04.1 LTS&quot;
NAME=&quot;Ubuntu&quot;
VERSION_ID=&quot;22.04&quot;
VERSION=&quot;22.04.1 LTS (Jammy Jellyfish)&quot;

And my failing pbuilder chroot environment creation:

# pbuilder create --distribution focal --architecture arm64 --mirror http://ports.ubuntu.com/ubuntu-ports/        
W: /root/.pbuilderrc does not exist
W: cgroups are not available on the host, not using them.
I: Distribution is focal.
I: Current time: Sat Feb 18 02:56:31 GMT 2023
I: pbuilder-time-stamp: 1676688991
I: Building the build environment
I: running debootstrap
/usr/sbin/debootstrap
I: Retrieving InRelease 
I: Checking Release signature
I: Valid Release signature (key id F6ECB3762474EDA9D21B7022871920D1991BC93C)
I: Retrieving Packages 
I: Validating Packages 
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://ports.ubuntu.com/ubuntu-ports...
I: Validating adduser 3.118ubuntu2
/// SNIP for brevity
W: Failure trying to run: chroot &quot;/var/cache/pbuilder/build/29550&quot; /bin/true
W: See /var/cache/pbuilder/build/29550/debootstrap/debootstrap.log for details
E: debootstrap failed
E: Tail of debootstrap.log:
2023-02-18 02:56:31 URL:http://ports.ubuntu.com/ubuntu-ports/dists/focal/InRelease [264892/264892] -&gt; &quot;/var/cache/pbuilder/build/29550/var/lib/apt/lists/partial/ports.ubuntu.com_ubuntu-ports_dists_focal_InRelease&quot; [1]
gpgv: Signature made Thu Apr 23 17:34:17 2020 GMT
gpgv:                using RSA key 3B4FE6ACC0B21F32
gpgv: Good signature from &quot;Ubuntu Archive Automatic Signing Key (2012) &lt;ftpmaster@ubuntu.com&gt;&quot;
gpgv: Signature made Thu Apr 23 17:34:17 2020 GMT
gpgv:                using RSA key 871920D1991BC93C
gpgv: Good signature from &quot;Ubuntu Archive Automatic Signing Key (2018) &lt;ftpmaster@ubuntu.com&gt;&quot;
2023-02-18 02:56:32 URL:http://ports.ubuntu.com/ubuntu-ports/dists/focal/main/binary-arm64/by-hash/SHA256/e014b241021d8c0cf16cb94f44f4cafb7746507769baf36b77845d3ae22e2c1b [940188/940188] -&gt; &quot;/var/cache/pbuilder/build/29550/var/lib/apt/lists/partial/ports.ubuntu.com_ubuntu-ports_dists_focal_main_binary-arm64_Packages.xz&quot; [1]
chroot: failed to run command &#39;/bin/true&#39;: Exec format error
E: End of debootstrap.log
W: Aborting with an error

why is the chroot environment trying to run /bin/true during filesystem creation? I would understand more if this was an issue at build time.

答案1

得分: 1

看起来我遇到了binfmt不自动调用qemu的问题。首先,我了解了binfmts,查看了已设置的内容,然后启用了正确的架构。

# update-binfmts --display | grep "aarch64 (" -A 9
qemu-aarch64 (disabled):
     package = qemu-user-static
        type = magic
      offset = 0
       magic = \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00
        mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
 interpreter = /usr/libexec/qemu-binfmt/aarch64-binfmt-P
    detector =

然后启用它:

update-binfmts --enable qemu-aarch64

我创建了Debian文件系统:

# debootstrap --arch=arm64 --foreign --variant=buildd --verbose --include=fakeroot,build-essential --components=main --resolve-deps --no-merged-usr focal /tmp/focal-arm-sbuild http://ports.ubuntu.com/ubuntu-ports

现在我可以chroot:

# 这是常规的shell,amd64架构
root@ruby-ubuntu-build:/# uname -a
Linux ruby-ubuntu-build 5.4.149-73.259.amzn2.x86_64 #1 SMP Mon Sep 27 12:48:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root@ruby-ubuntu-build:/# chroot /tmp/focal-arm-sbuild
# uname -a
Linux ruby-ubuntu-build 5.4.149-73.259.amzn2.x86_64 #1 SMP Mon Sep 27 12:48:12 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux
英文:

Looks like I had issues with binfmt not automatically invoking qemu. First I learned about binfmts, checking what was setup and then enabling the right architecture.

# update-binfmts --display | grep &quot;aarch64 (&quot; -A 9
qemu-aarch64 (disabled):
     package = qemu-user-static
        type = magic
      offset = 0
       magic = \x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00
        mask = \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
 interpreter = /usr/libexec/qemu-binfmt/aarch64-binfmt-P
    detector = 

and then enabled it:

update-binfmts --enable qemu-aarch64

I create the debian filesystem:

# debootstrap --arch=arm64 --foreign --variant=buildd --verbose --include=fakeroot,build-essential --components=main --resolve-deps --no-merged-usr focal /tmp/focal-arm-sbuild http://ports.ubuntu.com/ubuntu-ports

I can now chroot:

# this is the regular shell, amd64 arch
root@ruby-ubuntu-build:/# uname -a
Linux ruby-ubuntu-build 5.4.149-73.259.amzn2.x86_64 #1 SMP Mon Sep 27 12:48:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
root@ruby-ubuntu-build:/# chroot /tmp/focal-arm-sbuild
# uname -a
Linux ruby-ubuntu-build 5.4.149-73.259.amzn2.x86_64 #1 SMP Mon Sep 27 12:48:12 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

huangapple
  • 本文由 发表于 2023年2月18日 11:00:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定