Skip to content

Instantly share code, notes, and snippets.

@konstruktoid
Created April 30, 2021 10:24
Show Gist options
  • Save konstruktoid/b401c0d14134537f7833543850073450 to your computer and use it in GitHub Desktop.
Save konstruktoid/b401c0d14134537f7833543850073450 to your computer and use it in GitHub Desktop.
#!/bin/bash
IMG=ubuntu-20.04-server-cloudimg-amd64.img
USER_DATA=user-data
if [ ! -f "${IMG}" ]; then
wget "https://cloud-images.ubuntu.com/releases/focal/release/${IMG}"
qemu-img resize "${IMG}" +10G
fi
if [ ! -f "${USER_DATA}" ]; then
echo "instance-id: $(uuidgen || echo i-abcdefg)" > meta-data
cat >user-data <<EOF
#cloud-config
users:
- default
- name: qwerty
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh_import_id: None
plain_text_passwd: 'change me, seriously'
lock_passwd: false
EOF
fi
cloud-localds --disk-format qcow2 cloud.img "${USER_DATA}"
qemu-system-x86_64 \
-drive file="${IMG}" \
-drive file=cloud.img \
-device rtl8139,netdev=net0 \
-m 2G \
-serial mon:stdio \
-smp 2 \
-vga virtio \
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment