...
Unlike containers or WSL, a Linux Server VM runs “systemd” and supports components that require a background service (also known as a daemon). This allows you to run database systems and Docker itself on a Multipass VM.
Ubuntu automatically configures the generated VMs Multipass VMs are configured to run well enough under Hyper-V . There are a few optional packages that add convenience features, but you don’t have to research how to configure a system installed from a generic distribution on a DVD image.
Multipass is designed for personal machines that only one person uses. It has only minimal multi-user access control.
Install
When you install Hyper-V you should think about the default location for new VM system disks. These can be large and many users have a small C: drive and a larger secondary D disk. Multipass maintains its own separate directory where downloaded starter image files and new VMs are stored. If you have more space on an SSD other than C, you should to minimize code complexity they tend to use features available in every system they support (including VirtualBox, Linux, and Mac), so it is not optimized for Hyper-V. You can always add missing packages.
Multipass tries to support multi-user machines, but that objective conflicts with making some things easy to use. It works best on a personal machine with only one user who is admin, because then you can do everything .
Install
A new install of Multipass stores the disk images and virtual machines in the C:\ProgramData\Multipass directory. Hyper-V can only use locations that are on a local disk (not a network share), but if you want to move large files to another disk you should consider this before you install. If you have a larger D drive, then you might want to set the environment variable MULTIPASS_STORAGE to point to a path in the bigger disk first. This cannot be a network attached disk, because Hyper-V can only use directly attached diskslocation on that disk.
You can install Multipass with the winget package manager:
...
Enable Mounts (a convenience factor)
Multipass has the ability to share (using its own non-standard disk sharing technique) directories on your Host Windows system with VMs. Use this only to transfer files occasionally, because it has relatively poor performance. It also doesn’t have much in the way of access control, but this is not a problem if you are the only one who uses the host computer. On the chance that someone else logs onto your machine and your don’t trust them, this must be enabled.
Open a Run as Administrator command prompt window and issue the one time command:
multipass set local.privileged-simple commands and options to share Windows directories with Multipass VMs. This is done through the multipass mount command after the VM is created, or the --mount parameter when creating a VM. This is, however, one of the places where the authors opted first for something they could get to work on all systems without regard to performance. They use a terribly inefficient tool that shares directories over an SSH connection.
This is fine for casual access to files, but not for anything that does a lot of I/O. There are other options (NFS, CIFS - a.k.a. Windows Shares, …). I will update this if anyone proposes a best practice.
This is one of the places where a multi-user machine would have problems with security. Mounts are shipped disabled, and if you are running on a single user environment or you trust all your users, open a Run as Administrator command prompt window and issue the one time command:
multipass set local.privileged-mounts=true
Choose a Base Image
...
The “multipass launch” command creates a new VM. The single positional parameter (at the end of the command) is the name or alias of one of the images listed above (the default is “lts”, but you will note that several months after 22.04 was released they have not changed “lts” to point to it).
...
A Multipass VM is also a Hyper-V VM. The Hyper-V Manager allows you to change the number of CPUs and the amount of memory. However, modifying the size of a disk is more complicated. A Starting with Multipass 10 you can also change initial parameters by stopping the VM and issuing a multipass set command with the name of the vm and “cpus”, “memory”, or “disk”. For example, to expands the default 5G disk to something larger type:
multipass set local.vmname.disk=100G
Hyper-V virtual disk is dynamic, meaning it is created as a small file that expands only if you write more data into it. So overestimating the size of the disk is a better practice, and the default size of 5G is unusable for most purposes. Setting --disk 127G is a normal practice and just sets a limit to the maximum amount the virtual disk file can expand to.You can also add Virtual Network Adapters with Hyper-V, but network adapters are configured in a rather complicated file are dynamic and expand only when it is necessary because new data is being added to them, so overestimating the disk size in a multipass command does not use disk space. Running a bad program that fills up the disk is when you have a problem.
It is still useful to get the number of adapters correct in the multipass launch by adding as many --network parameters as you need. The IP addresses of the adapters are specified in the file /etc/netplan/50-cloud-init.yaml that you have to change to define the new adapter. It is better to add the adapter when multipass creates the VM and then the file will at least start up with all adapters defined and only require simpler edits. Each adapter is identified by its Ethernet address which is dynamically assigned by Hyper-V unless you explicitly add it to the --network parameter on the multipass launch. It is easier if you get a file that is already configured for the adapters and then only have to change the IP parameters rather than change the whole thing if you add an adapter later on.
An example of the command to create a VM is:
...
The last and only positional parameter is the image name “22.04” taken from the list of image names shown above.
There are many things you want to do to customize your VM, but some of these things you do to every VM. It is annoying to have to repeat 10 minutes of configuration for every VM. There is a cloud-init parameter and afile format provided with Multipass that allows you to do most of the configuration automatically during the execution of the “multipass launch”.
It can create groups and users, install SSH keys and CA Certificates, install additional packages and applications, and apply the most recent Ubuntu maintenance. A full discussion of this file format cannot be provided here, so read the manual.
Every time I type the “multipass launch” command interactively, as soon as I hit Enter I remember some parameter I accidentally left out. It is better to combine all the stuff you always do into a script file. If you need to make some changes, copy the script file and edit them inIf you have been reading carefully, you may have notices that the amount of memory on launch is set by --mem, but if you change it after launch you use “memory” as in multipass set local.vmname.memory. Of course, it is easier to change memory with the Hyper-V Manager if you are comfortable using it.
Lots of people have developed files and utilities to do configure a VM automatically when it is created by adding packages, users, groups, Certificates, keys, and other stuff. Canonical likes a tool called Cloud-Init. The “multipass launch --cloud-init “ parameter can take a file name or “-” for standard input. The file format is a bit complicated, and while some examples will be provided below, if you want the full syntax read the manual.
Of course, you can accomplish the same thing by writing a bash script, doing a “multipass transfer” of the script to the VM, and then run the script with “multipass exec” after the launch. It is up to you.
A useful trick in Powershell scripting is to put the text of the cloud-init file in the script as a multiline text literal that gets piped to the “multipass launch” and is then picked up by a “--cloud-init -” parameter where putting a dash “-” instead of a file name means “read from standard input” which is to say from the pipe. An alternative is to build a separate script that constructs the cloud-init file from parameters passed to the script, and then use that script to generate the text piped to the “multipass launch” command. Here is an example with inline text:
...
If you specify a new Ubuntu image name (22.04 here) a new image file will be downloaded from the Internet and saved in the cache first and then the rest of the launch will run.
Run Commands as “ubuntu” user
will run.
Run Commands as “ubuntu” user
When it is installed, Multipass generates SSH keys and stores the secret key in C:\ProgramData\multipass\data\ssh-keys.
On each VM, Multipass creates a user named “ubuntu” with sudo privileges . Multipass generates a ssh keys on install and copies the matching public SSH key to the /home/ubuntu/.ssh directory of every VM it creates. Multipass . It then has its own internal version of ssh and scp programs . It that it uses them to connect to the VM to pass commands, open a shell, copy files, and mount shared directories.You should always assign a password to the ubuntu user on each VM you create just in case the multipass ssh gets clobbered. Then VMs over the Hyper-V Default network. All the multipass commands that communicate to the VM (exec, shell, mount, transfer, etc.) use this internal SSH.
However, ubuntu does not have a password unless you assign one. You should always do this in case the ssh connection to the VM is broken, so you can login to the VM using a standard the Hyper-V console window for and the VMpassword you created.
IMPORTANT: READ THIS
Sometimes Multipass screws up.
...
Your Multipass VMs are real Hyper-V VMs. You can run them from Hyper-V, login to them with a Hyper-V console window, and generally ignore Multipass if you want. However, the special services provided by the multipass command fail if the ssh key is deleted or overwritten with a new keyconsole window, and generally ignore Multipass if you want. You can also create your own userid, assign it privileges, and store your normal SSH public key in your home directory.
This is useful if Multipass is clobbered on your machine and you have to fall back on standard VM communication. It is also useful if you move the VM to a different machine where the Multipass on that machine does not recognize VMs it did not itself create.
Until Version 1.9 Multipass stored its files in a directory that Microsoft believed it could delete on any annual major version upgrade of Windows 10 or 11. Even if that is fixed, you are given an opportunity to delete everything in the middle of the Setup dialogs each time Multipass updates its software with new fixes. Hit the Yes button instead of the No button and it is all gone.
...