This article provides a comprehensive guide on how to share a directory between a Mac host and a QEMU or UTM virtual machine. We will go through the key concepts, subtitles, and paragraphs, while covering the necessary steps to achieve this task. Note that this article assumes you have already installed QEMU or UTM on your Mac side and created a virtual machine.
Prerequisites
Ensure you have the following installed and configured:
- QEMU or UTM on your Mac
- A virtual machine created with QEMU or UTM
Introduction to QEMU and UTM Virtual Machine Sharing
QEMU and UTM support various methods for sharing directories between a host and a guest machine. The most common approaches are:
- 9p filesystem (also known as "9pfs" or "Virtual Ninja File System")
- SMB/CIFS (Server Message Block/Common Internet File System) using Samba
9p filesystem Implementation in Mac
Unfortunately, there is no native support for the 9p filesystem on the Mac side. However, you can use a third-party tool such as 9mount to enable 9p filesystem functionality on macOS. Here's how to do it:
Installing 9mount on Mac:
First, you'll need to install Homebrew, if you haven't already:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Next, install 9mount using Homebrew:
$ brew install 9mount
Setting Up a Shared Directory using 9p:
After successfully installing 9mount, you can proceed with setting up a shared directory:
-
Create a directory on the Mac side:
-
Inside the QEMU or UTM configuration file, add the following line to share the directory:
-
On the virtual machine side, run:
$ mkdir -p /path/to/shared/directory
<extra-args> -drive if=none,file=/path/to/shared/directory,id=share0 <extra-args> -device virtio-9p-device,drive=share0,bus=ahci.0,fsdev=fd0,mount\_tag=host\_share
$ sudo 9mount -t 9p host\_share /path/to/shared/directory/in/vm
Unmounting the Shared Directory on macOS
To unmount the shared directory, run the following command:
$ sudo 9unmount /path/to/shared/directory
SMB/CIFS Sharing Using Samba
On macOS, you can also use SMB/CIFS to share a directory with the virtual machine using Samba. Here's how:
Installing Samba on Mac:
First, install Homebrew, if you haven't already, and then install Samba:
$ brew install samba
Setting Up a SMB Share for the Virtual Machine
After installing Samba, you can proceed with setting up a shared directory:
-
Create a directory on the Mac side:
-
Create a Samba configuration file:
-
Create a Samba user:
$ mkdir -p /path/to/smb/shared/directory
$ sudo nano /etc/smb.conf
Add the following to the configuration file, replacing the placeholders:
[global]
workgroup = WORKGROUP
security = user
map to guest = never
[share]
comment = SMB Share for QEMU/UTM
path = /path/to/smb/shared/directory
browseable = yes
writeable = yes
create mask = 0777
directory mask = 0777
public = yes
$ sudo smbpasswd -a
```