Skip to content

Instantly share code, notes, and snippets.

@smoser

smoser/run-overlay.sh

Last active Aug 29, 2015
Embed
What would you like to do?
overlay example with maas ephemeral image
#!/bin/bash
# maas ephemeral wily image in root-image
# given the following:
# root-image: wily maas ephemeral image in root-image from [1] (uncompressed)
# boot-kernel: wily/generic/boot-kernel
# boot-initrd: wily/generic/boot-initrd
#
# --
# [1] http://maas.ubuntu.com/images/ephemeral-v2/daily/wily/amd64/20150728.1/
set -e
## create a qcow device to make sure root-image stays pristine
qemu-img create -f qcow2 -b root-image ephemeral.img
## if you wanted to make this easier to debug, you could patch 'ephemeral.img'
## to have a root password and disable the annoying ec2 datasource with this:
#qemu-img create -f qcow2 -b root-image ephemeral.img &&
# sudo mount-image-callback ephemeral.img -- \
# chroot _MOUNTPOINT_ sh -c 'echo root:foo | chpasswd &&
# sed -i s/Ec2,// /etc/cloud/cloud.cfg.d/*.cfg'
## create some seed files for cloud-init's nocloud-net datasource
printf "%s\n%s\n%s\n%s\n" "#cloud-config" "password: passw0rd" \
"chpasswd: { expire: False }" "ssh_pwauth: True" > user-data
echo "instance-id: $(uuidgen || echo i-abcdefg)" > meta-data
## if you wanted, add a 'power_state' option to power system off
#echo "power_state: {delay: now, mode: poweroff}" >> user-data
## Now, you can either attach a 'seed.img' with the user-data and meta-data
## inside it, or you can seed the overlay with this data.
##
## note, we set 'seedflag' and reference it below when booting.
##
## To use 'seed.img' path, do the following:
#cloud-localds seed.img user-data meta-data
#seedflag="-drive if=virtio,file=seed.img,format=raw"
## 'dir=' parameter defaults to '/overlay' in newer versions of ubuntu
## but previously defaulted to /. So we just specify one and use it.
overlay_path="/delta"
cmdline="console=ttyS0 root=LABEL=cloudimg-rootfs"
cmdline="$cmdline overlayroot=device:dev=LABEL=overlay-rootfs,debug=1,dir=$overlay_path"
## now we create an overlay.img and then put some files in it.
## since we're adding the nocloud seed data here, we dont need the
## seed disk image
seedflag=""
qemu-img create -f raw overlay.img 1G &&
mkfs.ext4 -F overlay.img -L overlay-rootfs
sudo mount-image-callback overlay.img -- \
env d="${overlay_path}/var/lib/cloud/seed/nocloud-net" \
sh -c 'p=$MOUNTPOINT/$d && mkdir -p $p && cp user-data meta-data $p/'
qemu-system-x86_64 -enable-kvm \
-device virtio-net-pci,netdev=net00 \
-netdev type=user,id=net00,hostfwd=tcp::2222-:22 \
-drive if=virtio,file=ephemeral.img \
-drive if=virtio,file=overlay.img,format=raw \
$seedflag \
-kernel boot-kernel -initrd boot-initrd \
-append "$cmdline" -m 1024 -echr 0x05 -nographic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment