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

debootstrap not empty during stage 0 #772

Open
knachte opened this issue May 2, 2024 · 18 comments
Open

debootstrap not empty during stage 0 #772

knachte opened this issue May 2, 2024 · 18 comments

Comments

@knachte
Copy link

knachte commented May 2, 2024

I set up a new wsl with ubuntu 24.04 today and started running into problems straight away:

During stage0 i get:

I: Extracting zlib1g...
W: Failure trying to run: chroot "/home/kristof/pi-gen.old/work/raspios/stage0/rootfs" /bin/true
W: See /home/kristof/pi-gen.old/work/raspios/stage0/rootfs/debootstrap/debootstrap.log for details
rmdir: failed to remove '/home/kristof/pi-gen.old/work/raspios/stage0/rootfs/debootstrap': Directory not empty
[12:22:20] bootstrap failed: please check /home/kristof/pi-gen.old/work/raspios/stage0/debootstrap.log

I checked the log mentioned above and at the end it contains:

chroot: failed to run command '/bin/true': Exec format error

I then went back to an older copy i had on another wsl running on 20.04, and that one suddenly started showing the same problem.
I accidently nuked my 22.04 that i was using to build this morning, so can't go and check in that one anymore :(

I found an old issue here that mentioned the same problem from 2019, and checked that the patch in there is present in the current code: #248

Any idea what could be causing this?

@XECDesign
Copy link
Member

The root of the issue is that your WSL environment isn't able to run the binaries of the architecture you're building for. That would normally be because binfmt isn't set up properly. On a normal Ubuntu install, as long as you have qemu-user-static and binfmt-support installed, it should just work.

What do you have in /usr/share/binfmts, /proc/sys/fs/binfmt_misc/ and what is the output of systemctl status binfmt-support?

@knachte
Copy link
Author

knachte commented May 2, 2024

I quickly installed the two packages you suggested and this is the output you requested.

kristof@ATLT-2202-1:~/pi-gen$ ls /usr/share/binfmts/
python3.12

kristof@ATLT-2202-1:~/pi-gen$ ls /proc/sys/fs/binfmt_misc/
WSLInterop  WSLInterop-late  python3.12  register  status

kristof@ATLT-2202-1:~/pi-gen$ sudo systemctl status binfmt-support
● binfmt-support.service - Enable support for additional executable binary formats
     Loaded: loaded (/usr/lib/systemd/system/binfmt-support.service; enabled; preset: enabled)
     Active: active (exited) since Thu 2024-05-02 14:18:56 CEST; 6min ago
       Docs: man:update-binfmts(8)
    Process: 752 ExecStart=/usr/sbin/update-binfmts --enable (code=exited, status=0/SUCCESS)
   Main PID: 752 (code=exited, status=0/SUCCESS)

May 02 14:18:56 ATLT-2202-1 systemd[1]: Starting binfmt-support.service - Enable support for additional executable binary formats...
May 02 14:18:56 ATLT-2202-1 systemd[1]: Finished binfmt-support.service - Enable support for additional executable binary formats.

Still with the same results when doing a build.

@XECDesign
Copy link
Member

Okay, that's not what I'd expect if you have qemu-user-static installed, but I'm on 22.04. Let me check if anything relevant has changed in 24.04...

It may be /usr/lib/binfmt.d/ now. If you see files like qemu-aarch64.conf there, does restarting the binfmt-support service change what you see in /proc/sys/fs/binfmt_misc/?

@knachte
Copy link
Author

knachte commented May 2, 2024

/usr/lib/binfmt.d does indeed contain qemu-aarch64.conf and other architectures.
Content of that file:
:qemu-aarch64:M::\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/libexec/qemu-binfmt/aarch64-binfmt-P:OCPF

I restarted the service, no changes to the content of /proc/sys/fs/binfmt_misc/

@XECDesign
Copy link
Member

If I search for binfmt wsl, there are many issues that come up, but I don't have a 24.04 WSL install handy to check which ones are actually applicable.

@knachte
Copy link
Author

knachte commented May 2, 2024

i'm seeing the same with my 20.04 install, but i'm not 100% certain that i ever built it on that one. I have a working one at home, i'll check that one when i get home later tonight if it's doing the same, but i'm not sure if it's a 20.4 or 22.4.

@XECDesign
Copy link
Member

I use WSL a bit at home, so when I get the chance, I'll poke around a bit as well.

@knachte
Copy link
Author

knachte commented May 2, 2024

i've reinstalled a wsl 22.04 ubuntu and there it seems to work with no problems, so it seems that the problem is related to 24.04.

@XECDesign
Copy link
Member

In my case, systemd doesn't work in WSL by default. Did you do something to enable it?

It looks like the systemd-binfmt service is meant to register everything in 24.04 instead of binfmt-support.

That service is meant to launch /usr/lib/systemd/systemd-binfmt. if I run that manuall, then it seems to work.

@XECDesign
Copy link
Member

XECDesign commented May 2, 2024

After updating wsl, systemd is working, and I've found this:

$ cat /usr/lib/systemd/system/systemd-binfmt.service.d/wsl.conf
# systemd breaks WSL interoperability by rewriting the binfmt interpreters configuration.

[Unit]
ConditionVirtualization=!wsl

So yeah, they intentionally disable it for whatever reason...

Edit: From what I gather, the reason is that they register other binfmt definitions (using wsl-binfmt.service) to make it possible to run .exe files from within wsl, and they don't want anything else overriding it (for example, wine or mono binfmt files, maybe), so they just break everything else instead 👍.

@knachte
Copy link
Author

knachte commented May 2, 2024

So basically, ubuntu 24.04 is a no go for building unless jumping trough a lot of hoops for the time being? I can stay on 22.04 without problem and this might be another good moment to bring up at work that they should let us dualboot linux.

@XECDesign
Copy link
Member

The hoops shouldn't be too major. If you remember to run sudo /usr/lib/systemd/systemd-binfmt, it should work.

However, qemu has been known to be a bit flakey and cause issues in the past, so the best thing to do is to build natively on a pi with enough storage.

@knachte
Copy link
Author

knachte commented May 2, 2024

Ok, i'll give that a try at work tomorrow. Thanks for the help!

@XECDesign
Copy link
Member

No worries. Good luck!

@knachte
Copy link
Author

knachte commented May 2, 2024

just for reference, at home i realised that on ubuntu 22.04 wsl i had not done a build yet on my main machine. I had to enable systemd in /etc/wsl.conf and restart the binfmt-support service which made /proc/sys/fs/binfmt_misc/ fill up, after which it would build. Before that i got the same result as on 24.04. At work the freshly installed 22.04 worked first time, so maybe older versions of 22.04 under wsl did not yet have systemd activated.

@knachte
Copy link
Author

knachte commented May 3, 2024

I just checked at work, the 22.04 and 24.04 that i installed yesterday both had systemd activated in /etc/wsl.conf.
And even more.. the 24.04 that did not work yesterday did the build this morning without any problems, without any changes done to it. I'm guessing that it needed a complete restart of wsl before making everything active.

If you think this might be interesting enough to add to the readme.md i'll play with it a bit more this weekend and send a pr somewhere next week.

@XECDesign
Copy link
Member

I think I'll add a check in build.sh before doing anything to verify that binfmt works as expected. If it doesn't, it should give some useful guidance rather than debootstrap's Exec format error ¯\_(ツ)_/¯

However, if it's not working out of the box, it generally indicates something wrong with the host system. I don't think it would be possible for us to document and track all of the potential issues when running in an unknown environment.

I think we'll say that native builds on a Raspberry Pi will work and are fully supported. But when users start introducing other distros, other kernels, VMs, containers, binfmt and emulators things start getting a bit fragile and those issues should go upstream to whichever component introduces it.

@XECDesign
Copy link
Member

Should be "fixed" in d87f764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants