MrZ
MrZ

Reputation: 334

qemu-system-aarch64: -accel hvf: invalid accelerator hvf

I have already compiled QEMU by myself in MacBook pro M1, and downloaded ubuntu 20.04.

When I am trying to install ubuntu by:

DYLD_LIBRARY_PATH=. \
./qemu-system-aarch64 \
-M virt,highmem=off \
-accel hvf \
-m 4G \
-smp 4 \
-cpu max \
-drive file=ubuntu.img,index=0,media=disk,format=raw \
-serial stdio \
-netdev type=user,id=net0 \
-device virtio-gpu-pci -vga none \
-device nec-usb-xhci \
-device usb-kbd \
-device usb-tablet \
-device intel-hda -device hda-duplex \
-device virtio-net-pci,netdev=net0,romfile="" \
-drive file=ubuntu-20.04.2-live-server-arm64.iso,media=cdrom,if=none,id=cdrom -device usb-storage,drive=cdrom \
-bios QEMU_EFI.fd

I got an error: qemu-system-aarch64: -accel hvf: invalid accelerator hvf.

I have tried this: sudo xattr -rd com.apple.quarantine ~/Desktop/buildV6 to close the gatekeeper, but it didn't work.

I don't quite understand this and I am new in QEMU. Could you just give me the solution?

Upvotes: 10

Views: 19879

Answers (5)

MrZ
MrZ

Reputation: 334

Nearly a year later, QEMU released new version with support of macOS aarch64 now(version 7.0.0).

Here is the method to use it:

  1. get QEMU's source code
git clone --single-branch --branch v6.2.0 https://github.com/qemu/qemu.git
  1. compile it
./configure --target-list=aarch64-softmmu --enable-hvf
make -j -1
  1. install it
make install
  1. how to use
qemu-system-aarch64 <your args>

args here is what you can do with qemu, check

qemu-system-aarch64 -h

to see the help message.


update: Now you don't need to compile by yourself, homebrew provide newest version.

Download:

brew install qemu

and you can use them freely.

Upvotes: -1

rgov
rgov

Reputation: 4329

It looks like the feature is supported as of QEMU 6.2.

Upvotes: 1

Bill
Bill

Reputation: 73

I found https://github.com/knazarov/homebrew-qemu-virgl is the simplest solution:

brew install qemu

brew install knazarov/qemu-virgl/qemu-virgl

Upvotes: 0

Vaibhav
Vaibhav

Reputation: 658

The accepted answer does not work anymore because the patch series does not show up when you click the link in that blog post. I had tried going through the same set of instructions. So I went through a lot of material to skim out what was out there. I was using Qemu after about 10 years since I last tried it so it took some time but it looks like someone already had built an app (an actual .app with a UI) which contains the qemu build for M1 that contains the hvf accelerator/hypervisor support.

I have written a detailed blog post about it here (in case the instructions are unclear or if you want to see the pictures).

Before you go in for the long haul, do take a look at the UTM App. It is free and open-source and I have used this app to successfully run my Ubuntu (ARM) image on Mac. There are features missing compared to VirtualBox and others, but as of now, this is the easiest it can get to running Ubuntu on your mac.

Now, the steps for long (manual) method:

Get the ACVM App

You can download it from here. You can try compiling it or just get the released version from releases.

Download the Ubuntu image

Download the Ubuntu for ARM image from Ubuntu's website. You can download a daily-live image from here or you can get the ARM server image from here and install the GUI later. I suggest you get the stable image and install the GUI later but current build served me just fine.

Create Target Disk

Create a target disk where your VM will live. If you moved the ACVM app into /Applications, then run the following commands:

cd /Applications/ACVM.app/Contents/Resources
mkdir $HOME/UbuntuVM
./qemu-img create -f qcow2 $HOME/UbuntuVM/Ubuntu.qcow2 40G

You can change the size of the target disk to what you want but 40 G should be fine.

Start the ACVM app

Start the ACVM app and drop your ISO file in the CD image area and qcow image you just created in the Main image section and click on start. There is also qemu command that you can use.

You should see Ubuntu booting up. Proceed with installation!

Start the installed Ubuntu

Ensure you are still in /Applications/ACVM.app/Contents/Resources and run:

./qemu-system-aarch64 \
  -serial stdio \
  -M virt,highmem=off \
  -accel hvf \
  -cpu cortex-a72 \
  -smp 4,cores=4 \
  -m 4096 \
  -bios "/Applications/ACVM.app/Contents/Resources/QEMU_EFI.fd" \
  -device virtio-gpu-pci \
  -display default,show-cursor=on \
  -device qemu-xhci \
  -device usb-kbd \
  -device usb-tablet \
  -device intel-hda \
  -device hda-duplex \
  -drive file="$HOME/UbuntuVM/Ubuntu.qcow2",if=virtio,cache=writethrough

You should get the Ubuntu (ARM architecture) VM running on your Mac M1 machine.

NOTE: You can also try to run the machine using the ACVM app again (just drop in the main image, leave the CD image one empty and press start). But when I did that, I would always face some kind of issues, mostly my screen would stay black for a very long time.

These steps should work for all macOS machines with the M1 chip (MacBook Air, MacBook Pro, Mac Mini and the upcoming iMacs).

Upvotes: 1

Peter Maydell
Peter Maydell

Reputation: 11383

The error message 'invalid accelerator hvf' means that your QEMU binary does not have 'hvf' support built into it. (You can check by running "qemu-system-aarch64 -accel help".)

So either you didn't build the right QEMU version (it will need to be a fork with the M1 support, because current upstream QEMU only supports hvf for the x86 architecture), or you were missing some dependency that meant configure disabled support. You can rule out the "missing dependency" possibility by building with the configure "--enable-hvf" argument -- that will force configure to either build with hvf support or produce an error if it can't.

The tutorials that David links to will probably be useful.

Upvotes: 1

Related Questions