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

Fix invalid file (bad magic number) Exec format error on Linux #50

Closed
metaist opened this issue Aug 16, 2024 · 7 comments
Closed

Fix invalid file (bad magic number) Exec format error on Linux #50

metaist opened this issue Aug 16, 2024 · 7 comments

Comments

@metaist
Copy link

metaist commented Aug 16, 2024

I'm having trouble running datasette (or any of the releases) on Linux:

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.4 LTS
Release:	22.04
Codename:	jammy

$ wget https://github.com/ahgamut/superconfigure/releases/download/z0.0.51/datasette.zip
$ chmod +x datasette.zip
$ mv datasette.zip datasette
$ ./datasette 
invalid file (bad magic number): Exec format error
@ahgamut
Copy link
Owner

ahgamut commented Aug 16, 2024

You can try changing binfmt_misc: https://github.com/jart/cosmopolitan?tab=readme-ov-file#linux

@metaist
Copy link
Author

metaist commented Aug 16, 2024

Thanks for getting back to me.

$ sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf
$ sudo chmod +x /usr/bin/ape
$ sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sh: 1: echo: echo: I/O error
$ sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
sh: 1: echo: echo: I/O error

Ok, so maybe the problem is that root can't write to /proc/sys/fs/binfmt_misc. I'll see if I can get that to work.

@metaist
Copy link
Author

metaist commented Aug 16, 2024

I tried looking at how other people handled similar issues:
multiarch/qemu-user-static#38 (comment)

But then after reading the actual binfmt_misc docs I see that I actually created the APE and APE-jart files in /proc/sys/fs/binfmt_misc (it was just when I tried recreating them that I got the I/O error).

Still doesn't work.

$ ./datasette 
invalid file (bad magic number): Exec format error

$ /usr/bin/ape ./datasette
ape error: ./datasette: didn't embed ELF magic

@ahgamut
Copy link
Owner

ahgamut commented Aug 16, 2024

Okay, I'll cut a new release in a bit and we can try again. Are you running this inside a Docker image?

@metaist
Copy link
Author

metaist commented Aug 16, 2024

Thanks. I'm running this directly on my machine.

@ahgamut
Copy link
Owner

ahgamut commented Aug 17, 2024

I think you can get it to work by:

wget https://github.com/ahgamut/superconfigure/releases/download/z0.0.51/datasette.zip
unzip datasette.zip
chmod +x bin/datasette
./bin/datasette 

@metaist
Copy link
Author

metaist commented Aug 18, 2024

Thank you; confirmed that works. I didn't realize that the APE was inside the first level of zip file.

@metaist metaist closed this as completed Aug 18, 2024
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