Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ubuntu cloud image creation
How to create a simple cloud image
sudo apt-get install cloud-utils
wget https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
mv xenial-server-cloudimg-amd64-disk1.img xenial-server-cloudimg-amd64-disk1.img.dist
qemu-img convert -O qcow2 xenial-server-cloudimg-amd64-disk1.img.dist xenial-server-cloudimg-amd64-disk1.img
qemu-img resize xenial-server-cloudimg-amd64-disk1.img +40G
user-data
#cloud-config
users:
- name: demo
ssh-authorized-keys:
- ssh-rsa xxx
- ssh-rsa yyy
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
runcmd:
- sed -i -e '$aAllowUsers demo' /etc/ssh/sshd_config
- restart ssh
cloud-localds user-data.img user-data
#Create your own macvtap device with a random mac
sudo ip link del "$MACVTAP"
sudo ip link add link "$PDEV" name "$MACVTAP" type macvtap mode bridge
sudo ip link set "$MACVTAP" address 02:00:DE:AD:02:01 up
sudo ip link show "$MACVTAP"
if [ ! -f "$IMAGE" ]; then
>&2 echo "Can't find image file \"$IMAGE\""
exit 1
fi
rm -f debug.log
tapindex=$(< /sys/class/net/"$MACVTAP"/ifindex)
tapdev=/dev/tap"$tapindex"
ifconfig "$MACVTAP" up
qemu-system-x86_64 \
-enable-kvm \
-smp cpus=4,cores=2 -cpu host \
-vga none -nographic \
-drive file="$IMAGE",if=virtio,aio=threads \
-net nic,model=virtio,macaddr=$(< /sys/class/net/"$MACVTAP"/address) -net tap,fd=3 3<>"$tapdev" \
-drive file=user-data.img,if=virtio,media=cdrom \
-debugcon file:debug.log -global isa-debugcon.iobase=0x402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment