Skip to content

Instantly share code, notes, and snippets.

@shagunattri
Forked from citruz/QEMU_ON_M1.md
Created December 1, 2020 03:41
Show Gist options
  • Save shagunattri/0cfe78e9e7bb5a1d80495d8e7921d75a to your computer and use it in GitHub Desktop.
Save shagunattri/0cfe78e9e7bb5a1d80495d8e7921d75a to your computer and use it in GitHub Desktop.
Create Ubuntu and WIndows VMs with QEMU on Apple Silicon

Running Linux and Windows on M1 with QEMU

30.11.2020: Updated with the new patchseries and instructions for Windows

Building QEMU

curl https://patchwork.kernel.org/series/392975/mbox/ | git am
  • Install required packages for building:
brew install libffi gettext pkg-config autoconf automake pixman
  • Run the following commands to build qemu:
mkdir build
cd build
../configure --target-list=aarch64-softmmu
make
sudo make install
  • For some reason, the qemu binary is modified during make install. You need to resign it with the correct entitlements, otherwise you will get an Unknown Error:
sudo codesign --entitlements /path/to/qemu/accel/hvf/entitlements.plist --force -s - `which qemu-system-aarch64`

Create Ubuntu VM

qemu-img create -f qcow2 disk.qcow2 10G
  • Run qemu with the following command-line arguments:
qemu-system-aarch64 \
    -accel hvf \
    -m 2048 \
    -cpu cortex-a57 -M virt,highmem=off  \
    -bios edk2-aarch64-code.fd \
    -serial telnet::4444,server,nowait \
    -drive if=none,file=disk.qcow2,format=qcow2,id=hd0 \
    -device virtio-blk-device,drive=hd0,serial="dummyserial" \
    -device virtio-net-device,netdev=net0 \
    -netdev user,id=net0 \
    -vga none -device ramfb \
    -cdrom /path/to/ubuntu.iso \
    -device usb-ehci -device usb-kbd -device usb-mouse -usb \
    -monitor stdio
  • You should be able to install Ubuntu as normal
  • If you want a desktop environment, you can install it using sudo apt-get install ubuntu-desktop

Create Windows VM

  • Download Windows for ARM from here
  • For Windows, we need to replace the VirtIO block device with something that is supported natively by the OS. Otherwise, the command-line is almost unchanged
  • You may want to pass multiple cores to the VM using -smp X:
qemu-system-aarch64 \
    -accel hvf \
    -m 2048 -smp 2 \
    -cpu cortex-a72 -M virt,highmem=off  \
    -bios edk2-aarch64-code.fd \
    -serial telnet::4444,server,nowait \
    -drive if=none,file=Windows10_InsiderPreview_Client_ARM64_en-us_20231.VHDX,format=vhdx,id=hd0 \
    -device nvme,drive=hd0,serial="dummyserial" \
    -device virtio-net-device,netdev=net0 \
    -netdev user,id=net0 \
    -vga none -device ramfb \
    -device usb-ehci -device usb-kbd -device usb-mouse -usb \
    -monitor stdio

Limitations

Networking on Windows

Windows does not support VirtIO network interfaces out of the box. To get it working, you need to install additional drivers. See this gist for a guide (be sure to use version 0.1.190 instead of 0.1.185)

Resolution

The resolution is set to 800x600 by default. To change it, hit Esc at the immediately after starting the VM, while you see the tianocore logo, to get into the OVMF config menu. Choose Device Manager -> OVMF Platform Configuration -> Change Preferred -> Select 1024x768 -> Commit Changes and Exit -> Esc -> Reset. This change will not persist, you have to repeat the same steps after every boot.

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