-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2-halvm.sh
executable file
·82 lines (71 loc) · 2.54 KB
/
ec2-halvm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# Build an EC2 bundle and upload/register it to Amazon.
source envs
NAME=halvm
BUCKET=halvm-test0
REGION=us-east-1
while getopts "hn:b:r:k:" arg; do
case $arg in
h)
echo "usage: $0 [-h] [-n <name>] [-b <bucket>] [-r <region>] -k <unikernel> "
echo ""
echo "<unikernel>: Name of the kernel file (e.g. mir-www.xen)"
echo "<name>: the application name to use (default: ${NAME})"
echo "<bucket>: the S3 bucket to upload to (default: ${BUCKET})"
echo "<region>: the EC2 region to register AMI in (default: ${REGION})"
echo Remember to set each of the following environment variables in your
echo environment before running this script:
echo EC2_ACCESS, EC2_ACCESS_SECRET, EC2_CERT, EC2_PRIVATE_KEY
exit 1 ;;
n) NAME=$OPTARG ;;
b) BUCKET=$OPTARG ;;
r) REGION=$OPTARG ;;
k) APP=$OPTARG ;;
esac
done
if [ ! -e "$APP" ]; then
echo "Must specify a unikernel file with the [-k] flag."
echo "Run '$0 -h' for full option list."
exit 1
fi
# Make name unique to avoid registration clashes
NAME=${NAME}-`date +%s`
MNT=/tmp/halvm-ec2
SUDO=sudo
IMG=${NAME}.img
echo Name : ${NAME}
echo Bucket: ${BUCKET}
echo Region: ${REGION}
set -e
# KERNEL is ec2-describe-images -o amazon --region ${REGION} -F "manifest-location=*pv-grub-hd0*" -F "architecture=x86_64" | tail -1 | cut -f2
# Also obtained from http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedKernels.html
KERNEL=aki-919dcaf8 # us-east-1
${SUDO} mkdir -p ${MNT}
rm -f ${IMG}
dd if=/dev/zero of=${IMG} bs=1M count=10
${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 HaLVM >> menu.lst
echo " root (hd0)" >> menu.lst
echo " kernel /boot/halvm.gz" >> menu.lst
${SUDO} mv menu.lst ${MNT}/boot/grub/menu.lst
${SUDO} sh -c "gzip -c $APP > ${MNT}/boot/halvm.gz"
${SUDO} umount -d ${MNT}
rm -rf ec2_tmp
mkdir ec2_tmp
echo Bundling image...
ec2-bundle-image -i ${IMG} -k ${EC2_PRIVATE_KEY} -c ${EC2_CERT} -u ${EC2_USER} -d ec2_tmp -r x86_64 --kernel ${KERNEL}
echo Uploading image...
ec2-upload-bundle -b ${BUCKET} -m ec2_tmp/${IMG}.manifest.xml -a ${EC2_ACCESS} -s ${EC2_ACCESS_SECRET} --location US
echo Registering image...
id=`ec2-register ${BUCKET}/${IMG}.manifest.xml -n ${NAME} --region ${REGION} | awk '{print $2}'`
rm -rf ec2_tmp
rm -f ${IMG}
echo You can now start this instance via:
echo ec2-run-instances --region ${REGION} $id
echo ""
echo Don\'t forget to customise this with a security group, as the
echo default one won\'t let any inbound traffic in.