Skip to content

Instantly share code, notes, and snippets.

@leafac
Created February 5, 2026 13:36
Show Gist options
  • Select an option

  • Save leafac/1aac8d19796f05c27bf0f709077b6a1d to your computer and use it in GitHub Desktop.

Select an option

Save leafac/1aac8d19796f05c27bf0f709077b6a1d to your computer and use it in GitHub Desktop.

Setting up Ubuntu Cloud virtual machine in macOS with QEMU

Install QEMU:

brew install qemu

Download Ubuntu Cloud:

mkdir images/
cd images/ && wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img && cd ..

Copy image and resize it:

rm -f ubuntu.img
cp images/jammy-server-cloudimg-amd64.img ubuntu.img
qemu-img resize ubuntu.img 10G

Create cloud-init:

  • cloud-init/meta-data
  • cloud-init/network-config
  • cloud-init/user-data:
    #cloud-config
    password: ubuntu
    chpasswd:
      expire: False
rm -f cloud-init.iso
hdiutil makehybrid -o cloud-init.iso -hfs -joliet -iso -default-volume-name cidata cloud-init/

Start virtual machine with QEMU:

qemu-system-x86_64 -nographic -machine q35 -cpu max -smp 4 -m 2G -nic user,model=virtio-net-pci,hostfwd=tcp::80-:80 -virtfs local,path=/Users/leafac/code/,mount_tag=code,security_model=mapped-xattr -cdrom cloud-init.iso ubuntu.img

Setup virtual machine:

sudo apt update
sudo apt install -y build-essential procps curl file git bindfs
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo >> /home/ubuntu/.bashrc
echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"' >> /home/ubuntu/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv bash)"
brew install gcc

Mount shared folder:

sudo mkdir -p /mnt/code
sudo mount -t 9p -o trans=virtio code /mnt/code
mkdir -p code
sudo bindfs -u ubuntu -g ubuntu /mnt/code code

Allow any user to bind to any port:

sudo sysctl -w net.ipv4.ip_unprivileged_port_start=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment