2021年1月25日星期一

Run arm rootfs with QEMU user

Extract or mount your rootfs to a dir. For example: ./rootfs

Install qemu-user-binfmt.

This package will tell kernel run arm ELF with qemu-user.

sudo apt install qemu-user-binfmt

To see what are installed:

ls  /proc/sys/fs/binfmt_misc/

cat /proc/sys/fs/binfmt_misc/qemu-arm

Now, we can find that the interpreter of arm ELF is changed to /usr/bin/qemu-arm-static.

The interpreter could be /usr/bin/qemu-arm depending your installation order of QEMU packages. 

When we call chroot, kernel will use the interpreter to run ELFs. So we need put qemu-arm-static into the chrooted "root".

If your interpreter is /usr/bin/qemu-arm-static:

cp `which qemu-arm-static` ./rootfs/usr/bin/

If your interpreter is /usr/bin/qemu-arm:

cp `which qemu-arm-static` ./rootfs/usr/bin/qemu-arm

 OK, we can chroot now.

chroot ./rootfs/ /bin/ash

Enjoy!