How to improve mounts performance in Multipass

See also: How to share data with an instance, multipass mount command, Mount

Since the initial writing of this document, Multipass has added support for native mounts which offer much higher performance than the classic sshfs mounts. Before attempting to set up any of the mounts described in this document, first try out native mounts to see if they fit your specific use case. See the multipass mount command to see how to define a native mount.

Multipass uses SSHFS by default for mounting host folders on instances. While it provides good compromise between performance, security and features, other methods can be used to manually accomplish this task.

We conducted thorough tests on many mount methods. Here, we briefly show how to create shares on each system and how to mount them in Multipass instances with the most performant methods we found.

Contents:

SMB/CIFS mounts

In our tests, SMB was very performant in all the architectures supported by Multipass. Windows and MacOS provide a system SMB server, while in Linux it can be easily installed (newer versions of the kernel provide a system server, but we describe here a solution which works for older Linux versions too).

Share a folder with SMB

In Windows

Native mounts on Windows already use SMB/CIFS. See the multipass mount command to see how to define a native mount.

First, optionally and to increase speed, we can enable RDMA on the SMB server built into Windows. In the control panel, we can find the Turn Windows Features on or off icon. On that window, we need to enable SMB Direct. Windows may require a restart.

Then, to share a folder we can use PowerShell. Issuing the command

New-SmbShare -Name "share_name" -Path "C:\my_path"

will create a share named \\hostname\share_name in the host. The command New-SmbShare has multiple options to control access and encryption, but these are not the topic of this document.

In MacOS

This can be entirely done using the GUI, but some steps can easily be done from the command-line. We’ll show the latter when possible.

To enable sharing system wide, we need these commands:

$ sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist EnabledServices -array disk
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist

Then, for sharing a specific folder:

$ sudo sharing -a /my_path/

Finally, we need to allow the user to access the shared folders via SMB. For this, we need to navigate the System Preferences, and find there the Sharing icon. In the Sharing menu, there is a button labeled Options. This button shows us a window, on which we can choose which users will be able to mount. There, we choose and enter the passwords of the users we want to authorize.

All these steps will create a mount point named //hostname/my_path/ in the host.

In Linux

In Ubuntu (or any other Debian-based distribution), the package samba-common contains a SMB server. We can install it with the command

$ sudo apt update && sudo apt install -y samba-common

Then, editing the file /etc/samba/smb.conf lets us add shares, adding entries like the following:

[test_smb_mount]
  comment = smb mount test
  path = /my_path/
  read only = no
  browsable = yes
  kernel oplocks = yes

Mount a folder shared with SMB on an instance

Once the host operating system is sharing the folder, we need to mount it on the instance. For this, the package cifs-tools is needed, which can be installed with

$ sudo apt update && sudo apt install -y cifs-utils

Mounting is finally done in the command line by

$ sudo mount -t cifs //hostname/my_path_or_share_name mount_folder/ -o user=my_name,uid=1000

Where my_name is the user sharing the folder on the host. The password will be asked in the terminal and after entering it, we are done.

Optionally, we can add a line to /etc/fstab to make the operating system automatically mount the folder at boot, or at least not having the need to specify the mount name and options. The line should read:

//hostname/my_path_or_share_name mount_folder/ cifs user=my_name,uid=1000 0 0

Entries in this file are space or tab separated. The first one is the share name or path, the second one is the directory where to mount the folder, the third one is the mount type, the fourth one is the comma-separated list of options (add noauto to avoid mounting at boot) and the two last options better remain as zero.

In case noauto is specified in the options, the folder should be mounted with

$ sudo mount mount_folder/

virtio-fs mounts

If using the LXD backend on Linux, we can benefit from a performant file system mount, at the expense of not being able to mount it while the instance is running. A folder is mounted on an instance with the command

$ lxc --project multipass config device add lxdinstance mount_lxd disk source=/my_path path=//mount_folder

where lxdinstance is the name of the instance, mount_lxd is an arbitrary device name for the mount, source specifies the path to share and path specifies the directory where the source is to be mounted. With only this command, LXD takes care of everything: no need to run commands on the instance.

NFS mounts

Linux and MacOS provide a NFS server on the system.

Share a folder with NFS

In MacOS

The NFS server included in MacOS is controlled with the nfsd command and the file /etc/exports. We need to add the folder we want to share to this file, with a line similar to

/my_path -mapall=host_user -network 192.168.0.0 -mask=255.255.0.0

where -network and -mask control the network from which the share can be accessed. Then, we start the server with the command

$ sudo nfsd start

(or restart if the server is already running).

In Linux

In Ubuntu (or any other Debian-based distribution), the package nfs-kernel-server contains the files to use the NFS server included in the kernel. We can install it with the command

$ sudo apt update && sudo apt install -y nfs-kernel-server

To share a folder, we use the following command:

$ sudo exportfs *:/my_path

where the * means “export to any host”; we can specify a host name or IP address there.

Mount a folder shared with NFS on an instance

We would first need to install the NFS client in the instance, with the commands

$ sudo apt update && sudo apt install -y nfs-common

then, we can mount the shared folder with

$ sudo mount -t nfs HOST_IP:/my_path /mount_folder -o user=host_user,uid=instance_uid,gid=instance_gid
1 Like

To connect to a share on a Windows host requires a slightly different syntax:

sudo mount -t cifs //hostname/my_path_or_share_name mount_folder/ -o username=my_name
Where ‘my_name’ = the Windows user (exactly how the Windows user’s User folder is spelled in C:\Users)

Given all of the underscores in the share path, I also missed seeing the space between ‘…share_name’ and ‘mount_folder’ several times. It may be worth modifying the example(s) to rename the share_name, or to use a full path for the mount target, or to do both.

Tested on a Multipass default vm on a Windows host, with a SMB share on the same Windows host.

1 Like