ppggff / vagrant-qemu

Use Vagrant to manage machines using QEMU. Test with Apple Silicon / M1 and CentOS aarch64 image
MIT License
431 stars 35 forks source link

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

Open darkn3rd opened 6 months ago

darkn3rd commented 6 months ago

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

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 commented 6 months ago

Please try the x86_64 example in the Readme.

darkn3rd commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

Thanks, I will try to make it more intelligent.