Skip to content

Instantly share code, notes, and snippets.

@arges
Created November 10, 2016 15:07
Show Gist options
  • Save arges/54d04d4f62ef249dab964ad5508ff77c to your computer and use it in GitHub Desktop.
Save arges/54d04d4f62ef249dab964ad5508ff77c to your computer and use it in GitHub Desktop.
#!/bin/bash -x
# Dependencies
sudo apt-get install -y kvm cloud-utils genisoimage
# Download cloud image
img_url="http://cloud-images.ubuntu.com/server/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
wget $img_url -O disk.img.dist
# Create user-data
cat > user-data <<EOF
#cloud-config
password: password
chpasswd: { expire: False }
ssh_pwauth: True
runcmd:
- [ sh, -xc, "echo 'password: password\nchpasswd: { expire: False }\nssh_pwauth: True' | tee /var/lib/cloud/seed/user-data" ]
- [ sh, -xc, "echo '{\"instance-id\": \"iid-local01\"}' | tee /var/lib/cloud/seed/meta-data" ]
- [ sh, -xc, "echo 'datasource_list: [ NoCloud ]' | sudo tee /etc/cloud/cloud.cfg.d/90_dpkg.cfg" ]
- dpkg-reconfigure -f noninteractive cloud-init
- poweroff
EOF
# Convert the compressed qcow file downloaded to a uncompressed qcow2
qemu-img convert -O qcow2 disk.img.dist disk.img.orig
# Create the disk with NoCloud data on it.
cloud-localds -d raw seed.img user-data
# Create a delta disk to keep our .orig file pristine
qemu-img create -f qcow2 -b disk.img.orig disk.img
# Boot a kvm
kvm -net nic -net user -hda disk.img -drive file=seed.img,index=1,media=disk,format=raw -m 512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment