Skip to content

Instantly share code, notes, and snippets.

@elemoine
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elemoine/27748e205d36a9006190 to your computer and use it in GitHub Desktop.
Save elemoine/27748e205d36a9006190 to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://gist.github.com/elemoine/27748e205d36a9006190
# Install packages.
sudo apt-get install kvm cloud-utils
# Download an Ubuntu cloud image.
wget http://cloud-images.ubuntu.com/releases/14.04/release/ubuntu-14.04-server-cloudimg-amd64-disk1.img -O disk.img.dist
# Create user-data file for devstack.
# See http://docs.openstack.org/developer/devstack/guides/single-vm.html.
cat > user-data << EOF
#cloud-config
password: ubuntu
chpasswd: {expire: False}
ssh_pwauth: True
users:
- default
- name: stack
lock_passwd: False
sudo: ["ALL=(ALL) NOPASSWD:ALL\nDefaults:stack !requiretty"]
shell: /bin/bash
write_files:
- content: |
#!/bin/sh
DEBIAN_FRONTEND=noninteractive sudo apt-get -qqy update || sudo yum update -qy
DEBIAN_FRONTEND=noninteractive sudo apt-get install -qqy git || sudo yum install -qy git
sudo chown stack:stack /home/stack
cd /home/stack
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack
echo '[[local|localrc]]' > local.conf
echo ADMIN_PASSWORD=password >> local.conf
echo MYSQL_PASSWORD=password >> local.conf
echo RABBIT_PASSWORD=password >> local.conf
echo SERVICE_PASSWORD=password >> local.conf
echo SERVICE_TOKEN=tokentoken >> local.conf
./stack.sh
path: /home/stack/start.sh
permissions: 0755
runcmd:
- su -l stack ./start.sh
EOF
# Create the disk with nocloud data on it.
cloud-localds seed.img user-data
# Convert the compressed qcow file downloaded to a uncompressed qcow2.
qemu-img convert -O qcow2 disk.img.dist disk.img.orig
# Resize the image.
qemu-img resize disk.img.orig +10G
# Create a delta disk to keep our .orig file pristine.
# Re-run this command each time you want to start fresh.
qemu-img create -f qcow2 -b disk.img.orig disk.img
# Boot using kvm.
# Use ssh -p 2222 ubuntu@localhost to ssh into the virtual machine. Password is "ubuntu".
$ kvm -net nic -net user,hostfwd=tcp::2222-:22 -drive file=disk.img,if=virtio -drive file=seed.img,if=virtio -m 4096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment