github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/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 ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX) 18 chmod 755 $ROOTFS 19 20 # packages to ignore for space savings 21 PKGIGNORE=linux,jfsutils,lvm2,cryptsetup,groff,man-db,man-pages,mdadm,pciutils,pcmciautils,reiserfsprogs,s-nail,xfsprogs 22 23 expect <<EOF 24 set send_slow {1 .1} 25 proc send {ignore arg} { 26 sleep .1 27 exp_send -s -- \$arg 28 } 29 set timeout 60 30 31 spawn pacstrap -C ./mkimage-arch-pacman.conf -c -d -G -i $ROOTFS base haveged --ignore $PKGIGNORE 32 expect { 33 -exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue } 34 -exact "(default=all): " { send -- "\r"; exp_continue } 35 -exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue } 36 } 37 EOF 38 39 arch-chroot $ROOTFS /bin/sh -c "haveged -w 1024; pacman-key --init; pkill haveged; pacman -Rs --noconfirm haveged; pacman-key --populate archlinux; pkill gpg-agent" 40 arch-chroot $ROOTFS /bin/sh -c "ln -s /usr/share/zoneinfo/UTC /etc/localtime" 41 echo 'en_US.UTF-8 UTF-8' > $ROOTFS/etc/locale.gen 42 arch-chroot $ROOTFS locale-gen 43 arch-chroot $ROOTFS /bin/sh -c 'echo "Server = https://mirrors.kernel.org/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist' 44 45 # udev doesn't work in containers, rebuild /dev 46 DEV=$ROOTFS/dev 47 rm -rf $DEV 48 mkdir -p $DEV 49 mknod -m 666 $DEV/null c 1 3 50 mknod -m 666 $DEV/zero c 1 5 51 mknod -m 666 $DEV/random c 1 8 52 mknod -m 666 $DEV/urandom c 1 9 53 mkdir -m 755 $DEV/pts 54 mkdir -m 1777 $DEV/shm 55 mknod -m 666 $DEV/tty c 5 0 56 mknod -m 600 $DEV/console c 5 1 57 mknod -m 666 $DEV/tty0 c 4 0 58 mknod -m 666 $DEV/full c 1 7 59 mknod -m 600 $DEV/initctl p 60 mknod -m 666 $DEV/ptmx c 5 2 61 ln -sf /proc/self/fd $DEV/fd 62 63 tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - archlinux 64 docker run -i -t archlinux echo Success. 65 rm -rf $ROOTFS