Skip to content

Instantly share code, notes, and snippets.

@thomaswilley
Last active September 20, 2022 02:54
Show Gist options
  • Save thomaswilley/88b805de9b5e75f26dbcbb94eff4a559 to your computer and use it in GitHub Desktop.
Save thomaswilley/88b805de9b5e75f26dbcbb94eff4a559 to your computer and use it in GitHub Desktop.
QEMU setup & run ubuntu

the basics (zero to bootable)

# create disk
$ qemu-img create -f qcow2 ~/QEMU/ubuntu-desktop-18.04.qcow2 10G

# setup
$ qemu-system-x86_64 -m 2048 -vga virtio -show-cursor -usb -device usb-tablet -enable-kvm -cdrom ~/QEMU/ubuntu-18.04.2-desktop-amd64.iso -drive file=~/QEMU/ubuntu-desktop-18.04.qcow2,if=virtio -accel hvf -cpu host

# run (unmount CDROM)
$ qemu-system-x86_64 -m 2048 -vga virtio -show-cursor -usb -device usb-tablet -enable-kvm -drive file=~/QEMU/ubuntu-desktop-18.04.qcow2,if=virtio -accel hvf -cpu host

good read @ https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/

sharing host storage with guests/VMs

disclaimer: after trying a bunch of options, Samba ultimately worked best & simplest despite the non-trivial complexity associated with getting it working. if you know a better option, please lmk @thomaswilley!

  1. compile samba b/c the default osx-edition of smbd is incompatible https://gist.github.com/thomaswilley/ffcdb83c21c782cbab8a18d6134f87d7

  2. be sure you ran $ make install; then lazily run the following (lazily b/c I did a $ brew install qemu rather than compile from src and if I'd compiled from src I'dve just set the smb path to its install loc..

$ mkdir /usr/local/sbin
$ sudo ln -s /opt/samba/sbin/smbd /usr/local/sbin/smbd
$ sudo mkdir /usr/local/sbin
$ sudo ln -s /opt/samba/bin/smbd /usr/local/sbin/samba-dot-org-smbd
$ qemu-system-x86_64 -m 2048 -vga virtio -show-cursor -usb -device usb-tablet \
  -enable-kvm -drive file=absolute-path-to-ubuntu-desktop-18.04.qcow2,if=virtio \
  -accel hvf -cpu host \
  -device virtio-net,netdev=vmnic \
  -netdev user,id=vmnic,smb=path-on-hostmachine-to-share-with-guestmachine

w/in the guest os, mount the samba share:

$ sudo mkdir /mnt/share
$ sudo mount -t cifs -o user=your-user-at-host.local //10.0.2.4/qemu /mnt/share

if you want it to be persistent, copy the last line of /etc/mtab and append it to /etc/fstab.

note that when you $ sudo shutdown -r now; or otherwise reboot, QEMU can sometimes look as though it's frozen (while trying to mount the location). If this happens, just click into the QEMU VM so it captures your inputs and go ahead and type (into oblivion) the password you typed during the $ sudo mount ...; process and then a carriage return. It should boot right up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment