You are not logged in.

#1 2022-12-14 13:29:03

greatergood
Member
Registered: 2022-12-14
Posts: 5

Cross-architectural Chroot

Hello! First time poster.

I'm trying to perform a cross architectural chroot as described in this blog post:

https://gitbook.seguranca-informatica.p … c-approach

Basically, I parse the firmware (using binwalk) then decompress the squashfs filesystem. Then I copy over qemu-arm static and chroot in:

cd squashfs-root
sudo chroot . qemu-arm-static bin/sh
ls
bin/sh: ls: not found

The chroot works, but the bins on the new file system cannot be discovered... besides 'pwd' for some reason.

If I hit the tab key twice for auto-complete, I can also see all of the available commands I would expect.

I've checked my path variable and everything looks good. I can also successfully run the binaries if I pass them to qemu-arm-static directly:

./qemu-arm-static /bin/ls

Here's my path:

export PATH='/bin:/usr/bin'

I'm also using kitty/zsh if that makes a difference. But I've also tried with Konsole/bash. Appreciate any help!

Last edited by greatergood (2022-12-14 13:30:08)

Offline

#2 2022-12-14 13:36:03

frostschutz
Member
Registered: 2013-11-15
Posts: 1,647

Re: Cross-architectural Chroot

are the binaries present, with executable bits set? does 'set' work and does it show that the PATH is indeed set? does /bin/ls or /usr/bin/ls work?

Offline

#3 2022-12-14 13:40:10

greatergood
Member
Registered: 2022-12-14
Posts: 5

Re: Cross-architectural Chroot

frostschutz wrote:

are the binaries present, with executable bits set? does 'set' work and does it show that the PATH is indeed set? does /bin/ls or /usr/bin/ls work?

Yes, the binaries are present and marked executable. They are mostly sym links to busybox. Busybox is present.

'set' works surprisingly, and shows that the PATH is correct.

Neither /bin/ls nor /usr/bin/ls work, even though I can see they are present.

Offline

#4 2022-12-14 13:54:15

frostschutz
Member
Registered: 2013-11-15
Posts: 1,647

Re: Cross-architectural Chroot

does it show up in /proc/sys/fs/binfmt_misc/? if not then I guess the binfmt_misc step is somehow missing or fails for you, and you have to manually specify qemu-arm-static every time

note that even in a chroot, it's still quite dangerous to run random stuff with root permissions. qemu might not protect you from that unless you run a full VM

Offline

#5 2022-12-14 14:01:55

greatergood
Member
Registered: 2022-12-14
Posts: 5

Re: Cross-architectural Chroot

frostschutz wrote:

does it show up in /proc/sys/fs/binfmt_misc/? if not then I guess the binfmt_misc step is somehow missing or fails for you, and you have to manually specify qemu-arm-static every time

note that even in a chroot, it's still quite dangerous to run random stuff with root permissions. qemu might not protect you from that unless you run a full VM

This arch install is running in a VM since it's for doing goofy stuff like this, appreciate the warning though smile

Here's what's in /proc/sys/fs/binfmt_misc (outside of the chroot):

ls /proc/sys/fs/binfmt_misc
CLR register status
cat /proc/sys/fs/binfmt_misc/CLR
enabled
interpreter /usr/bin/mono
flags: 
offset 0
magic 4d5a
cat /proc/sys/fs/binfmt_misc/status
enabled

Appreciate you helping to debug!

Offline

#6 2022-12-14 14:06:54

frostschutz
Member
Registered: 2013-11-15
Posts: 1,647

Re: Cross-architectural Chroot

Well, I'm not that familiar with qemu user mode or binfmt_misc myself. But I expect it should be registered in there if it was to run automatically.

Debian wiki has a guide for Raspberry Pi https://wiki.debian.org/RaspberryPi/qemu-user-static where they also put the qemu-arm-static binary in the path ( /mnt/usr/bin instead of /mnt ) maybe that could be related?

Otherwise there is some ingredient for binfmt_misc functionality missing. Here are also some binftm configuration steps mentioned: https://unix.stackexchange.com/question … hitechture

Never done it myself but something like that should probably be it then

Offline

#7 2022-12-14 14:26:25

greatergood
Member
Registered: 2022-12-14
Posts: 5

Re: Cross-architectural Chroot

frostschutz wrote:

Well, I'm not that familiar with qemu user mode or binfmt_misc myself. But I expect it should be registered in there if it was to run automatically.

Debian wiki has a guide for Raspberry Pi https://wiki.debian.org/RaspberryPi/qemu-user-static where they also put the qemu-arm-static binary in the path ( /mnt/usr/bin instead of /mnt ) maybe that could be related?

Otherwise there is some ingredient for binfmt_misc functionality missing. Here are also some binftm configuration steps mentioned: https://unix.stackexchange.com/question … hitechture

Never done it myself but something like that should probably be it then

An issue I'm having is a lot of these guides (including the one mentioned in the StackExchange post) talk about using binfmt-support packages and related commands (update-binfmts). This package/commands seem to be deprecated as this functionality is included in systemd now I believe...

I moved the qemu-arm-static to the /x/usr/bin/ directory, where x is my alternate filesystem. I then chrooted using the following command:

 sudo chroot . qemu-arm-static /bin/sh

Still no luck sad

whoami
/bin/sh: whoami: not found

I also found this post: https://archlinuxarm.org/forum/viewtopi … 57&t=12969

which led me to this script: https://github.com/qemu/qemu/blob/maste … mt-conf.sh

which also didn't work out...

Last edited by greatergood (2022-12-14 14:26:48)

Offline

#8 2022-12-14 14:55:01

greatergood
Member
Registered: 2022-12-14
Posts: 5

Re: Cross-architectural Chroot

Just tested on a debian based distro and everything worked properly...

Offline

#9 2023-03-10 22:40:15

conchyliferous
Member
Registered: 2012-08-06
Posts: 21

Re: Cross-architectural Chroot

I came across this problem as well, I think. For me I think the fix was to install

qemu-user-static-binfmt

. It automatically replaced

qemu-user-binfmt

and after that everything worked fine.

I got the clue from https://wiki.archlinux.org/title/QEMU#C … rom_x86_64, but it was not really described there.

Offline

#10 2023-03-10 22:42:39

conchyliferous
Member
Registered: 2012-08-06
Posts: 21

Re: Cross-architectural Chroot

To clarify, static QEMU worked even before, but unexpectedly not inside a chroot, and I think that was the problem described in this thread as well.

Offline

Board footer

Powered by FluxBB