Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HVF QEMU fails on Intel - path to qemu is invalid #59

Open
darkn3rd opened this issue May 10, 2024 · 5 comments
Open

HVF QEMU fails on Intel - path to qemu is invalid #59

darkn3rd opened this issue May 10, 2024 · 5 comments

Comments

@darkn3rd
Copy link

darkn3rd commented May 10, 2024

I wanted to try out this plugin on an Macbook (Intel), but it seems to crash/burn. There should be some intelligent defaults to use hvf on either Macbook M-series or Macbook (Intel).

For Homebrew environments, the HOMEBREW_PREFIX env var should be used.

Also, the environment should be detected, as MacPorts can also easily support qemu with sudo port install qemu (ref) and uses different installation paths.

Steps

## Install
brew install qemu
brew tap hashicorp/tap
brew install hashicorp/tap/hashicorp-vagrant
vagrant plugin install vagrant-qemu

cat << EOF > Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2204"
  config.vm.provider "qemu" do |qe|
    qe.ssh_port = "50022" # change ssh port as needed
  end
end
EOF

vagrant up --provider=qemu

Expected Results

I expected that the system would come up, as the generic/ubuntu2204 image supports QEMU.

Actual Results

Something has hardwired the Homebrew path for ARM64 binaries of /opt/homebrew/, and not the Intel_x86_64 binaries, which is /usr/local. These can be resolved by using the $HOMEBREW_PREFIX.

Invalid config.

Error: Invalid qemu dir: /opt/homebrew/share/qemu

Other

  • Also, on Intel Macbook, the arch is hardwired to use qemu-system-aarch64 binary and uses invalid machines.
  • Default machine type fails, as virt is not supported on intel. hvf acceleration is supported.
  • Default network fails: Stderr: qemu-system-x86_64: -device virtio-net-device,netdev=net0: No 'virtio-bus' bus found for device 'virtio-net-device'

I was able to get around some of this but inserting these defaults:

Vagrant.configure("2") do |config|
  config.vm.box = "generic/ubuntu2204"
  config.vm.provider "qemu" do |qe|
    qe.ssh_port = "50022" # change ssh port as needed
    qe.qemu_dir = "/usr/local/share/qemu"
    qe.arch = "x86_64"
    qe.machine = "q35,accel=hvf"
    qe.net_device = "virtio-net-pci"
  end
end
@ppggff
Copy link
Owner

ppggff commented May 11, 2024

Please try the x86_64 example in the Readme.

@darkn3rd
Copy link
Author

darkn3rd commented May 11, 2024

For clarification, you are talking about Example 6? Example 4? or both? The docs are not clear if either of these examples are for running this on Macbook M-series (ARM64) or Macbook (Intel) host. Both of these examples do not have hvf acceleration enabled, which is supported and works with QEMU on Macbook (Intel).

Additionally, I doubt that example 4 will work on Intel (trying it out now). The default settings do not work on Intel Macs. There should be intelligent defaults without the need for overrides.

@darkn3rd
Copy link
Author

darkn3rd commented May 12, 2024

Example 4 Test: FAILS as documented

  1. Docs unclear or ambiguous if this is an Intel example for Macs on Apple Silicon, Macs on Intel, or both.
  2. centos/7 does not have qemu listed as a supported provider, so vagrant up --provider=qemu uses libvirt provider.
  3. This test failed, but the plugin defaults the wrong path to qemu binary. I expected that (1) homebrew environment would be detected, (2) given homebrew environment search for HOMEBREW_PREFIX env var, (3) if HOMEBREW_PREFIX env var not found select path based on current arch, /usr/local/share/qemu for Mac Intel host, /opt/homebrew/share/qemu for Mac on Apple Silicon host.

Steps

cat << EOF > Vagrantfile 
# Example 4 form docs
Vagrant.configure(2) do |config|
  config.vm.box = "centos/7"

  config.vm.provider "qemu" do |qe|
    qe.arch = "x86_64"
    qe.machine = "q35"
    qe.cpu = "qemu64"
    qe.net_device = "virtio-net-pci"
  end
end
EOF  

vagrant up --provider=qemu

Actual Results

Example 4 as documented does fails on Intel Macs.

Invalid config.

Error: Invalid qemu dir: /opt/homebrew/share/qemu

Example 6 Test: Passes, but ambiguity as to host

  1. Ambiguity between this example is for Apple Silicon host, Intel and Apple Silicon, or both. If one is familiar, they can tell that this is for Intel given the qe.qemu_dir override, but then with TCG accelerator used, it looks like this is for Apple Silicon.
  2. Strange that the TCG accelerator is used for a Mac Intel example, as QEMU natively supports HVF on Mac Intel. One doesn't need to translate Intel to Intel.

Ultimately with similar steps above, this passes. I wouldn't recommend using this, even for intelligent defaults on an Mac Intel host, as HVF should grant the highest performance under Intel.

@darkn3rd
Copy link
Author

TL;DR summary is that there should be an intelligent default solution path for macOS (Intel) to use HVF.

For the examples, separate from this issue, there should be clarity as to the host the example is appropriate for. Right it is vague and ambiguous, especially for those new to QEMU. As a suggestion, perhaps have examples that or organized per host. There may be some redundancy. Or if that is not welcomed, maybe having some text to show the type of host.

@ppggff
Copy link
Owner

ppggff commented May 20, 2024

Thanks, I will try to make it more intelligent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants