Skip to content

Instantly share code, notes, and snippets.

@marccarre
Last active October 26, 2023 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marccarre/60fee57029ba627dbeee027f63f102b1 to your computer and use it in GitHub Desktop.
Save marccarre/60fee57029ba627dbeee027f63f102b1 to your computer and use it in GitHub Desktop.
Vagrant on Apple M1

Vagrant on Apple M1

Summary:

  • QEMU: ✅ (but few boxes)
  • libvirt: ❎ (suggestions welcome!)
  • Parallels: ✅ (but few boxes)
  • VMWare Fusion: ✅ (but few boxes)
  • VirtualBox: ❎ (timeout)

QEMU

brew install hashicorp/tap/hashicorp-vagrant
brew install qemu
vagrant plugin install vagrant-qemu
vagrant init perk/debian-11-genericcloud-arm64
vagrant up --provider qemu
vagrant ssh

Unfortunately, there are very few QEMU ARM64 boxes at this time.

See also:

libvirt

brew install hashicorp/tap/hashicorp-vagrant
brew install libiconv gcc qemu libvirt
brew install iproute2mac  # The libvirt Vagrant plugin expects the ip command. This packages provides a similar API. See also: https://superuser.com/a/898971

Attempt #1

The following command failed:

$ vagrant plugin install vagrant-libvirt
[...]
Vagrant failed to install the requested plugin because development tools
are required for installation but are not currently installed on this
machine. Please install development tools and then try this command
again.
[...]

Attempt #2

The following command failed:

$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 \
    CONFIGURE_ARGS="with-libvirt-include=$(brew --prefix libvirt) with-libvirt-lib=$(brew --prefix libvirt)" \
    vagrant plugin install --verbose --debug vagrant-libvirt
[...]
Vagrant failed to install the requested plugin because development tools
are required for installation but are not currently installed on this
machine. Please install development tools and then try this command
again.
[...]

Attempt #3

The following steps are inspired from: vagrant-libvirt/vagrant-libvirt#1205 (comment)

$ brew install grpc  # ... as bundle initially failed as it required some gRPC libraries
$ ruby --version
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin21]
$ git clone git@github.com:hashicorp/vagrant.git  # HEAD: f33ac0bc98bd
$ cd vagrant
$ git apply <<EOF
diff --git a/vagrant.gemspec b/vagrant.gemspec
index 80b54bacc..7ef7a32c0 100644
--- a/vagrant.gemspec
+++ b/vagrant.gemspec
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
   s.add_dependency "ed25519", "~> 1.3.0"
   s.add_dependency "erubi"
   s.add_dependency 'googleapis-common-protos-types', '~> 1.3'
-  s.add_dependency "grpc", "~> 1.56.0"
+  s.add_dependency "grpc", "~> 1.59.0"
   s.add_dependency "hashicorp-checkpoint", "~> 0.1.5"
   s.add_dependency "i18n", "~> 1.12"
   s.add_dependency "listen", "~> 3.7"
EOF
$ bundle config set --local deployment 'true'
$ bundle install
$ CONFIGURE_ARGS="with-libvirt-lib=$(brew --prefix libvirt)/lib with-libvirt-include=$(brew --prefix libvirt)/include" bundle exec vagrant plugin install vagrant-libvirt
$ bundle --binstubs exec
$ ls -al $(which vagrant)
lrwxr-xr-x  1 root  admin  24 Oct 20 04:06 /usr/local/bin/vagrant -> /opt/vagrant/bin/vagrant
$ sudo ln -sf "${PWD}/exec/vagrant" /usr/local/bin/vagrant

Edit $(brew --prefix)/etc/libvirt/libvirtd.conf and uncomment:

unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"
unix_sock_admin_perms = "0700"
unix_sock_dir = "/opt/homebrew/var/run/libvirt"

But... the next step failed:

brew services start libvirt
brew install virt-manager
virt-manager -c "qemu:///session?socket=/opt/homebrew/var/run/libvirt/libvirt-sock" --no-fork
vagrant init debian/bullseye64

Edit Vagrantfile to point to the above socket. The configuration should look like this:

Vagrant.configure("2") do |config|
  config.vm.box = "debian/bullseye64"
  config.vm.provider :libvirt do |libvirt|
    libvirt.uri = "qemu:///session"
    libvirt.socket = "/opt/homebrew/var/run/libvirt/libvirt-sock"
  end
end

Run:

vagrant up --provider=libvirt

In my case, the above failed with:

missing interpolation argument :error_message in "Error while connecting to Libvirt: %{error_message}" ({:_key=>:fog_libvirt_connection_error, :_namespace=>"vagrant_libvirt.errors"} given) (I18n::MissingInterpolationArgument)

on these lines: https://github.com/vagrant-libvirt/vagrant-libvirt/blob/448ed69f0ccbe8557157644a0ebd8809b35d5b71/lib/vagrant-libvirt/driver.rb#L221-L231

N.B.: given that there are no libvirt ARM64 boxes available (see here) it is unclear if this solution would have worked anyway.

See also:

Clean up

sudo ln -sf /opt/vagrant/bin/vagrant /usr/local/bin/vagrant
brew services stop libvirt

vagrant plugin repair
vagrant plugin expunge --reinstall
vagrant plugin update

Parallels

brew install hashicorp/tap/hashicorp-vagrant
vagrant plugin install vagrant-parallels
vagrant plugin update vagrant-parallels
vagrant init "${PARALLELS_ARM64_BOX}"
vagrant up --provider=parallels
vagrant ssh

Unfortunately, there are very few Parallels ARM64 boxes at this time. But the above worked with:

export PARALLELS_ARM64_BOX=luminositylabsllc/bento-ubuntu-22.04-arm64

See also:

VMWare Fusion

brew install hashicorp/tap/hashicorp-vagrant
brew install --cask vagrant-vmware-utility
vagrant plugin install vagrant-vmware-desktop
vagrant plugin update vagrant-vmware-desktop
vagrant init gyptazy/debian11.8-arm64 --box-version 1.0.0
vagrant up --provider=vmware_desktop
# OR:
# vagrant up --provider=vmware_fusion

# You may get the following error:
#   The following SSH command responded with a non-zero exit status.
#   Vagrant assumes that this means the command failed!
# Ignore it, and run:

vagrant ssh

Unfortunately, there are very few VMware ARM64 boxes at this time. See also:

VirtualBox

brew install hashicorp/tap/hashicorp-vagrant
vagrant init debian/bullseye64
vagrant up --provider virtualbox

This did NOT succeed and timed out on VM creation.

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