Skip to main content
Topic: How chroot in foreign architecture (ARMtix etc.) (Read 192 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How chroot in foreign architecture (ARMtix etc.)

1 - Install necessary packages:
Code: [Select]
pacman -S artools-base qemu-user qemu-user-static qemu-user-static-binfmt

2 - Enable binfmt service if necessary and restart it, dinit example:
Code: [Select]
dinitctl restart binfmt

3 - Extract the archive somewhere e.g. some ARMtix image https://armtixlinux.org/images/.

4 - You need to bind mount the chroot to itself and then chroot:
Code: [Select]
mount -o bind <path> <path> 
artix-chroot <path>

You can use this script that will handle all and you can safely call it more than once:
Code: [Select]
#!/bin/sh

if ! mountpoint -q "$HOME"/path/armtix; then
mount -o bind "$HOME"/path/armtix "$HOME"/path/armtix
fi

artix-chroot "$HOME"/path/armtix

Troubleshooting

Code: [Select]
chroot: failed to run command '/bin/bash': Exec format error
The error above means that something is wrong with binfmt.

Check if binfmt_misc is mounted:
Code: [Select]
ls /proc/sys/fs/binfmt_misc
register status

If it is empty you have to mount it (that should be done already automatically):
Code: [Select]
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc

Then you have to write the content of /usr/lib/binfmt.d/qemu-aarch64-static.conf (for aarch64 architecture) in /proc/sys/fs/binfmt_misc/register:
Code: [Select]
echo ':qemu-aarch64:M::\x7fELF\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/bin/qemu-aarch64-static:FP' >  /proc/sys/fs/binfmt_misc/register

Useful links:
https://www.kernel.org/doc/html/v5.9/admin-guide/binfmt-misc.html
https://wiki.archlinux.org/title/Binfmt_misc_for_Java
https://forum.artixlinux.org/index.php/topic,6550.0.html