Skip to content

Instantly share code, notes, and snippets.

@jpadams
Created June 11, 2018 03:02
Show Gist options
  • Save jpadams/8d9f81fd3f641b9c1fcfd111c23b54b7 to your computer and use it in GitHub Desktop.
Save jpadams/8d9f81fd3f641b9c1fcfd111c23b54b7 to your computer and use it in GitHub Desktop.
#!/bin/sh
# by Jakukyo Friel <weakish@gmail.com> under GPL v2.
# heavily modified by Jeremy Adams for simpler chroot on Apline ppc64le under GPL v2.
# chroot users' group
readonly Members=members
# chroot directory (should be owned and writable only by root)
readonly Chroot=/chroot
## Set up chroot environment
setup_chroot() {
# prepare chroot group
groupadd $Members
# build directory tree
mkdir $Chroot
cd $Chroot
mkdir -p dev/pts proc etc etc/apk lib usr/lib var var/log \
home bin usr/bin sbin usr/sbin mnt/iso
# copy files
cp /etc/localtime etc/
cp /etc/nsswitch.conf etc/
cp /etc/resolv.conf etc/
cp /etc/host.conf etc/
cp /etc/hosts etc/
cp /etc/apk/repositories etc/apk/
touch var/log/lastlog
touch var/run/utmp
touch var/log/wtmp
if [ ! -f /etc/resolv.conf ]; then
echo "Creating resolv.conf"
echo "nameserver 8.8.8.8" > etc/resolv.conf
fi
# create devices
mknod dev/urandom c 1 9 && chmod 0666 dev/urandom
mknod dev/ptmx c 5 2 && chmod 0666 dev/ptmx
mknod dev/tty c 5 0 && chmod 0666 dev/tty
# The new environment needs access to terminals (this is necessary for a user to login) and to proc filesystem.
mount -o bind /dev/pts dev/pts/
mount -o bind /proc proc/
cd /tmp
mirror=http://dl-cdn.alpinelinux.org/alpine
apk_version=2.9.1-r2
wget ${mirror}/latest-stable/main/ppc64le/apk-tools-static-${apk_version}.apk
tar -xzf apk-tools-static-*.apk
./sbin/apk.static -X ${mirror}/latest-stable/main -U --allow-untrusted --root ${Chroot} --initdb add alpine-base
cd $Chroot
}
## main function
setup_chroot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment