Skip to content

Instantly share code, notes, and snippets.

@Lirt
Forked from smoser/gist:4756561
Last active December 11, 2017 08:31
Show Gist options
  • Save Lirt/e22e5b6b28499fb55f518f9c7bd29dae to your computer and use it in GitHub Desktop.
Save Lirt/e22e5b6b28499fb55f518f9c7bd29dae to your computer and use it in GitHub Desktop.
boot a cloud image in kvm
## Install a necessary packages
sudo apt-get install kvm cloud-utils genisoimage
modprobe kvm && modprobe kvm-intel
## URL to most recent cloud image of 16.04
img_url="http://cloud-images.ubuntu.com/server/releases/16.04/release"
img_url="${img_url}/ubuntu-16.04-server-cloudimg-amd64-disk1.img"
## download the image
wget $img_url -O disk.img.dist
## Create a file with some user-data in it
cat > my-user-data <<EOF
#cloud-config
password: passw0rd
chpasswd: { expire: False }
ssh_pwauth: True
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 my-seed.img my-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 -hdb my-seed.img -m 1024
# Cirros
# Download from http://download.cirros-cloud.net/
username: cirros
password: cubswin:)
# Test qemu guest agent
virsh qemu-agent-command $INSTANCE '{"execute":"guest-info"}'
virsh qemu-agent-command $INSTANCE '{"execute":"guest-ping"}'
virsh qemu-agent-command $INSTANCE '{"execute":"guest-network-get-interfaces"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment