diff --git a/multipass/how-to/how_to_set_up_the_driver.md b/multipass/how-to/how_to_set_up_the_driver.md index f018d33..0483f59 100644 --- a/multipass/how-to/how_to_set_up_the_driver.md +++ b/multipass/how-to/how_to_set_up_the_driver.md @@ -1,11 +1,3 @@ -tmihoc | 2024-07-10 09:07:46 UTC | #1 - - - -> *Errors or typos? Topics missing? Hard to read? Let us know or open an issue on GitHub.* - > See also: [Driver](/t/28410), [`local.driver`](/t/27357) 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. @@ -45,20 +37,20 @@ If you want more control over your VMs after they are launched, you can also use To install libvirt, run the following command (or use the equivalent for your Linux distribution): ```plain -$ sudo apt install libvirt-daemon-system +sudo apt install libvirt-daemon-system ``` -Now you can switch the Multipass driver to libvirt. First, allow Multipass to use your local libvirt by connecting to the libvirt interface/plug: +Now you can switch the Multipass driver to libvirt. First, enable Multipass to use your local libvirt by connecting to the libvirt interface/plug: ```plain -$ sudo snap connect multipass:libvirt +sudo snap connect multipass:libvirt ``` -Then, [stop](/t/23951) all instances and tell Multipass to use libvirt, running the following commands: +Then, stop all instances and tell Multipass to use libvirt, running the following commands: ```plain -$ multipass stop --all -$ multipass set local.driver=libvirt +multipass stop --all +multipass set local.driver=libvirt ``` All your existing instances will be migrated and can be used straight away. @@ -76,7 +68,7 @@ An alternative option is to use VirtualBox. To switch the Multipass driver to VirtualBox, run this command: ```plain -$ sudo multipass set local.driver=virtualbox +sudo multipass set local.driver=virtualbox ``` From now on, all instances started with `multipass launch` will use VirtualBox behind the scenes. @@ -92,7 +84,7 @@ To that end, install VirtualBox, if you haven't yet. You may find that you need To switch the Multipass driver to VirtualBox (also with Administrator privileges), run this command: ```powershell -PS> multipass set local.driver=virtualbox +multipass set local.driver=virtualbox ``` From then on, all instances started with `multipass launch` will use VirtualBox behind the scenes. @@ -109,15 +101,19 @@ From then on, all instances started with `multipass launch` will use VirtualBox You can view instances with libvirt in two ways, using the `virsh` CLI or the [`virt-manager` GUI](https://virt-manager.org/). -To use the `virsh` CLI, launch an instance and then execute `virsh list` (see [`man virsh`](http://manpages.ubuntu.com/manpages/xenial/man1/virsh.1.html) for a command reference): +To use the `virsh` CLI, launch an instance and then run the command `virsh list` (see [`man virsh`](http://manpages.ubuntu.com/manpages/xenial/man1/virsh.1.html) for a command reference): ```plain -$ virsh list +virsh list +``` + +The output will be similar to the following: + +```plain Id Name State -------------------------------------- 1 unaffected-gyrfalcon running ``` - Alternatively, to use the `virt-manager` GUI, ... ![obraz|584x344](upload://bFIxA9CPAqBeWjuQxDaZBYBNsZK.png) @@ -126,18 +122,22 @@ Alternatively, to use the `virt-manager` GUI, ... [tab version="macOS"] -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: +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, use the command: ```plain -$ sudo VirtualBox +sudo VirtualBox ``` ![Multipass instances in VirtualBox](upload://mld2SIalX93tc3StGHaqb6OTyDO.png) -And, to list the instances on the command line, execute: +And, to list the instances on the command line, run: ```plain -$ sudo VBoxManage list vms +sudo VBoxManage list vms +``` + +Sample output: +```plain "primary" {395d5300-557d-4640-a43a-48100b10e098} ``` @@ -152,14 +152,20 @@ You can still use the `multipass` client and the system menu icon, and any chang 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`](https://docs.microsoft.com/en-us/sysinternals/downloads/psexec). Download and unpack [PSTools.zip](https://download.sysinternals.com/files/PSTools.zip) in your *Downloads* folder, and in an administrative PowerShell, run: ```powershell -PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s -i $env:VBOX_MSI_INSTALL_PATH\VirtualBox.exe +& $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s -i $env:VBOX_MSI_INSTALL_PATH\VirtualBox.exe ``` ![Multipass instances in VirtualBox](upload://xVIOErbwcdoppcN5KSzvHJybSi7.png) To list the instances on the command line: + +```powershell +& $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe list vms +``` + +Sample output: + ```powershell -PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe list vms "primary" {05a04fa0-8caf-4c35-9d21-ceddfe031e6f} ``` @@ -187,7 +193,7 @@ This option only applies to macOS and Windows systems. To expose a service running inside the instance on your host, you can use [VirtualBox's port forwarding feature](https://www.virtualbox.org/manual/ch06.html#natforward), for example: ```plain -$ sudo VBoxManage controlvm "primary" natpf1 "myservice,tcp,,8080,,8081" +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. @@ -199,7 +205,7 @@ You can then open, say, http://localhost:8081/, and the service running inside t To expose a service running inside the instance on your host, you can use [VirtualBox's port forwarding feature](https://www.virtualbox.org/manual/ch06.html#natforward), for example: ```powershell -PS> & $env:USERPROFILE\Downloads\PSTools\PsExec.exe -s $env:VBOX_MSI_INSTALL_PATH\VBoxManage.exe controlvm "primary" natpf1 "myservice,tcp,,8080,,8081" +& $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. @@ -225,14 +231,19 @@ An often requested Multipass feature is network bridging. You can add a second n First, stop the instance: ```plain -$ multipass stop primary +multipass stop primary ``` -Now, find the network interface you want to bridge with (you want the identifier before the second colon): +Now, find the network interface you want to bridge with, running the command: ```plain -$ VBoxManage list bridgedifs | grep ^Name: -Name: en0: Ethernet +VBoxManage list bridgedifs | grep ^Name: +``` + +You want the identifier before the second colon; for example `en0` in the following sample output: + +```plain +Name: en0: Ethernet Name: en1: Wi-Fi (AirPort) Name: en2: Thunderbolt 1 Name: en3: Thunderbolt 2 @@ -242,25 +253,35 @@ 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](https://www.virtualbox.org/manual/ch06.html#network_bridged) on this topic): ```plain -$ sudo VBoxManage modifyvm primary --nic2 bridged --bridgeadapter2 en0 +sudo VBoxManage modifyvm primary --nic2 bridged --bridgeadapter2 en0 ``` [note=caution] Do not touch --nic1 as that's used by Multipass. [/note] -You can then start the instance again and find the name of the new interface: +You can then start the instance again: + +```plain +multipass start primary +``` + +To find the name of the new interface, run this command: + +```plain +multipass exec primary ip link | grep DOWN +``` + +In the following sample output, the name of the interface that we are looking for is `enp0s8`: ```plain -$ multipass start primary -$ multipass exec primary ip link | grep DOWN -3: enp0s8: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 +3: enp0s8: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 ``` -And configure that new interface — Ubuntu uses [netplan](https://netplan.io/) for that: +Now, configure that new interface (Ubuntu uses [netplan](https://netplan.io/) for that): ```plain -$ multipass exec -- primary sudo bash -c "cat > /etc/netplan/60-bridge.yaml" < /etc/netplan/60-bridge.yaml" < 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 @@ -284,7 +311,7 @@ $ multipass exec primary ip address show dev enp0s8 up 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>/. +All the services running inside the instance should now be available on your physical network under http://<instance IP>/. [/tab] @@ -307,8 +334,8 @@ This option only applies to macOS systems. To switch back to the default `qemu` driver, first you need to stop all instances again: ```plain -$ multipass stop --all -$ multipass set local.driver=qemu +multipass stop --all +multipass set local.driver=qemu ``` Here, too, existing instances will be migrated. @@ -324,7 +351,7 @@ This will make you lose any customisations you made to the instance in libvirt. If you want to switch back to the default driver, run: ```plain -$ sudo multipass set local.driver=qemu +multipass set local.driver=qemu ``` Instances created with VirtualBox don't get transferred, but you can always come back to them. @@ -336,7 +363,7 @@ Instances created with VirtualBox don't get transferred, but you can always come If you want to switch back to the default driver: ```plain -PS> multipass set local.driver=hyperv +multipass set local.driver=hyperv ``` Instances created with VirtualBox don't get transferred, but you can always come back to them. @@ -345,8 +372,6 @@ Instances created with VirtualBox don't get transferred, but you can always come [/tabs] - --- -*Let us know how this worked for you and what you’d like to see next!* -------------------------- \ No newline at end of file +*Errors or typos? Topics missing? Hard to read? Let us know or open an issue on GitHub.*