Canonical Multipass
Posted on October 2, 2023 • 6 min read • 1,173 wordsCreate virtual maschines using Multipass
If no graphical user interface is required, this is really super easy.
At the end of this article we have the option of running a virtual machine that is accessible via SSH or public key. With such a VM you can, for example:
The tool is installed on an Ubuntu Linux machine via snap
:
sudo snap install multipass
multipass find
Image | Aliases | Version | Description |
---|---|---|---|
core | core16 | 20200818 | Ubuntu Core 16 |
core18 | 20211124 | Ubuntu Core 18 | |
core20 | 20230119 | Ubuntu Core 20 | |
core22 | 20230119 | Ubuntu Core 22 | |
20.04 | focal | 20230922 | Ubuntu 20.04 LTS |
22.04 | jammy,lts | 20230927 | Ubuntu 22.04 LTS |
22.10 | kinetic | 20230524 | Ubuntu 22.10 |
23.04 | lunar | 20230926 | Ubuntu 23.04 |
appliance:adguard-home | 20200812 | Ubuntu AdGuard Home Appliance | |
appliance:mosquitto | 20200812 | Ubuntu Mosquitto Appliance | |
appliance:nextcloud | 20200812 | Ubuntu Nextcloud Appliance | |
appliance:openhab | 20200812 | Ubuntu openHAB Home Appliance | |
appliance:plexmediaserver | 20200812 | Ubuntu Plex Media Server Appliance |
Blueprint | Aliases | Version | Description |
---|---|---|---|
anbox-cloud-appliance | latest | Anbox Cloud Appliance | |
charm-dev | latest | A development and testing environment for charmers | |
docker | 0.4 | A Docker environment with Portainer and related tools | |
jellyfin | latest | Jellyfin is a Free Software Media System that puts you in control of managing and streaming your media. | |
minikube | latest | minikube is local Kubernetes | |
ros-noetic | 0.1 | A development and testing environment for ROS Noetic. | |
ros2-humble | 0.1 | A development and testing environment for ROS 2 Humble. |
different Ubuntu versions
is certainly interesting, but also the docker
(incl. Portainer) or minikube
variant. Otherwise, you can install additional applications or tools as usual via the shell.
multipass launch <name of image>
multipass launch jammy
Create a Virtual Machine with custom name
multipass launch <name of image> --name <your VM name>
User-defined settings for number of CPUs, disc size and memory
multipass launch <name of image> --cpus 4 --disk 20G --memory 8G
You can also define your own network properties at startup (see Multipass Documentation )
multipass list
multipass info <name of VM>
The default and easiest way to work with a running VM is to open a shell
in the virtual machine via its instance name.
multipass shell <name of VM>
An SSH connection is not provided in the basic settings. It will be shown later how this can be configured (SSH connection via public key or via user & password ).
multipass exec <name of VM> -- <Command>
multipass exec <name of VM> -- lsb_release -a # e.g., gather information about the OS
A running VM can be shutdown using stop
.
multipass stop <name of VM>
A stopped VM can be restarted/booted via start
.
multipass start <name of VM>
A specific instance of a VM can be deleted using:
multipass delete <name of VM>
Instances that have already been deleted are permanently removed from the system via:
multipass purge
If you want to try out Ansible Playbooks in a VM, for example, you need a user who can log into the VM via SSH using the local SSH public key, i.e. without entering a password.
On Linux systems, the private and public SSH keys are often located in the hidden directory ~/.ssh
. The pair consists of two files that can be named as desired. The public key is often called the same as the private key with the suffix .pub
appended, e.g. id_rsa
(private) and id_rsa.pub
for the public key.
However, it is possible that the directory and therefore the SSH keys do not yet exist, simply because they have not yet been used. In this case, the SSH key pair can simply be generated.
ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ubuntu/.ssh/id_rsa #<< private ssh key
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub #<< public ssh key
The key fingerprint is:
[...]
nano
and copy the public key from the clipboard to the end of this file.The user of the public key just copied can now log into the instance from the local computer.
ssh ubuntu@<IP-of-multipass-VM>
The connection is established without requesting a password, as authentication is based on the public key.
When the instance is created, a configuration file (Cloud-Init
) is transferred, which ensures the creation of the user with password and enables the SSH login via user and password
.
In this case, the password for the new user myadmin is specified unencrypted (via plain_text_passwd) in the script. This is generally not a good idea!
For local use of multipass and the instantiated virtual machines, however, this seems acceptable to me.
---
users:
- name: myadmin
plain_text_passwd: 'myAdminPassword'
shell: /bin/bash
groups: users, admin
lock_passwd: false
chpasswd: { expire: False }
ssh_pwauth: True
If you wish, you can also specify a hashed password via passwd:, e.g. generated with
echo myAdminPassword | mkpasswd -m sha-512 -s
$6$oJA8JgSV3pvYqPAZ$TK/3n/ywsbZfEhYFbKIAAlVHw4i3Xc [...]
and then replace the line plain_text_passwd:
in cloud-init.yaml with
passwd: $6$oJA8JgSV3pvYqPAZ$TK/3n/ywsbZfEhYFbKIAAlVHw4i3Xc [...]
The instance is created in the same way as before, only the cloud init script is also transferred
multipass launch <name of image> --cloud-init cloud-init.yaml --name <your own name>
The SSH connection is established in exactly the same way as using the public SSH key,
ssh myadmin@<IP-of-multipass-Instance>
myadmin@<IP-of-multipass-Instance>'s password:
but this time the user password is requested.
Whenever you want to try something out, under different operating system versions, with different versions of software libraries, locally optimize an Ansible playbook or much more, even the ambitious home lab user often runs out of physical machines. With virtual machines based on Multipass, the boundaries of your own home lab can be significantly pushed back.
…as long as you have enough main memory…