github.com/jen20/docker@v1.13.1/contrib/mkimage-arch.sh (about) 1 #!/usr/bin/env bash 2 # Generate a minimal filesystem for archlinux and load it into the local 3 # docker as "archlinux" 4 # requires root 5 set -e 6 7 hash pacstrap &>/dev/null || { 8 echo "Could not find pacstrap. Run pacman -S arch-install-scripts" 9 exit 1 10 } 11 12 hash expect &>/dev/null || { 13 echo "Could not find expect. Run pacman -S expect" 14 exit 1 15 } 16 17 18 export LANG="C.UTF-8" 19 20 ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX) 21 chmod 755 $ROOTFS 22 23 # packages to ignore for space savings 24 PKGIGNORE=( 25 cryptsetup 26 device-mapper 27 dhcpcd 28 iproute2 29 jfsutils 30 linux 31 lvm2 32 man-db 33 man-pages 34 mdadm 35 nano 36 netctl 37 openresolv 38 pciutils 39 pcmciautils 40 reiserfsprogs 41 s-nail 42 systemd-sysvcompat 43 usbutils 44 vi 45 xfsprogs 46 ) 47 IFS=',' 48 PKGIGNORE="${PKGIGNORE[*]}" 49 unset IFS 50 51 arch="$(uname -m)" 52 case "$arch" in 53 armv*) 54 if pacman -Q archlinuxarm-keyring >/dev/null 2>&1; then 55 pacman-key --init 56 pacman-key --populate archlinuxarm 57 else 58 echo "Could not find archlinuxarm-keyring. Please, install it and run pacman-key --populate archlinuxarm" 59 exit 1 60 fi 61 PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX) 62 version="$(echo $arch | cut -c 5)" 63 sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}" 64 PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo' 65 PACMAN_EXTRA_PKGS='archlinuxarm-keyring' 66 EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1) 67 ARCH_KEYRING=archlinuxarm 68 DOCKER_IMAGE_NAME="armv${version}h/archlinux" 69 ;; 70 *) 71 PACMAN_CONF='./mkimage-arch-pacman.conf' 72 PACMAN_MIRRORLIST='Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch' 73 PACMAN_EXTRA_PKGS='' 74 EXPECT_TIMEOUT=60 75 ARCH_KEYRING=archlinux 76 DOCKER_IMAGE_NAME=archlinux 77 ;; 78 esac 79 80 export PACMAN_MIRRORLIST 81 82 expect <<EOF 83 set send_slow {1 .1} 84 proc send {ignore arg} { 85 sleep .1 86 exp_send -s -- \$arg 87 } 88 set timeout $EXPECT_TIMEOUT 89 90 spawn pacstrap -C $PACMAN_CONF -c -d -G -i $ROOTFS base haveged $PACMAN_EXTRA_PKGS --ignore $PKGIGNORE 91 expect { 92 -exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue } 93 -exact "(default=all): " { send -- "\r"; exp_continue } 94 -exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue } 95 -exact "delete it? \[Y/n\]" { send -- "y\r"; exp_continue } 96 } 97 EOF 98 99 arch-chroot $ROOTFS /bin/sh -c 'rm -r /usr/share/man/*' 100 arch-chroot $ROOTFS /bin/sh -c "haveged -w 1024; pacman-key --init; pkill haveged; pacman -Rs --noconfirm haveged; pacman-key --populate $ARCH_KEYRING; pkill gpg-agent" 101 arch-chroot $ROOTFS /bin/sh -c "ln -s /usr/share/zoneinfo/UTC /etc/localtime" 102 echo 'en_US.UTF-8 UTF-8' > $ROOTFS/etc/locale.gen 103 arch-chroot $ROOTFS locale-gen 104 arch-chroot $ROOTFS /bin/sh -c 'echo $PACMAN_MIRRORLIST > /etc/pacman.d/mirrorlist' 105 106 # udev doesn't work in containers, rebuild /dev 107 DEV=$ROOTFS/dev 108 rm -rf $DEV 109 mkdir -p $DEV 110 mknod -m 666 $DEV/null c 1 3 111 mknod -m 666 $DEV/zero c 1 5 112 mknod -m 666 $DEV/random c 1 8 113 mknod -m 666 $DEV/urandom c 1 9 114 mkdir -m 755 $DEV/pts 115 mkdir -m 1777 $DEV/shm 116 mknod -m 666 $DEV/tty c 5 0 117 mknod -m 600 $DEV/console c 5 1 118 mknod -m 666 $DEV/tty0 c 4 0 119 mknod -m 666 $DEV/full c 1 7 120 mknod -m 600 $DEV/initctl p 121 mknod -m 666 $DEV/ptmx c 5 2 122 ln -sf /proc/self/fd $DEV/fd 123 124 tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - $DOCKER_IMAGE_NAME 125 docker run --rm -t $DOCKER_IMAGE_NAME echo Success. 126 rm -rf $ROOTFS