Experimenting with Ubuntu using Multipass

Multipass is a quick and easy way to bring up Ubuntu instances with a single command. It’s available on Mac, Linux and Windows and uses hypervisors available natively on each platform; like hyperkit on OSX. You can also provide cloud-init metadata to new instances, similar to any major cloud provider.

Installation on OSX is easy with brew or by downloading a .pkg file. It was easier to get started with Multipass than lxd on OSX because, lxd only runs on linux.

Creating new instances

Creating a new instance can be done with a single command.

multipass launch 20.10 -n instance-name

You can specify which Ubuntu version you would like to use by including a version number, but this param is optional.

The instance name can be specified with the -n flag, but is also optional. If you don’t specify one, a random one will be generated.

Listing Instances

Running instances can be listed using list.

$ multipass list
Name                    State             IPv4             Image
instance-name           Running           192.168.64.4     Ubuntu 20.10

Inspecting Instances

You can inspect the state of your running instances using info.

$ multipass info instance-name
Name:           instance-name
State:          Running
IPv4:           192.168.64.4
Release:        Ubuntu 20.10
Image hash:     1780c1352766 (Ubuntu 20.10)
Load:           0.39 0.60 0.70
Disk usage:     2.3G out of 4.7G
Memory usage:   768.4M out of 977.6M

It’s worth nothing that by default, Multipass seems to auto allocate a subset of available resources to each running instance (CPU, disk and memory).

Interacting with Instances

You can easily ssh into a running instance using:

multipass shell instance-name

Starting, Stopping, Deleting Instances

You can use the multipass start <instance-name>, multipass stop <instance-name> and multipass delete <instance-name> commands to control instances. Once an instance is deleted, it will still appear in the instance list till you run the multipass purge command.

Using cloud-init

If you want to use a cloud-init file, you can also include that with the launch command. As an example, we can create a very basic cloud-init file that specifies the hostname of the new instance.

cloud-config.yaml:

hostname: newhostname

To launch a new instance with this cloud-init file, use the --cloud-init flag.

multipass launch 20.10 -n instance-name --cloud-init cloud-config.yaml

Transferring Files

For transferring files between host and VM, you can either mount a shared directory or use the transfer command to move individual files.

Mounting a Directory

On the host machine, to mount a directory:

mkdir somedir
multipass mount somedir/ instance-name:/home/ubuntu/somedir

Using the transfer command

multipass transfer instance-name:/path/to/remote/file /path/to/local/file
multipass transfer /path/to/local/file instance-name:/path/to/remote/file

Networking

Instances are assigned IP addresses and accessible from the host at the IP address listed in the list/info command.

For example if you were to run a webserver on port 8080 and the instance IP is 192.168.64.4, you could reach that webserver from the host at 192.168.64.4:8080.

Communication between instances

Instances are networked and you should be able to access one host from another via IP address. There doesn’t seem to be any DNS setup by default.

Advanced networking settings

A number of other networking features like Bridging are now possible but require that you use VirtualBox as the hypervisor. Instructions can be found here.