#!/usr/bin/env bash # Generate a minimal filesystem for archlinux and load it into the local # docker as "archlinux" # requires root set -e if [ -z "${ARCHITECTURE}" ]; then # adapt to the flavour of Archlinux32 you need ARCHITECTURE=pentium4 #ARCHITECTURE=i686 #ARCHITECTURE=i486 fi DOCKER=docker #DOCKER=podman hash pacstrap &>/dev/null || { echo "Could not find pacstrap. Run pacman -S arch-install-scripts" exit 1 } hash expect &>/dev/null || { echo "Could not find expect. Run pacman -S expect" exit 1 } export LANG="C.UTF-8" MOUNTPOINT=$(mktemp -d ${TMPDIR:-/var/tmp}/mountpoint-archlinux-XXXXXXXXXX) ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX) chmod 755 $ROOTFS # packages to ignore for space savings PKGIGNORE=( dhcpcd jfsutils linux lvm2 man-db man-pages mdadm nano netctl openresolv pcmciautils reiserfsprogs s-nail usbutils vi xfsprogs ) IFS=',' PKGIGNORE="${PKGIGNORE[*]}" unset IFS arch="$(uname -m)" case "$arch" in armv*) if ! pacman -Q archlinuxarm-keyring >/dev/null 2>&1; then echo "Could not find archlinuxarm-keyring. Please, install it" exit 1 fi PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX) version="$(echo $arch | cut -c 5)" sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}" PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo' PACMAN_EXTRA_PKGS='archlinuxarm-keyring' EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1) ARCH_KEYRING=archlinuxarm DOCKER_IMAGE_NAME="armv${version}h/archlinux" ;; *) if ! pacman -Q archlinux32-keyring >/dev/null 2>&1; then echo "Could not find archlinux32-keyring. Please, install it" exit 1 fi PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX) sed "s/Architecture.*/Architecture = ${ARCHITECTURE}/" './mkimage-arch-pacman.conf' > "${PACMAN_CONF}" echo 'Server = http://pkgcache.eckner.net/arch/$arch/$repo' > mirrorlist32 sed -i "s|/etc/pacman.d/mirrorlist|mirrorlist32|g" "${PACMAN_CONF}" PACMAN_MIRRORLIST='Server = http://pkgcache.eckner.net/arch/$arch/$repo' PACMAN_EXTRA_PKGS='archlinux32-keyring' EXPECT_TIMEOUT=1800 ARCH_KEYRING=archlinux32 DOCKER_IMAGE_NAME=archlinux32-${ARCHITECTURE} ;; esac export PACMAN_MIRRORLIST expect < $MOUNTPOINT/etc/locale.gen arch-chroot $MOUNTPOINT locale-gen sed -i "s/Architecture.*/Architecture = ${ARCHITECTURE}/" "$MOUNTPOINT/etc/pacman.conf" arch-chroot $MOUNTPOINT /bin/sh -c 'echo $PACMAN_MIRRORLIST > /etc/pacman.d/mirrorlist' # udev doesn't work in containers, rebuild /dev DEV=$MOUNTPOINT/dev rm -rf $DEV mkdir -p $DEV mknod -m 666 $DEV/null c 1 3 mknod -m 666 $DEV/zero c 1 5 mknod -m 666 $DEV/random c 1 8 mknod -m 666 $DEV/urandom c 1 9 mkdir -m 755 $DEV/pts mkdir -m 1777 $DEV/shm mknod -m 666 $DEV/tty c 5 0 mknod -m 600 $DEV/console c 5 1 mknod -m 666 $DEV/tty0 c 4 0 mknod -m 666 $DEV/full c 1 7 mknod -m 600 $DEV/initctl p mknod -m 666 $DEV/ptmx c 5 2 ln -sf /proc/self/fd $DEV/fd umount $MOUNTPOINT tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | $DOCKER import - $DOCKER_IMAGE_NAME $DOCKER run --rm -t $DOCKER_IMAGE_NAME echo Success. rmdir $MOUNTPOINT rm -rf --one-file-system $ROOTFS rm $PACMAN_CONF rm mirrorlist32