| #!/bin/bash -ux | |
| # | |
| # image.img.dist - converted to qcow2 | |
| # image.img.orig - downloaded version | |
| # image.img - final disk image | |
| RELEASE="xenial" | |
| IMG_URL="http://cloud-images.ubuntu.com/daily/server/$RELEASE/current" | |
| SEED_FILE="seed.img" | |
| USER_DATA="user-data.yaml" | |
| ########################################################### | |
| ## Is the image available locally? If not, download it | |
| # TODO put date on daily images | |
| if [ ! -e "images/$RELEASE.img.orig" ]; then | |
| if [ -e "images/$RELEASE.img.dist" ]; then | |
| rm images/$RELEASE.img.dist | |
| fi | |
| if [ "$RELEASE" == "xenial" ] || [ "$RELEASE" == "trusty" ]; then | |
| url="$IMG_URL/$RELEASE-server-cloudimg-amd64-disk1.img" | |
| else | |
| url="$IMG_URL/$RELEASE-server-cloudimg-amd64.img" | |
| fi | |
| wget -O images/$RELEASE.img.dist $url | |
| qemu-img convert -O qcow2 images/$RELEASE.img.dist images/$RELEASE.img.orig | |
| fi | |
| ## Make a fresh copy of the image | |
| if [ -e "images/$RELEASE.img" ]; then | |
| rm images/$RELEASE.img | |
| fi | |
| qemu-img create -f qcow2 -b $RELEASE.img.orig images/$RELEASE.img | |
| ########################################################### | |
| ## Make seed file with user data | |
| if [ -e $SEED_FILE ]; then | |
| rm $SEED_FILE | |
| fi | |
| cloud-localds $SEED_FILE $USER_DATA | |
| ########################################################### | |
| ## Boot QEMU image | |
| # Remove existing host key | |
| ssh-keygen -f "/home/$USER/.ssh/known_hosts" -R [localhost]:2222 | |
| qemu-system-x86_64 -enable-kvm \ | |
| -drive file=images/$RELEASE.img,format=qcow2,if=virtio \ | |
| -drive file=$SEED_FILE,format=raw,if=virtio \ | |
| -device virtio-net-pci,netdev=net00 \ | |
| -netdev type=user,id=net00,hostfwd=tcp::2222-:22 \ | |
| -m 1024 | |
| #TODO check that cloud-init is done and print out result | |
| ########################################################### | |
| # #TODO print out ssh info | |
| # ssh -p 2222 ubuntu@localhost | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment