Introduction
In this article, we'll discuss how to set up an NFS server on a QEMU virtual machine (VM) using Vagrant on a macOS Monterey host. Specifically, we will use two base boxes: Alpine Linux and Ubuntu 22.04 LTS. By the end of this guide, you will have a solid understanding of the following key concepts:
- Installing QEMU on macOS Monterey
- Configuring Vagrant to work with QEMU
- Setting up an NFS server within a QEMU VM
- Sharing folders between the host and the guest using NFS
Prerequisites
Ensure you have the following installed and configured:
- QEMU
- Vagrant
- Xcode (for macOS Monterey) and vmware-tools or virtualbox-guest-utils-darwin to enable shared folders in QEMU on macOS Monterey
Installing QEMU on macOS Monterey
Use Homebrew to install the latest version of QEMU:
brew install qemu
Configuring Vagrant to Work with QEMU
Create a Vagrantfile and set up the VM:
Vagrant.configure("2") do |config|
config.vm.define "vm1" do |vm1|
vm1.box = "alpine/3.15"
vm1.network "private_network", ip: "172.28.128.21"
vm1.provider "virtualbox" do |v|
v.memory = "2048"
v.cpus = "2"
end
Setting Up an NFS Server within a QEMU VM
SSH into the VM:
vagrant ssh vm1
Update the package list and install the NFS server:
apk update && apk add nfs-server
Configure the NFS server:
vim /etc/exports
Add the following lines, replacing /path/to/share with the actual folder you want to share:
/path/to/share *(rw,sync,no_subtree_check,no_root_squash)
Start the NFS server:
rc-service nfs start
Sharing Folders Between the Host and the Guest Using NFS
Create a sharing configuration in the Vagrantfile:
config.vm.provision "file", source: "/path/to/share", destination: "/path/to/share"
config.vm.provision "shell", inline: <<-SHELL
mount -t nfs -o rw,sync,no_subtree_check,no_root_squash 172.28.128.21:/path/to/share /path
SHELL