github.com/raychaser/docker@v1.5.0/contrib/mkimage-crux.sh (about) 1 #!/usr/bin/env bash 2 # Generate a minimal filesystem for CRUX/Linux and load it into the local 3 # docker as "cruxlinux" 4 # requires root and the crux iso (http://crux.nu) 5 6 set -e 7 8 die () { 9 echo >&2 "$@" 10 exit 1 11 } 12 13 [ "$#" -eq 1 ] || die "1 argument(s) required, $# provided. Usage: ./mkimage-crux.sh /path/to/iso" 14 15 ISO=${1} 16 17 ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-crux-XXXXXXXXXX) 18 CRUX=$(mktemp -d ${TMPDIR:-/var/tmp}/crux-XXXXXXXXXX) 19 TMP=$(mktemp -d ${TMPDIR:-/var/tmp}/XXXXXXXXXX) 20 21 VERSION=$(basename --suffix=.iso $ISO | sed 's/[^0-9.]*\([0-9.]*\).*/\1/') 22 23 # Mount the ISO 24 mount -o ro,loop $ISO $CRUX 25 26 # Extract pkgutils 27 tar -C $TMP -xf $CRUX/tools/pkgutils#*.pkg.tar.gz 28 29 # Put pkgadd in the $PATH 30 export PATH="$TMP/usr/bin:$PATH" 31 32 # Install core packages 33 mkdir -p $ROOTFS/var/lib/pkg 34 touch $ROOTFS/var/lib/pkg/db 35 for pkg in $CRUX/crux/core/*; do 36 pkgadd -r $ROOTFS $pkg 37 done 38 39 # Remove agetty and inittab config 40 if (grep agetty ${ROOTFS}/etc/inittab 2>&1 > /dev/null); then 41 echo "Removing agetty from /etc/inittab ..." 42 chroot ${ROOTFS} sed -i -e "/agetty/d" /etc/inittab 43 chroot ${ROOTFS} sed -i -e "/shutdown/d" /etc/inittab 44 chroot ${ROOTFS} sed -i -e "/^$/N;/^\n$/d" /etc/inittab 45 fi 46 47 # Remove kernel source 48 rm -rf $ROOTFS/usr/src/* 49 50 # udev doesn't work in containers, rebuild /dev 51 DEV=$ROOTFS/dev 52 rm -rf $DEV 53 mkdir -p $DEV 54 mknod -m 666 $DEV/null c 1 3 55 mknod -m 666 $DEV/zero c 1 5 56 mknod -m 666 $DEV/random c 1 8 57 mknod -m 666 $DEV/urandom c 1 9 58 mkdir -m 755 $DEV/pts 59 mkdir -m 1777 $DEV/shm 60 mknod -m 666 $DEV/tty c 5 0 61 mknod -m 600 $DEV/console c 5 1 62 mknod -m 666 $DEV/tty0 c 4 0 63 mknod -m 666 $DEV/full c 1 7 64 mknod -m 600 $DEV/initctl p 65 mknod -m 666 $DEV/ptmx c 5 2 66 67 IMAGE_ID=$(tar --numeric-owner -C $ROOTFS -c . | docker import - crux:$VERSION) 68 docker tag $IMAGE_ID crux:latest 69 docker run -i -t crux echo Success. 70 71 # Cleanup 72 umount $CRUX 73 rm -rf $ROOTFS 74 rm -rf $CRUX 75 rm -rf $TMP