github.com/slene/docker@v1.8.0-rc1/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 export LANG="C.UTF-8" 18 19 ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX) 20 chmod 755 $ROOTFS 21 22 # packages to ignore for space savings 23 PKGIGNORE=( 24 cryptsetup 25 device-mapper 26 dhcpcd 27 iproute2 28 jfsutils 29 linux 30 lvm2 31 man-db 32 man-pages 33 mdadm 34 nano 35 netctl 36 openresolv 37 pciutils 38 pcmciautils 39 reiserfsprogs 40 s-nail 41 systemd-sysvcompat 42 usbutils 43 vi 44 xfsprogs 45 ) 46 IFS=',' 47 PKGIGNORE="${PKGIGNORE[*]}" 48 unset IFS 49 50 expect <<EOF 51 set send_slow {1 .1} 52 proc send {ignore arg} { 53 sleep .1 54 exp_send -s -- \$arg 55 } 56 set timeout 60 57 58 spawn pacstrap -C ./mkimage-arch-pacman.conf -c -d -G -i $ROOTFS base haveged --ignore $PKGIGNORE 59 expect { 60 -exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue } 61 -exact "(default=all): " { send -- "\r"; exp_continue } 62 -exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue } 63 } 64 EOF 65 66 arch-chroot $ROOTFS /bin/sh -c 'rm -r /usr/share/man/*' 67 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" 68 arch-chroot $ROOTFS /bin/sh -c "ln -s /usr/share/zoneinfo/UTC /etc/localtime" 69 echo 'en_US.UTF-8 UTF-8' > $ROOTFS/etc/locale.gen 70 arch-chroot $ROOTFS locale-gen 71 arch-chroot $ROOTFS /bin/sh -c 'echo "Server = https://mirrors.kernel.org/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist' 72 73 # udev doesn't work in containers, rebuild /dev 74 DEV=$ROOTFS/dev 75 rm -rf $DEV 76 mkdir -p $DEV 77 mknod -m 666 $DEV/null c 1 3 78 mknod -m 666 $DEV/zero c 1 5 79 mknod -m 666 $DEV/random c 1 8 80 mknod -m 666 $DEV/urandom c 1 9 81 mkdir -m 755 $DEV/pts 82 mkdir -m 1777 $DEV/shm 83 mknod -m 666 $DEV/tty c 5 0 84 mknod -m 600 $DEV/console c 5 1 85 mknod -m 666 $DEV/tty0 c 4 0 86 mknod -m 666 $DEV/full c 1 7 87 mknod -m 600 $DEV/initctl p 88 mknod -m 666 $DEV/ptmx c 5 2 89 ln -sf /proc/self/fd $DEV/fd 90 91 tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - archlinux 92 docker run -t archlinux echo Success. 93 rm -rf $ROOTFS