Ubuntu images can be booted with an additional disk that provides user-data, meta-data and network configuration. This is described some in the upstream documentation.
But this example allows for more easily tinkering.
See a screencast of this on asciinema.org.
A brief description of files here.
-
check-dependencies: check that all dependencies are available. It will give you an
apt-get
command to install any missing packages. -
get-image: download an ubuntu disk image from cloud-images.ubuntu.com
-
boot: wrapper around calling qemu-system-x86_64 as those command lines are not so friendly. It will pass through additional arguments to qemu.
-
network-config-v1.yaml, network-config-v2.yaml: network config files version 1 and version 2 from upstream doc
-
user-data.yaml: example user-data that sets password for login. Note that not all user-data is required to be yaml formatted, but this example is '#cloud-config' which is yaml.
-
meta-data.yaml: example meta-data for nocloud.
Heres an example walking through how to use this.
-
Verify dependencies
$ ./check-dependencies All good. (cloud-localds genisoimage qemu-img qemu-system-x86_64 wget)
-
Download an image
Original images are compressed qcow2. get-image downloads an original image and converts it to 'raw' format. This is not strictly necessary, but booting a compressed qcow2 directly means that all disk reads go through decompression.
$ ./get-image xenial downloading <...> dist: xenial-server-cloudimg-amd64-disk1.img raw: xenial-server-cloudimg-amd64.raw
-
Build a seed image from provided files
cloud-localds
creates an iso9660 filesystem with expected content. Specifically the filesystem label is 'cidata', and the top level directory has 'meta-data', 'user-data', and 'network-config' files. network-config is optional.$ cloud-localds -v --network-config=network-config-v1.yaml \ seed.img user-data.yaml meta-data.yaml wrote seed.img with filesystem=iso9660 and diskformat=raw
-
Create a qcow2 disk named 'disk.img' backed by the raw image
By using a qcow image backed by the raw, we can avoid modifying the original.
$ qemu-img create -f qcow2 -b xenial-server-cloudimg-amd64.raw disk.img
-
Boot the image
By default, boot will run qemu in vga graphics mode, and create a window on your system. It will boot to a login prompt and you can login with username
ubuntu
and passwordpassw0rd
.I like to boot with qemu's
-nographic
option, which will display the full boot in a terminal which is better for demos. See a full boot log hereSome things to look at once you've logged in
$ cat /run/cloud-init/result.json { "v1": { "datasource": "DataSourceNoCloud [seed=/dev/sr0][dsmode=net]", "errors": [] } } $ grep -v '^[#]' /etc/network/interfaces.d/50-cloud-init.cfg auto lo iface lo inet loopback auto interface0 iface interface0 inet static address 192.168.1.10/24 gateway 192.168.1.254 $ grep INFO /var/log/cloud-init.log 2017-11-03 18:10:18,785 - stages.py[INFO]: Loaded datasource DataSourceNoCloud - DataSourceNoCloud [seed=/dev/sr0][dsmode=net] 2017-11-03 18:10:18,964 - stages.py[INFO]: Applying network configuration from ds bringup=False: {'config': [{'type': 'physical', 'mac_address': '52:54:00:12:34:00', 'name': 'interface0', 'subnets': [{'netmask': '255.255.255.0', 'gateway': '192.168.1.254', 'type': 'static', 'address': '192.168.1.10'}]}], 'version': 1} 2017-11-03 18:10:22,954 - cc_apt_configure.py[INFO]: No custom template provided, fall back to builtin
@smoser this is great! thank you!