Running Vagrant on MacOS Apple M1


Very often in development there is a need to raise a local environment to debug any working moments. In my work, I constantly use Vagrant for testing infrastructure code, for example ansible-roles. Vagrant remains one of the most popular utilities for such tasks, has a flexible syntax and support for basic algorithmic structures – you can raise N and K machines in a loop using predefined variables, and then also ansible inventory generate output by splitting machines into groups.

Figure 1. Vagrant configuration for looping creation of virtual machines
Figure 1. Vagrant configuration for looping creation of virtual machines

For a long time I remained a MacBook user on an Intel processor, but this could not continue anymore – I had to change my computer, although I knew about some of the features of the M1 with virtual machines.

In this article, I’ll show you how to set up and run Vagrant on processors Apple M1/M2 and return to normal operating mode.

Working installation

Figure 2. Working installation of Vagrant on Apple M1/M2
Figure 2. Working installation of Vagrant on Apple M1/M2
  1. Rosetta 2: allows Mac computers with Apple processors to use applications created for Mac computers with Intel processors.

  2. Vagrant (2.3.0+): software for creating and configuring a virtual development environment. It is a wrapper for virtualization software such as VirtualBox and configuration management tools such as Chef, Salt, and Puppet.

  3. Vagrant-vmware-desktop (3.0.1+): A plugin that allows a vagrant to control VMware-based machines, providing better stability and performance than VMware software.

  4. Vagrant vmware utility (1.0.21+): A service that gives vagrant-vmware-desktop e access to various VMware features. It is also used to perform operations that require privileged access on the host, network operations, and machine verification.

  5. Hypervisor (VMware Fusion Public Tech Preview 22H2): Virtual Machine Hypervisor


Installation

1 Rosetta

First of all, you need to install Rosetta 2, to do this, run the following command:

/usr/sbin/softwareupdate --install-rosetta --agree-to-license

2. Vagrant

Next, you need to install Vagrant itself. This can be done by downloading it from the official site. https://www.vagrantup.com/downloads – by selecting MacOS and installing dmg, or via brewby running the command:

brew install vagrant

You can also check that Vagrant is running from the console:

vagrant -v                                                                                                                                                                 ✔
vagrant global-status
Figure 3 Sample output from a freshly installed Vagrant
Figure 3 Sample output from a freshly installed Vagrant

3. Hypervisor

Here the first jokes begin, but first things first. We can’t just take and download from the VMWare website. But we can see the current version. Let’s go to the site https://customerconnect.vmware.com/downloads/get-download?downloadGroup=FUS-PUBTP-22H2there we find and write down the numbers:

Figure 4. Remembering the current version of VMware Fusion Technology Preview II 22H2
Figure 4. Remembering the current version of VMware Fusion Technology Preview II 22H2

After that, we can download this file from the link, replacing the version with the current one. For example, you can use the command:

wget https://download3.vmware.com/software/FUS-PUBTP-22H2/VMware-Fusion-e.x.p-#{version}_universal.dmg

Alternatively, you can install via brew:

brew install --cask vmware-fusion

But that’s not all. The fact is that “tech preview” is installed in its own path (/Applications/VMWare Fusion Tech Preview.app), and vagrant providers will look for VMWare according to the standard (/Applications/VMWare Fusion.app). To fix this misunderstanding, let’s use the command:

ln -s /Applications/VMWare\ Fusion\ Tech\ Preview.app /Applications/VMWare\ Fusion.app

4. Vagrant vmware utility

Page dedicated to this utility: https://developer.hashicorp.com/vagrant/docs/providers/vmware/vagrant-vmware-utilitybut you can just go to the following link, download and install the latest version https://developer.hashicorp.com/vagrant/downloads/vmware. Alternatively, you can use brew again:

brew install vagrant-vmware-utility

After installation, I recommend checking the utility’s performance, by the way, you can debug it in the same way to understand what doesn’t work (I found out about the mismatch of installation paths):

sudo /opt/vagrant-vmware-desktop/bin/vagrant-vmware-utility api -debug

The output may give an error that port 9922 is already busy. This happens if the utility is already enabled and running. It can be turned off and debugged.

Check if ports are busy:

sudo lsof -i -P | grep LISTEN | grep 'vagrant-v'
Figure 5. Console output if vagrant vmware utility occupies a port
Figure 5. Console output if vagrant vmware utility occupies a port

Download utility:

sudo launchctl unload -w /Library/LaunchDaemons/com.vagrant.vagrant-vmware-utility.plist

Download the utility back:

sudo launchctl load -w /Library/LaunchDaemons/com.vagrant.vagrant-vmware-utility.plist

Also, you can check the functionality of the utility with the command:

sudo launchctl list | grep vagrant
Figure 6. Console output if vagrant vmware utility is successfully launched
Figure 6. Console output if vagrant vmware utility is successfully launched

5. Vagrant VMWare Plugin

To install the plugin, simply run the command:

vagrant plugin install vagrant-vmware-desktop

This completes the installation, it’s time to try to start the virtual machine.

Starting the virtual machine

Next, the most difficult 🙂 In general, all of the above can pass without errors, but the machine still will not start. I have tried many options, combinations and settings vagrantfile and give you the solution that worked for me and my students.

I was able to identify three main problem areas when starting a virtual machine:

  1. Box (virtual machine image) for ARM processors
    Finished images are different providers, for which they are sharpened, processors, and content. There are popular images that did not work for me, there are images with 100 downloads that proved to be successful.
    I settled on the following: spox/ubuntu-arm and bytesguy/ubuntu-server-20.04-arm64

  2. GUI
    For reasons that I have not yet been able to find out (tell me in the comments!) – the virtual machine does not start if the GUI is turned off (and it is turned off by default). In view of this feature, it is necessary to add the parameter vmware.gui = true in Vagrantfile config

  3. Network
    When your car is already practically running, the vagrant can treacherously freeze in step ==> default: Waiting for the VM to receive an address...
    A solution has been found – indicate vmware.vmx["ethernet0.virtualdev"] = “vmxnet3” in Vagrantfile config

We create a directory for the configuration of our future machine and Vagrantfile in it. The final Vagrantfile is as follows:

Vagrant.configure("2") do |config|
  config.vm.box = "spox/ubuntu-arm"
  config.vm.box_version = "1.0.0"
  config.vm.provider :vmware_desktop do |vmware|
    vmware.gui = true
    vmware.cpus = 2
    vmware.vmx["ethernet0.virtualdev"] = "vmxnet3"
    vmware.ssh_info_public = true
    vmware.linked_clone = false
  end
end

We start the machine with the usual command vagrant up:

Figure 7. Successful start of the virtual machine
Figure 7. Successful start of the virtual machine

We connect to a freshly created machine through vagrant ssh:

Figure 8. Successful SSH connection
Figure 8. Successful SSH connection

That’s all, I hope my guide helped you save your nerves and time. I wish you a pleasant use of the laptop and see you soon 🙂 Well, if you are fond of DevOps and system administration, I am waiting for you in my lamp community in telegrams: https://t.me/deusops

Useful sources

  1. https://www.vagrantup.com/intro

  2. https://github.com/hashicorp/vagrant-vmware-desktop

  3. https://www.vagrantup.com/docs/providers/vmware/installation

  4. https://gist.github.com/sbailliez/f22db6434ac84eccb6d3c8833c85ad92

  5. https://github.com/hashicorp/vagrant/issues/12195

  6. https://github.com/hashicorp/vagrant/issues/12050

  7. https://www.youtube.com/watch?v=UZXFMCfXqh8

  8. https://www.vagrantup.com/docs/providers/vmware/configuration

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *