How to set up the driver

See also: Driver

This document demonstrates how to choose, set up, and manage the drivers behind Multipass. Multipass already has sensible defaults, so this is an optional step.

Contents:

Linux: use libvirt

By default, Multipass on Linux uses the qemu or lxd driver (depending on the architecture). However, if you want more control over your VMs after they are launched, you can also use the experimental libvirt driver. This section demonstrates how.

Install libvirt

To install libvirt, execute:

# use the equivalent for your distribution
$ sudo apt install libvirt-daemon-system

Switch the Multipass driver to libvirt

See also: stop, local.driver

First, allow Multipass to use your local libvirt:

# connect the libvirt interface/plug
$ sudo snap connect multipass:libvirt

Then, to switch the Multipass driver to libvirt, run:

# you'll need to stop all the instances first
$ multipass stop --all

# and tell Multipass to use libvirt
$ multipass set local.driver=libvirt

All your existing instances will be migrated and can be used straight away.

You can still use the multipass client and the tray icon, and any changes you make to the configuration of the instance in libvirt will be persistent. They may not be represented in Multipass commands such as multipass info, though.

Use libvirt to view Multipass instances

You can view instances with libvirt in two ways, using the virsh CLI or the virt-manager GUI.

To use the virsh CLI, launch an instance and then execute virsh list (see man virsh for a command reference):

$ virsh list                             
 Id   Name                   State
--------------------------------------
 1    unaffected-gyrfalcon   running

Alternatively, to use the virt-manager GUI, …

obraz

Switch back to the default driver

See also: stop, local.driver

To switch back to the default qemu driver, execute:

# stop all instances again
$ multipass stop --all

# and switch back to the qemu driver
$ multipass set local.driver=qemu

Here, too, existing instances will be migrated.

This will make you lose any customisations you made to the instance in libvirt.

macOS: use VirtualBox

By default, Multipass on macOS uses the qemu driver. However, an alternative option is to use VirtualBox.

Switch the Multipass driver to VirtualBox (macOS)

See also: stop, local.driver

To switch the Multipass driver to VirtualBox, execute:

$ sudo multipass set local.driver=virtualbox

From now on, all instances started with multipass launch will use VirtualBox behind the scenes.

Use VirtualBox to view Multipass instances

Multipass runs as the root user, so to see the instances in VirtualBox, or through the VBoxManage command, you have to run those as root, too. To see the instances in VirtualBox, execute:

$ sudo VirtualBox

Multipass instances in VirtualBox

And, to list the instances on the command line, execute:

$ sudo VBoxManage list vms
"primary" {395d5300-557d-4640-a43a-48100b10e098}

You can still use the multipass client and the system menu icon, and any changes you make to the configuration of the instances in VirtualBox will be persistent. They may not be represented in Multipass commands such as multipass info , though.

Use VirtualBox to set up port forwarding for a Multipass instance

To expose a service running inside the instance on your host, you can use VirtualBox’s port forwarding feature, for example:

$ sudo VBoxManage controlvm "primary" natpf1 "myservice,tcp,,8080,,8081"

You can then open, say, http://localhost:8081/, and the service running inside the instance on port 8080 will be exposed.

Use VirtualBox to set up network bridging for a Multipass instance

An often requested Multipass feature is network bridging. You can add a second network interface to the instance and expose it on your physical network.

First, stop the instance:

$ multipass stop primary

Now, find the network interface you want to bridge with (you want the identifier before the second colon):

$ VBoxManage list bridgedifs | grep ^Name:
Name:            en0: Ethernet
Name:            en1: Wi-Fi (AirPort)
Name:            en2: Thunderbolt 1
Name:            en3: Thunderbolt 2
...

Finally, tell VirtualBox to use it as the “parent” for the second interface (see more info on bridging in VirtualBox documentation on the topic):

# Do not touch --nic1 as that's in use by Multipass
$ sudo VBoxManage modifyvm primary --nic2 bridged --bridgeadapter2 en0

You can then start the instance again and find the name of the new interface:

$ multipass start primary
$ multipass exec primary ip link | grep DOWN
3: enp0s8:  mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000

And configure that new interface — Ubuntu uses netplan for that:

$ multipass exec -- primary sudo bash -c "cat > /etc/netplan/60-bridge.yaml" <<EOF
network:
  ethernets:
    enp0s8:                  # this is the interface name from above
      dhcp4: true
      dhcp4-overrides:       # this is needed so the default gateway
        route-metric: 200    # remains with the first interface
  version: 2
EOF
$ multipass exec primary sudo netplan apply

Finally, find the IP of the instance given by your router:

$ multipass exec primary ip address show dev enp0s8 up       
3: enp0s8:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:2a:5f:55 brd ff:ff:ff:ff:ff:ff
    inet 10.2.0.39/24 brd 10.2.0.255 scope global dynamic enp0s8
       valid_lft 86119sec preferred_lft 86119sec
    inet6 fe80::a00:27ff:fe2a:5f55/64 scope link 
       valid_lft forever preferred_lft forever

All the services running inside the instance should now be available on your physical network under http://<the ip>/.

Switch back to the default driver

See also: stop, local.driver

If you want to switch back to the default driver, run:

$ sudo multipass set local.driver=qemu

Instances created with VirtualBox don’t get transferred, but you can always come back to them.

Windows: use VirtualBox

By default, Multipass on Windows uses the hyperv driver. However, if you want to (or have to), you can change the hypervisor that Multipass uses to VirtualBox.

Install VirtualBox

To that end, install VirtualBox, if you haven’t yet. You may find that you need to run the VirtualBox installer as administrator.

Switch the Multipass driver to VirtualBox

See also: stop, local.driver

You can then tell Multipass to use it (also with Administrator privileges):

PS> multipass set local.driver=virtualbox

From then on, all instances started with multipass launch will use VirtualBox behind the scenes.

Use VirtualBox to view Multipass instances

Multipass runs as the System account, so to see the instances in VirtualBox, or through the VBoxManage command, you have to run those as that user via PsExec -s. Download and unpack PSTools.zip in your Downloads folder, and in an administrative PowerShell, run:

PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s -i $env:VBOX_MSI_INSTALL_PATH\VirtualBox.exe

Multipass instances in VirtualBox

To list the instances on the command line:

PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe list vms
"primary" {05a04fa0-8caf-4c35-9d21-ceddfe031e6f}

You can still use the multipass client and the system menu icon, and any changes you make to the configuration of the instances in VirtualBox will be persistent. They may not be represented in Multipass commands such as multipass info , though.

Use VirtualBox to set up port forwarding for a Multipass instance

To expose a service running inside the instance on your host, you can use VirtualBox’s port forwarding feature, for example:

PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe controlvm "primary" natpf1 "myservice,tcp,,8080,,8081"

You can then open, say, http://localhost:8081/, and the service running inside the instance on port 8080 will be exposed.

Switch back to the default driver

See also: stop, local.driver

If you want to switch back to the default driver:

PS> multipass set local.driver=hyperv

Instances created with VirtualBox don’t get transferred, but you can always come back to them.

1 Like