...
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. You can also attach or detach a virtual network adapter to a Hyper-V virtual network (virtual switch). 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 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. 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 the number of CPUs or amount of memory using a Multipasss command, but the Hyper-V Manager interface is better for these type of changes.
There are still a few changes that are complicated and require some thought. Changing the size of the hard disk requires first enlarging the virtual size of the disk, then expanding the partition, and finally telling the file system to use the extra space. You can find articles that give you the Linux commands, but Multipass makes it much simpler with a command that allows you to expand (but not reduce) the disk size of a VM:
multipass set local.vmname.disk=100G
Note that Hyper-V virtual disk file are dynamic, start out small, and only increase in size when you are adding data to the disk. Therefore, it is generally a good practice to overestimate the size of the disk you will need since you are only assigning a maximum size the disk will grow to. The same amount of data will take the same amount of disk space whether the disk (maximum) size is 50G, 100G, or 200G.
In the same way, it is better to create a VM with the maximum number of network adapters you will ever need. Extra adapters that you are not using immediately can be attached to an otherwise unused private Hyper-V switch, but it is probably better if they are not attached to any switch at all (leaving them like a physical network adapter that has no cable plugged into it). The problem is that Ubuntu networks are configured in a file /etc/netplan/50-cloud-init.yaml. Each adapter is identified by its Ethernet address which is dynamically assigned by Hyper-V. If you create all the adapters you may ever use, you get a file that configures each of them then only have to change the IP parameters rather than change the whole thing if you add an adapter later onaddress parameters on an already configured adapter.
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. If 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.Multipass will download the initial image file if it is not already on your machine.
Cloud-Init
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.
...
Run Commands as “ubuntu” user
When it is installed, During installation Multipass generates a local set of SSH keys and stores the secret key in C:\ProgramData\multipass\data\ssh-keys file.
On each VM, Multipass creates a user named “ubuntu” with sudo privileges and inserts in its home directory the matching public SSH key.
Multipass does not depend on SSH installed on the Windows system. It then has comes with its own internal version of ssh and scp programs that it uses SSH programs to connect to the VMs, create a session, pass commands, or transfer files. It does all this over the Default Hyper-V Default network. All the multipass commands that communicate to the VM (exec, shell, mount, transfer, etc.) use this internal SSH.However, ubuntu
The “ubuntu” user does not have a password unless you assign one, so if you lose Multipass or its private key gets clobbered you are locked out. You should always do this in case the ssh connection to the VM is broken, so you can login to the VM using the Hyper-V console window and the password you created.
...
use the “passwd” command to create your own password for this user. Multipass won’t use it, but if you lost Multipass (or if you feel like it) you can use the Hyper-V Manager to open a window with the hardware console of the VM and then login as “ubuntu” with the password you assigned.
But also back up the C:\ProgramData\multipass\data\ssh-keys file someplace safe, since even if Multipass was clobbered you can use the real ssh.exe client program built into current Windows to connect to the VM without multipass if you have the file (since it doesn’t appear to have a passcode and you can just point to it on the ssh command).
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. You can also create your own userid, assign it sudo 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.
So you should always create Multipass VMs that can stand on their own without a multipass command. You should also take advantage of Hyper-V tools to checkpoint and backup and export VMs. You should also find and backup the multipass ssh keysThen you can use Windows ssh command instead of Multipass.
You want three alternative backups: a password on the “ubuntu” user, a backup of the Multipass private key file, and your own authorized user with you own ssh key (and if you want, put your password on it too). Now if you lose Multipass control, you still have access to the VM. This is useful if you now use it for docker, or a database, or a Web server.
If you install a new Multipass today, it puts its files in C:\ProgramData which is safe. Several releases ago it put them in the C:\Windows subdirectories which was a mistake because Windows would remove them across a semiannual feature upgrade. Of course, every time winget upgrades Multipass from one minor version to the next it runs an uninstall which pops up a dialog offering you the chance to destroy all your files and VMs if you just click the Yes button. In other words, it is just too easy to lose everything.
So back up Multipass in C:\ProgramData, at least to some offline backup disk just in case.
Multipass does not do a good job of explaining how things are done. It uses a Windows feature called a “difference disk”. Each VM starts with a read-only copy of the base Ubuntu disk image file, but from this image it creates a read-write file where Windows writes all the changes that were made to the disk as it first boots up and is configured.
Code Block |
---|
Directory of C:\ProgramData\Multipass\data\vault\instances\docker
06/19/2022 11:53 AM <DIR> .
07/14/2022 06:03 PM <DIR> ..
06/19/2022 11:53 AM 59,392 cloud-init-config.iso
06/19/2022 11:53 AM 1,686,110,208 ubuntu-22.04-server-cloudimg-amd64.vhdx
07/14/2022 08:17 PM 3,507,486,720 ubuntu-22.04-server-cloudimg-amd64_11B1CDD6-25BA-44B1-92A3-1C4DBFCA6924.avhdx
3 File(s) 5,193,656,320 bytes |
The ubuntu-22.04-server-cloudimg-amd64.vhdx is the read-only image and the ubuntu-22.04-server-cloudimg-amd64_11B1…24.avhdx file is the read-write difference disk. Hyper-V will only show the difference disk name. You may confuse this with a similar arrangement for Hyper-V checkpoints. This is not a checkpoint but rather an option Windows provides for its virtual disk files.
If you upgrade to 22H2 and Multipass appears to have been deleted, remember that the old files are saved for a month or so in the C:\Windows.old directory. That does not, however, give you instructions for restoring your old multipass installation on the new system.
On each VM, do a “sudo passwd ubuntu” and give the built in ubuntu user a real password and not just SSH keys.
Add a second user with your own normal SSH login key and a password, and give it SUDO privileges.
Find the Multipass ssh key and save the file separately (it has no passcode).
Don’t count on “multipass mount”. Find another way to share files. For example, the new system.
Durable Shared Files
If you count on “multipass mount” you are in trouble if the multipass configuration gets broken. Besides, the performance is pretty terrible.
A native Windows to Linux file sharing solution can be added using Windows standard file shares. On the VM do a “sudo apt install cifs-utils” and learn how to connect to a Windows Shared disk directory. This is a good article.Backup VMs using Hyper-V “Export”. Not only does this allow you to restore after various problems, but is also a convenient way to move VMs from one host to anothera Windows Shared disk directory. This is a good article.
Export
Backup VMs or move them from one Windows system to another using Hyper-V “Export”. Note that if you do this, Multipass on the Importing host will not know about and cannot talk to a VM that was previously connected to Multipass on the Exporting host, which is a second excellent reason for creating VMs that can stand on their own without the multipass command. That is why you have multiple ways to login, transfer files, and share directories.
The eth0 Network
When Multipass creates a new VM it creates a first Virtual Network Adapter and connects it to the Hyper-V Default Switch network. Default is a network that “just works out of the box” so you don’t need to configure or administer it, so you are not allowed to change or manage it. Every time the Host computer reboots, it does the equivalent of a “factory reset” on the Default network and everyone gets a new IP address.
...
You get more if you add a service that combines DHCP, DNS, a firewall, and a gateway to the Sandbox network. For this, you create an empty VM and install a system from a DVD image. Search the Web for “pfSense”, “opnSense”, or “openWRT” for widely used alternatives. These systems are not related to Multipass, so I just suggest them as network configuration options.
There is also a physical version of this, where you take the Ethernet adapters connecting a Sandbox 2 configuration and plug them into the wired ports on the back of a TPLink or Netgate wired router/gateway box. Then you only have to know how to admin these familiar boxes and you don’t need to learn pfSense, but at this time you are now limited to Gigabit Ethernet speed.
Make the Second Adapter Preferred
...