Created
July 29, 2021 05:30
-
-
Save lifning/015ddd5f2af19eb98a2c4ec491e2fad7 to your computer and use it in GitHub Desktop.
quickly make a void chroot in a foreign architecture for testing things in a binfmt-misc context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -exo noclobber | |
ARCH="${1:?}" | |
ROOT="/var/chroot/void-$ARCH" | |
REPO=https://alpha.us.repo.voidlinux.org/current | |
if [[ "$ARCH" =~ ^ppc ]] ; then | |
case "$ARCH" in | |
ppc) REPO=https://repo.voidlinux-ppc.org/current/ppc ;; | |
ppc-musl) REPO=https://repo.voidlinux-ppc.org/current/ppc/musl ;; | |
ppc64) REPO=https://repo.voidlinux-ppc.org/current/be ;; | |
ppc64-musl) REPO=https://repo.voidlinux-ppc.org/current/be/musl ;; | |
ppc64le-musl) REPO=https://repo.voidlinux-ppc.org/current/musl ;; | |
ppcle) REPO=https://auto.voidlinux-ppc.org/testing/ppcle ;; | |
ppcle-musl) REPO=https://auto.voidlinux-ppc.org/testing/ppcle-musl ;; | |
*) REPO=https://auto.voidlinux-ppc.org/current ;; | |
esac | |
elif [ "$ARCH" == aarch64 ] ; then | |
REPO=https://alpha.us.repo.voidlinux.org/current/aarch64 | |
fi | |
cat > "$HOME/bin/chroot-void-$ARCH.sh" <<EOF | |
#!/bin/bash | |
if [ "\$EUID" -ne 0 ] ; then | |
exec sudo "\$0" "\$@" | |
fi | |
cd "$ROOT" | |
mount --rbind --make-rprivate /dev dev/ | |
mount -t sysfs sys sys | |
mount -t proc proc proc | |
mount -o bind /tmp tmp/ | |
chroot . | |
umount tmp sys proc dev/pts dev/shm dev | |
EOF | |
chmod +x "$HOME/bin/chroot-void-$ARCH.sh" | |
sudo mkdir -p "$ROOT/usr/bin/" "$ROOT/etc" | |
sudo cp "/usr/bin/qemu-${ARCH/armv7l/arm}-static" "$ROOT/usr/bin/" | |
sudo cp "/etc/resolv.conf" "$ROOT/etc/" | |
sudo env XBPS_ARCH=$ARCH xbps-install -S -y -r "$ROOT" -R "$REPO" base-chroot pam | |
sudo useradd -R "$ROOT" -u "$UID" `whoami` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment