Skip to content

Instantly share code, notes, and snippets.

@moonlightdrive
Created August 17, 2014 04:30
Show Gist options
  • Save moonlightdrive/94a8a254f7ac7f6ed479 to your computer and use it in GitHub Desktop.
Save moonlightdrive/94a8a254f7ac7f6ed479 to your computer and use it in GitHub Desktop.
Create image from unikernel
#!/usr/bin/env bash
# Create an image from a unikernel.
# Props to Mirage for this script, which was derived from
# https://raw.githubusercontent.com/mirage/mirage/master/scripts/ec2.sh
while getopts "hn:k:" arg; do
case $arg in
h)
echo "usage: $0 [-h] [-n <name>] [-r <region>] -k <unikernel> "
echo ""
echo "<unikernel>: Name of the kernel file (e.g. mir-www.xen)"
echo "<name>: the application name to use"
exit 1 ;;
n) NAME=$OPTARG ;;
k) APP=$OPTARG ;;
esac
done
if [ ! -e "$APP" ]; then
echo "Must specify a unikernel file with -k."
exit 1
fi
# Make name unique to avoid registration clashes
[ ! "$NAME" ] && NAME=$(basename $APP .xen)
NAME=${NAME} -`date +%s`
MNT=/tmp/mirage-ec2
SUDO=sudo
IMG=${NAME}.img
echo Name : ${NAME}
set -e
${SUDO} mkdir -p ${MNT}
rm -f ${IMG}
dd if=/dev/zero of=${IMG} bs=1M count=5
${SUDO} mke2fs -F -j ${IMG}
${SUDO} mount -o loop ${IMG} ${MNT}
${SUDO} mkdir -p ${MNT}/boot/grub
echo default 0 > menu.lst
echo timeout 1 >> menu.lst
echo title Mirage >> menu.lst
echo " root (hd0)" >> menu.lst
echo " kernel /boot/mirage-os.gz" >> menu.lst
${SUDO} mv menu.lst ${MNT}/boot/grub/menu.lst
${SUDO} sh -c "gzip -c $APP > ${MNT}/boot/mirage-os.gz"
${SUDO} umount -d ${MNT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment