Skip to content

Commit 8bce804

Browse files
mrexodiaosy
authored andcommitted
Clarify the instruction on setting up VirtFS
1 parent cfe91ee commit 8bce804

File tree

1 file changed

+44
-12
lines changed

1 file changed

+44
-12
lines changed

guest-support/linux.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,69 @@ $ sudo pacman -S phodav
9595
## VirtFS
9696
VirtFS enables [QEMU directory sharing]({% link settings-qemu/sharing.md %}#virtfs) as an alternative to SPICE WebDAV.
9797

98-
After making sure your Linux installation [supports 9pfs](#drivers), you can mount the share with the following command:
98+
After making sure your Linux installation [supports 9pfs](#drivers), you can automatically mount the share by adding the following entry to your `/etc/fstab`:
9999

100100
```
101-
$ sudo mkdir [mount point]
102-
$ sudo mount -t 9p -o trans=virtio share [mount point] -oversion=9p2000.L
101+
# UTM Shared Folder
102+
share /mnt/utm 9p trans=virtio,version=9p2000.L,rw,_netdev,nofail,auto 0 0
103103
```
104104

105-
Where `[mount point]` is the desired destination path. For example: `/media/share`.
105+
_Note_: `share` is the name UTM uses for the VirtIO device and you should not change it. You can replace `/mnt/utm` with a different folder if you like.
106106

107-
You can also modify `/etc/fstab` and add the following line to automatically mount the share on startup:
107+
After updating `/etc/fstab` you need to create an empty folder for the mount:
108108

109+
```sh
110+
sudo mkdir /mnt/utm
109111
```
110-
share [mount point] 9p trans=virtio,version=9p2000.L,rw,_netdev,nofail 0 0
112+
113+
You can apply the changes to `/etc/fstab` with the following commands (this will automatically happen on reboot as well):
114+
115+
```sh
116+
systemctl daemon-reload
117+
systemctl restart network-fs.target
118+
systemctl list-units --type=mount
111119
```
112120

121+
A systemd `.mount` unit for `/mnt/utm` should now be displayed in the list, and you can access the contents of your shared folder.
122+
113123
### Fixing permission errors
114-
You may notice that accessing the mount point fails with "access denied" unless you're the root user. This is because by default the directory inherits the UID/GID from macOS/iOS which has a different numbering scheme. You can fix the error with the following command:
124+
You may notice that accessing the mount point fails with "access denied" unless you're the root user. This is because by default the directory inherits the UID/GID from macOS/iOS which has a different numbering scheme.
125+
126+
To fix this we are going to use [`bindfs`](https://bindfs.org/) to create a mount in the user's home directory that we can access normally. You have to first install `bindfs` with your system's package manager.
127+
128+
The first step is to get the UID and GID used by the host:
115129

116130
```
117-
$ sudo chown -R $USER [mount point]
131+
$ ls -na /mnt/utm
132+
total 8
133+
drwxr-xr-x 4 502 20 128 Feb 22 15:52 .
134+
drwxr-xr-x 3 0 0 4096 Feb 22 14:50 ..
135+
-rw-r--r-- 1 502 20 13 Feb 22 15:52 shared-file.txt
118136
```
119137

120-
This will not change the permissions on your host system but will store the guest ownership in a file attribute.
138+
In this case the UID for the host is `502` and the GID is `20`. You have to do the same for the guest user (usually UID `1000` and GID `1000`). Additionally, create an empty folder for the `bindfs` mount in the home directory:
121139

122-
Alternatively, you can install `bindfs` and use the following `/etc/fstab` instead:
140+
```sh
141+
mkdir /home/user/utm
142+
```
143+
144+
_Note_: In this example the username is `user`, you might have to adjust this to match your configuration.
145+
146+
Now add another entry to `/etc/fstab`:
147+
148+
```
149+
# bindfs mount to remap UID/GID
150+
/mnt/utm /home/user/utm fuse.bindfs map=502/1000:@20/@1000,x-systemd.requires=/mnt/utm,_netdev,nofail,auto 0 0
151+
```
152+
153+
An alternative solution is to recursively change the permissions of the files in your shared folder:
123154

124155
```
125-
share /mnt/macos 9p trans=virtio,version=9p2000.L,rw,_netdev,nofail 0 0
126-
/mnt/macos [mount point] fuse.bindfs map=501/1000:@20/@1000,x-systemd.requires=/mnt/macos 0 0
156+
$ sudo chown -R $USER /mnt/utm
127157
```
128158

159+
_Note_: This will not change the permissions on your host system, but it will add a custom `user.virtfs` file attributes to every file to store the guest ownership. It is not recommended to do this if you want to share your host's home folder for instance.
160+
129161
## **macOS**{: .label .label-green } VirtioFS
130162
When using Apple Virtualization backend, [directory sharing]({% link settings-apple/sharing.md %}) is enabled through VirtioFS.
131163

0 commit comments

Comments
 (0)