Forked from relyt0925/provision_ubuntu2004_qemu_macosx.sh
Created
July 1, 2023 11:05
-
-
Save pertsevds/ce01d7baeff41cd5c3301558ec40d10b to your computer and use it in GitHub Desktop.
Provisions a Ubuntu 20.04 VM in QEMU on Mac OSX using Cloud-Init
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#Install brew and qemu + cloud init metadata dependencies | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" | |
brew install qemu | |
brew install cdrtools | |
rm -rf /tmp/ubuntuqemuboot | |
#download Ubuntu 20.04 Cloud Image and resize to 30 Gigs | |
mkdir -p /tmp/ubuntuqemuboot/images | |
cd /tmp/ubuntuqemuboot/images | |
curl https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img --output focal-server-cloudimg-amd64.img | |
qemu-img resize focal-server-cloudimg-amd64.img 30G | |
#create the cloud-init NoCloud metadata disk file | |
mkdir -p /tmp/ubuntuqemuboot/cloudinitmetadata | |
cd /tmp/ubuntuqemuboot/cloudinitmetadata | |
ssh-keygen -b 2048 -t rsa -f id_rsa_ubuntu2004boot -P "" | |
chmod 0600 /tmp/ubuntuqemuboot/cloudinitmetadata/id_rsa_ubuntu2004boot | |
PUBLIC_KEY=$(cat id_rsa_ubuntu2004boot.pub) | |
cat <<EOF >/tmp/ubuntuqemuboot/cloudinitmetadata/meta-data | |
instance-id: circle-the-wagons-local716 | |
local-hostname: circle-the-wagons | |
EOF | |
cat <<EOF >/tmp/ubuntuqemuboot/cloudinitmetadata/user-data | |
#cloud-config | |
debug: true | |
disable_root: false | |
users: | |
- name: root | |
shell: /bin/bash | |
ssh-authorized-keys: | |
- ${PUBLIC_KEY} | |
EOF | |
#create the cloud-init optical drive | |
mkisofs -output cidata.iso -volid cidata -joliet -rock user-data meta-data | |
#boot the machine up | |
qemu-system-x86_64 -m 2048 -smp 4 -hda /tmp/ubuntuqemuboot/images/focal-server-cloudimg-amd64.img -cdrom /tmp/ubuntuqemuboot/cloudinitmetadata/cidata.iso -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22 -nographic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment