by tamjan » Wed Apr 27, 2022 10:16 am
I did the qemu-stuff on a Gentoo system, but any compatible system ought work. I'll share my script for you:
$this->bbcode_second_pass_code('', '
#!/bin/sh
# This is rpi4-chroot.sh
set -e
declare -g RPI4__ROOT=""
function enter()
{
local QEMU_STATIC
[[ -f "/usr/bin/qemu-aarch64" ]] && file /usr/bin/qemu-aarch64 | grep -qE 'statically linked' && QEMU_STATIC="/usr/bin/qemu-aarch64"
[[ -n "${QEMU_STATIC}" ]] || { [[ -f "/usr/bin/qemu-aarch64-static" ]] && file /usr/bin/qemu-aarch64-static | grep -qE 'statically linked' && QEMU_STATIC="/usr/bin/qemu-aarch64-static"; }
[[ -n "${QEMU_STATIC}" ]] || return 252
[[ ! -e /proc/sys/fs/binfmt_misc/aarch64 ]] || echo '-1' > /proc/sys/fs/binfmt_misc/aarch64
echo ':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\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:'"${QEMU_STATIC}"':' > /proc/sys/fs/binfmt_misc/register \
&& pushd "${RPI4__ROOT}" && { \
cp -av "${QEMU_STATIC}" ".${QEMU_STATIC}" \
&& { [[ ! -f ./etc/resolv.conf && ! -L ./etc/resolv.conf ]] || mv -v ./etc/resolv.conf ./etc/resolv.conf.original; } \
&& cat /etc/resolv.conf > ./etc/resolv.conf \
&& chmod 00644 ./etc/resolv.conf \
&& mount -v -t proc proc ./proc \
&& mount -v --rbind /sys ./sys \
&& mount -v --rbind /dev ./dev \
&& mkdir -p -m1777 /tmp/.rpi4-chroot \
&& mount -v --rbind /tmp/.rpi4-chroot ./tmp \
&& ` #chroot . /bin/busybox mdev -s` \
&& trap '( sync; umount -l ./tmp; umount -l ./{proc,sys}; umount -l ./dev{/shm,/pts,}; rm -fv '".${QEMU_STATIC}"' ./etc/resolv.conf; { [[ ! -f ./etc/resolv.conf.original && ! -L ./etc/resolv.conf.original ]] || mv -v ./etc/resolv.conf.original ./etc/resolv.conf; }; popd ) || true' EXIT \
&& chroot . /bin/bash --login
sync; umount -l ./tmp; umount -l ./{proc,sys}; umount -l ./dev{/shm,/pts,}; rm -fv ".${QEMU_STATIC}" ./etc/resolv.conf; { [[ ! -f ./etc/resolv.conf.original && ! -L ./etc/resolv.conf.original ]] || mv -v ./etc/resolv.conf.original ./etc/resolv.conf; }; popd
trap - EXIT; }
echo '-1' > /proc/sys/fs/binfmt_misc/aarch64
echo ':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:P' > /proc/sys/fs/binfmt_misc/register
}
if [ "${1}" == "enter" ]; then
[[ -n "${2}" && -d "${2}" ]] && RPI4__ROOT="${2}" || exit 253
enter
else
exit 254
fi
')
The script is run as root. YMMV, of course. You might need to change how the qemu binary is detected.
$this->bbcode_second_pass_code('', 'rpi4-chroot.sh enter /tmp/mnt/rpi4-rootfs')
Assuming that you have mounted the sdcard root and boot partitions to /tmp/mnt/rpi4-rootfs and /tmp/mnt/rpi4-rootfs/boot, respectively - and have unpacked ArchLinuxARM-rpi-aarch64-latest.tar.gz there, of course.