Arch Chroot on Alpine

Arch Chroot on Alpine

From: http://wiki.alpinelinux.org/Installing_ArchLinux_inside_an_Alpine_chroot.


Install bash/wget

zstd is needed too for arch-boostrap.sh

sudo apk add bash wget zstd

wget --no-check-certificate https://raw.github.com/tokland/arch-bootstrap/master/arch-bootstrap.sh

mkdir chroot64
sudo bash arch-bootstrap.sh -a x86_64 chroot64

Use this script, save it as start_chroot.

#!/bin/sh -e
user=`whoami`
if [ "$user" != "root" ]; then
  echo "This script needs root access" >&2
  exit 1
fi
if ! [ -d "$1" ]; then
  echo "Usage: $0 <chroot directory>" >&2
  exit 1
fi
if [ x1 = x`sysctl -ne kernel.grsecurity.chroot_deny_chmod` ]; then
  echo "Warning: can't suid/sgid inside chroot" >&2
fi
if [ x1 = x`sysctl -ne kernel.grsecurity.chroot_deny_chroot` ]; then
  echo "Warning: can't chroot inside chroot" >&2
fi
if [ x1 = x`sysctl -ne kernel.grsecurity.chroot_deny_mknod` ]; then
  echo "Warning: can't mknod inside chroot" >&2
fi
if [ x1 = x`sysctl -ne kernel.grsecurity.chroot_deny_mount` ]; then
  echo "Warning: can't mount inside chroot" >&2
fi
cd "$1"
shift
cp -L /etc/resolv.conf ./etc/ || true
mount -t proc proc ./proc
mount -t sysfs sys ./sys
mount -o bind /dev ./dev
# next line is said to be important for pacman's signature check
mount -o bind /dev/pts ./dev/pts
# # for emacsclient to work
# if [ -d /tmp/emacs1000 ]
# then
#     mkdir -p ./tmp/emacs1000
#     mount -o bind /tmp/emacs1000 ./tmp/emacs1000
# fi

# copy .Xauthority for firefox to work
# cp /home/paul/.Xauthority home/paul/

case $1 in
  -l) shift;;
  -l*) one=${1#-l}; shift; set -- -$one "$@";;
esac
# chroot . /bin/sh -c "su - paul" -l "$@"
chroot . /bin/sh -l "$@"
umount ./dev/pts
# umount ./tmp/emacs1000
umount ./dev ./sys ./proc

pacman-key --init
pacman-key --populate archlinux
pacman -Syyu
pacman -Rs systemd # NOTE: systemd not needed, but can't seem to remove
pacman -S sudo

passwd
useradd -m -g users -G wheel -s /usr/bin/bash paul
passwd paul
export VISUAL=/usr/bin/vim
visudo # uncomment the wheel group