Last active
August 25, 2023 23:28
-
-
Save emolitor/0567e51c0ce04f4b025fc78d2cf0b4f1 to your computer and use it in GitHub Desktop.
chroot script for testing aarch64
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
# This simple script is setting up a Alpine Linux installation in a chroot. | |
# chroot will be placed in the current working directory. | |
# | |
# Most parts of this script are written down at | |
# http://wiki.alpinelinux.org/wiki/Setting_up_the_build_environment_in_chroot | |
# | |
# Licensed under GPLv2 | |
# | |
# Copyright (c) 2011-2019 Fabian Affolter <fabian at affolter-engineering.ch> | |
MIRROR=http://dl-5.alpinelinux.org/alpine | |
ARCH=aarch64 | |
CHROOT=alpine-chroot | |
VERSION=v3.9 | |
APK_TOOL=apk-tools-static-2.10.3-r1.apk | |
# Root has $UID 0 | |
ROOT_UID=0 | |
if [ "$UID" != "$ROOT_UID" ] | |
then | |
echo "You are not root. Please use su to become root." | |
exit 0 | |
fi | |
if [ -d $CHROOT ] | |
then | |
echo "$CHROOT already exists." | |
exit 0 | |
else | |
mkdir -p $CHROOT | |
fi | |
wget $MIRROR/$VERSION/main/$ARCH/$APK_TOOL | |
tar -xzf $APK_TOOL | |
./sbin/apk.static \ | |
-X $MIRROR/$VERSION/main \ | |
-U \ | |
--allow-untrusted \ | |
--root ././$CHROOT \ | |
--initdb add alpine-base alpine-sdk | |
mkdir -p $CHROOT{/root,/etc/apk,/proc} | |
mount --bind /proc $CHROOT/proc | |
mknod -m 666 $CHROOT/dev/full c 1 7 | |
mknod -m 666 $CHROOT/dev/ptmx c 5 2 | |
mknod -m 644 $CHROOT/dev/random c 1 8 | |
mknod -m 644 $CHROOT/dev/urandom c 1 9 | |
mknod -m 666 $CHROOT/dev/zero c 1 5 | |
mknod -m 666 $CHROOT/dev/tty c 5 0 | |
rm -f $CHROOT/dev/null | |
mknod -m 666 $CHROOT/dev/null c 1 3 | |
chmod 777 /dev/shm | |
cp /etc/resolv.conf $CHROOT/etc/ | |
echo "$MIRROR/$VERSION/main" > $CHROOT/etc/apk/repositories | |
# Cleaning up | |
rm -rf sbin | |
rm -f APK_TOOL | |
echo " " | |
echo "Your Alpine Linux installation in '$CHROOT' is ready now." | |
echo "To start Alpine:" | |
echo "sudo chroot $CHROOT /bin/sh -l" | |
echo " " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment