A "Data Source" to cloud-init provides 2 essential bits of information that turn a generic cloud-image into a cloud instance that is actually usable to its creator. Those are:
- public ssh key
- user-data
Very early on it felt like we should have a way to use these images outside of a cloud. They were essentially ready-to-use installations of Ubuntu Server that allow you to bypass installation. In 11.04 we added the OVF as a data source and a tool in cloud-init's source tree for creating a OVF ISO Transport that cloud-init would read data from. It wasn't until 12.04 that we improved the "NoCloud" data source to make this even easier.
Available in cloud-utils, and packaged in Ubuntu 12.10 is a utility named 'cloud-localds'. This makes it trivial to create a "local datasource" that the cloud-images will then use to get the ssh key and/or user-data described above.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Install a necessary packages | |
$ sudo apt-get install kvm cloud-utils genisoimage | |
## URL to most recent cloud image of 12.04 | |
$ img_url="http://cloud-images.ubuntu.com/server/releases/12.04/release" | |
$ img_url="${img_url}/ubuntu-12.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 512 |
Some notes about the above:
- None of the commands other than 'apt-get install' require root.
- The 2 qemu-img commands are not strictly necessary.
- The 'convert' converts the compressed qcow2 disk image as downloaded to an uncompressed version. If you don't do this the image will still boot, but reads will go decompression.
- The 'create' creates a new qcow2 delta image backed by 'disk1.img.orig'. It is not necessary, but useful to keep the '.orig' file pristine. All writes in the kvm instance will go to the disk.img file.
- libvirt, different kvm networking or disk could have been used. The kvm command above is just the simplest for demonstration. (I'm a big fan of the '-curses' option to kvm.)
- In the kvm command above, you'll need to hit 'ctrl-alt-3' to see kernel boot messages and boot progress. That is because the cloud images by default send console output to the first serial device, that a cloud provider is likely to log.
- There is no default password in the Ubuntu images. The password was set by the user-data provided.