How to build VM on Apple M1/M2 chip Mac with VMware Fusion & Vagrant?

Apple launched the M1/M2 chip for Macs and iPads, bringing numerous features and benefits. However, as a developer, creating VMs using familiar desktop hypervisors like VirtualBox wasn't straightforward. I patiently waited for about a year for community support. Thankfully, a solution has emerged. Let's delve into it.
VMware Fusion Player
We create VMs using software called Hypervisor. There are two types: bare metal hypervisors (for cloud/on-premise) and desktop hypervisors (for personal computers). Desktop hypervisors work with most operating systems. VMware Fusion is a desktop hypervisor designed for Mac Intel and Apple M1/M2 chip computers, developed by VMware. VMware Fusion is available in two versions: VMware Fusion Pro and VMware Fusion Player. You can explore the significant distinctions between them on their official webpage.
Create VMware Customer Connect Profile
- Visit the VMware Customer Connect registration page and provide accurate details.
- Confirm your email address to ensure proper activation of your profile.
Download VMware Fusion Player
- Navigate to the VMware Fusion Download page.
- Under the Select Version drop-down menu, select the 13.02 version.
- Click Go to Downloads.
- Click Download Now. If prompted, log in to your Customer Connect profile. If you do not have a profile, please create one.
Install VMware Fusion Player
- Open the Finder app and navigate to the Downloads directory.
- Open the VMware Fusion disk image.
- Double-click the VMware Fusion icon and follow the onscreen instructions.
- During the installation process, a license key prompt appears. Within the same window, you'll find a "Get a Free License Key" button. Simply click this button to obtain the Personal Use License key and finalize the installation.
Vagrant
Vagrant is a tool for building and managing virtual machines, developed by HashiCorp. It makes the process of creating VMs easier on various desktop hypervisors like VirtualBox, VMware Workstation, Parallels, Hyper-V, VMware Fusion, and others.
Install Vagrant
- Download the Vagrant 2.3.7 AMD64 disk image.
- Double-click the disk image and follow the onscreen instructions.
- Once Vagrant is installed successfully, confirm by using the following command.
Verify Vagrant
After installing Vagrant, launch a Terminal and execute the provided command.
sudo vagrant --version
Install Vagrant VMware Utility
- Download the Vagrant VMware Utility 1.0.22 AMD64 disk image.
- Double-click the disk image and follow the onscreen instructions.
Install Vagrant VMware Provider Plugin
sudo vagrant plugin install vagrant-vmware-desktop
Let's build a VM
Constructing a VM becomes effortless after successfully installing VMware Fusion Player and Vagrant. Let's proceed with the building process.
Create a Directory and Initialize the Project
To begin, you create a Vagrant environment by creating a Vagrantfile. In this file, you can customize VM settings like its name, CPU count, memory, and more. The Vagrantfile is portable across all platforms supported by Vagrant, such as Mac, Linux, Windows, etc., and it can be stored in version control. Even though it uses Ruby syntax, you don't need advanced programming knowledge.
We are already handling Vagrantfiles within the repository and actively utilizing them.
# Download Linux starter-kit from GitHub to local filesystem path.
$ sudo git clone https://github.com/sloopstash/kickstart-linux.git /opt/kickstart-linux
# Change ownership of Linux starter-kit directory.
$ sudo chown -R $USER /opt/kickstart-linux
# Switch to Linux starter-kit directory.
$ cd /opt/kickstart-linux
Start and Provision VM
After customizing the VM configurations to suit your requirements, execute the following command to initiate the creation of the Guest Machine (VM) based on your Vagrantfile settings. The default username and password for the guest machine are both set as vagrant.
sudo VAGRANT_CWD=./vagrant/ubuntu-22-04/vmware/arm64/server vagrant up
After the VM has started, you can confirm its status by using the following command.
sudo vagrant global-status
SSH to VM
Vagrant set up VM access through SSH. During the initial boot of the VM, Vagrant automatically introduces a key-pair for SSH authentication. You can use the following commands to access the VM shell.
sudo VAGRANT_CWD=./vagrant/ubuntu-22-04/vmware/arm64/server vagrant ssh
Power off VM
The following command ensures a smooth shutdown of the guest machine (VM).
sudo VAGRANT_CWD=./vagrant/ubuntu-22-04/vmware/arm64/server vagrant halt
Delete VM
The following command ensures the removal of the guest machine (VM).
sudo VAGRANT_CWD=./vagrant/ubuntu-22-04/vmware/arm64/server vagrant destroy
I trust this article has been beneficial to you. For any uncertainties, feel free to reach out to the Sloopstash community - we're here to help. Your questions are important to us for fostering a supportive learning environment.