Skip to content

Commit

Permalink
Add info how to fix failed chroot
Browse files Browse the repository at this point in the history
  • Loading branch information
zer011b committed Apr 14, 2024
1 parent 82c0016 commit 196f508
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Docs/CrossBuild.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,33 @@ Another way is to create rootfs with all required libs from scratch: https://wik

# Troubleshooting

## `chroot failed: no such file or directory`

Debootstrap might fail with smth like `chroot failed: no such file or directory` during rootfs generation when it needs to continue setup in rootfs.
Or same can happen during manual chroot `sudo chroot ./rootfs/<arch> /bin/bash`, which also fails with same error as debootstrap even though `/bin/bash` is present in rootfs.

To fix this first check that `qemu-<arch>-static` is copied from `/usr/bin/` on host to `/usr/bin` in rootfs. If it's not copied, do that manually.

If this doesn't solve the problem, this means that binfmt was misconfigured for some reason. To verify this try `sudo chroot ./rootfs/<arch> /usr/bin/qemu-<arch>-static /bin/bash`, and if it works, the problem is indeed with binfmt.

1. First check that binfmt is enabled with `cat /proc/sys/fs/binfmt_misc/status`.
2. Then check that config for required arch is present with `cat /proc/sys/fs/binfmt_misc/qemu-<arch>` or `update-binfmts --display`, and that this arch is enabled.
3. Even if both are present and seem correct, there migt be misconfiguration (i.e. binfmt arch config is outdated). To update config follow next steps (example for RISC-V from https://wiki.debian.org/RISC-V#Manual_qemu-user_installation):

```sh
$ cat >/tmp/qemu-riscv64 <<EOF
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\xf3\x00
mask \xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff
interpreter /usr/bin/qemu-riscv64-static
EOF
$ sudo update-binfmts --import /tmp/qemu-riscv64
```

Now chroot should work.

## Non-standard system paths

For systems with non-standard paths (like `/lib64/`) `-L<path>` option might not be enough to find libararies, since `-L` specifies search dirs only for explicitly specified libs (i.e. through `-l<libname>` in command line).
Expand Down

0 comments on commit 196f508

Please sign in to comment.