Skip to content

Instantly share code, notes, and snippets.

@NiklasGollenstede
Created March 29, 2022 23:58
Show Gist options
  • Save NiklasGollenstede/2019ca37c248cf4cb05c761e9709659b to your computer and use it in GitHub Desktop.
Save NiklasGollenstede/2019ca37c248cf4cb05c761e9709659b to your computer and use it in GitHub Desktop.
aarch64 user space on x86_64 Debian/Ubuntu
# These commands create and enter a aarch64 user space on x86_64 Debian/Ubuntu.
# Expects qemu-aarch64-static to be installed and registered for the aarch64 binfmt on the host, see e.g.: https://codepyre.com/2019/12/arming-yourself/
mkdir -p /tmp/chroot ; mount tmpfs -t tmpfs /tmp/chroot # (tmpfs is optional)
debootstrap --arch=arm64 $(lsb_release --short --codename) /tmp/chroot # install aarch4 user space of host's distro
# copy qemu to where it's registered as binfmt in the kernel (and since it is statically linked, copying a single file is sufficient)
mkdir -p /tmp/chroot/$(dirname $(which qemu-aarch64-static))
cp -a {/,/tmp/chroot/}$(which qemu-aarch64-static)
# make it usable
mkdir -p /tmp/chroot/etc/ ; cp -a {/,/tmp/chroot/}/etc/resolv.conf
for dir in dev/ proc/ sys/ ; do mkdir -p /tmp/chroot/$dir ; mountpoint -q /tmp/chroot/$dir || mount --rbind /$dir /tmp/chroot/$dir ; done
chroot /tmp/chroot /bin/bash --login # do (or rather emulate) great things
mount | grep -oP 'on \K/tmp/chroot(/\S+)?(?=\s)' | xargs -r -n1 umount -l # unmount everything (lazy to avoid "busy" issues, and since it's all virtual file systems anyway)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment