Skip to content

Instantly share code, notes, and snippets.

@smoser
Created February 17, 2022 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smoser/09f60b725f29d34239f47cc67dca887c to your computer and use it in GitHub Desktop.
Save smoser/09f60b725f29d34239f47cc67dca887c to your computer and use it in GitHub Desktop.
Boot Ubuntu maas kernel and initrd with cloud-init network seed.

Boot Ubuntu MAAS kernel, initrd and squashfs with cloud-init seed data.

The demo-it script here will do the following:

  • download kernel and initrd from published MAAS images
  • download the minimal squashfs image from cloud-images.ubuntu.com.
    We use the minimal image just because it is smaller than the maas provided ephemeral image. We could use that just as well.
  • create cloud-init 'user-data' and 'meta-data'
  • boot qemu with the provided kernel and initrd use the kernel command line to:
    • provide it with a 'rooturl` to the squashfs image
    • use overlayfs to give writable space
    • provide cloud-init with a 'nocloud-net' datasource

Once you run, you can log in with 'ubuntu' and 'passw0rd'.

Notes

#!/bin/sh
myurl="http://10.0.2.2:8888"
baseurl="http://images.maas.io/ephemeral-v3/stable/focal/amd64/20220131.1"
kurl="$baseurl/hwe-20.04/generic/boot-kernel"
iurl="$baseurl/hwe-20.04/generic/boot-initrd"
surl="$baseurl/squashfs"
surl="https://cloud-images.ubuntu.com/minimal/daily/focal/20220210/focal-minimal-cloudimg-amd64.squashfs"
dl() {
[ -f "$2" ] && return 0
wget "$1" -O "$2.tmp" && mv "$2.tmp" "$2"
}
fail() { echo "$@" 1>&2; exit 1; }
dl "$kurl" boot-kernel &&
dl "$iurl" boot-initrd &&
dl "$surl" squashfs ||
fail "failed downloads"
if [ ! -e "user-data" ]; then
cat > "user-data" <<EOF
#cloud-config
password: passw0rd
chpasswd: { expire: False }
ssh_pwauth: True
EOF
fi
if [ ! -e "meta-data" ]; then
echo "instance-id: i-demo" > meta-data
fi
append="root=$myurl/squashfs console=ttyS0 overlayroot=tmpfs"
append="$append ds=nocloud-net;seedfrom=$myurl/"
qemu-system-x86_64 \
-enable-kvm \
-device virtio-net-pci,netdev=net00 \
-netdev type=user,id=net00 \
-m 1G -nographic \
-kernel boot-kernel -initrd boot-initrd \
-append "$append break=bottom,init"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment