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