We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Run Ubuntu Virtual Machines on Linux and macOS using Multipass

Learn how to – Run Ubuntu Virtual Machines on Linux and macOS using Multipass.

This guide demonstrates how to run Ubuntu Virtual Machines on Linux and macOS using Multipass. But before we dive into the crux of this tool. Let us get to know what this tool is.

What is Multipass?

There are many virtualization tools available to deploy VMs for testing and learning purposes. These include Virtualbox, VMware, LXD, KVM, Docker, LXC, Proxmox, Vagrant e.t.c I use Virtualbox and VMware regularly for testing various Linux applications on Linux distributions. In this guide, we are going to take in yet another virtualization tool known as Multipass. This tool makes it easy to create and launch Ubuntu Virtual Machines for regular users, developers, and system admins.

Multipass is a lightweight Virtual machine manager developed by the canonical team to create and launch ubuntu instances on your local machine. It is developed to run on macOS, Windows, and GNU/Linux systems. Multipass uses KVM on Linux, Hyper kit on macOS, and Hyper-V on Windows to run the virtual machine with minimal overhead.

With Multipass, one can run commands directly into the VM’s shell from your local computer. Moreso, it is possible to mount directories of your host system and share files with the VM.

With the above knowledge, we are now set to dive into the installation of Multipass.

Step 1: Install Multipass On Linux and macOS

1. Install Multipass on Linux

On Linux, Multipass is available as a snap package. It can easily be installed on any Linux distribution that supports snapd.

In some distributions such as Zorin OS, Solus 3 and Ubuntu releases from 16.04 LTS snap comes as a pre-installed application. You can install snapd as below:

###On Debian/Ubuntu
sudo apt install snapd

###On RHEL 7/CentOS 7
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y upgrade
sudo yum -y install snapd

###On Rhel 8/Centos 8/Rocky Linux 8/Fedora
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo dnf -y upgrade
sudo dnf -y install snapd

Then enable snapd as below:

sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap

With snap installed and started, we are set to install Multipass on any Linux distribution using the command:

First, update and upgrade your system. Then install Multipass on Linux as below

sudo snap install multipass

If the above fails to run for any reason, try to install Multipass with this command:

sudo snap install multipass --classic

With Multipass successfully installed, you will see this output:

multipass 1.10.1 from Canonical✓ installed

2. Install Multipass on macOS

On macOS, there are multiple ways to get Multipass installed on your system.

1. Using Multipass Installer

Download the Multipass installer from the official downloads page then install it. With the .pkg package downloaded, Install it on your macOS system by activating it. Follow through the steps given using Administrator privileges.

2. Using Brew

With brew, you can easily install Multipass on macOS using the command below:

brew install --cask multipass

On macOS, Multipass supports VirtualBox as a virtualization provider. If you would like to use VirtualBox, issue the below command:

sudo multipass set local.driver=virtualbox

Verify your Multipass installation using the command.

$ multipass version
multipass 1.10.1+mac
multipassd 1.10.1+mac

Step 2: Create and launch Ubuntu VMs with Multipass on Linux and macOS

With Multipass successfully installed on your system, running Ubuntu VM’s is incredibly easy.

To launch an Ubuntu Instance use the command:

multipass launch --name test-instance

alternatively use:

multipass launch -n test-instance

In the above code, replace test-instance with your desired Ubuntu instance name.

The latest minimal Ubuntu LTS instance will be downloaded and automatically started as below:

You can now list your available VMs using the command:

multipass list

Sample Output:

Name                    State             IPv4             Image
test-instance           Running           10.14.155.56     Ubuntu 20.04 LTS

From the above output, we have an Ubuntu instance with the name test-instance with Ubuntu 20.04 LTS and also the IP is provided.

Execute commands for your VM from the Local System.

One of the amazing features of Multipass is that it allows one to run commands for the Ubuntu instance from the local machine.

To find the system’s details for a running VM use:

multipass exec test-instance -- lsb_release -a

In the code, test-instance is the name for the VM we want the details for.

Sample Output:

Launch Ubuntu VM’s shell.

Aside from running commands from the local system’s shell, you can launch the Ubuntu VM’s shell and directly run the commands on it. The Shell for the Ubuntu VM is launched with the command:

multipass shell test-instance

Sample Output:

Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-81-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Mon Aug 30 14:32:29 EAT 2021

  System load:  0.08              Processes:             104
  Usage of /:   27.4% of 4.67GB   Users logged in:       0
  Memory usage: 18%               IPv4 address for ens4: 10.14.155.56
  Swap usage:   0%


1 update can be applied immediately.
To see these additional updates run: apt list --upgradable


Last login: Mon Aug 30 14:31:40 2021 from 10.14.155.1
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@test-instance:~$ 

From the shell, you can execute the normal Ubuntu command such as:

sudo apt update

To logout from the shell use:

exit

Find other instances to Launch

As we already saw earlier, Multipass finds and downloads the current LTS version of Ubuntu for the VM. But you still can find other available versions you want to run using the command:

$ multipass find
Image                       Aliases           Version          Description
snapcraft:core18            18.04             20201111         Snapcraft builder for Core 18
snapcraft:core20            20.04             20210921         Snapcraft builder for Core 20
snapcraft:core22            22.04             20220426         Snapcraft builder for Core 22
snapcraft:devel                               20220913         Snapcraft builder for the devel series
core                        core16            20200818         Ubuntu Core 16
core18                                        20211124         Ubuntu Core 18
18.04                       bionic            20220901         Ubuntu 18.04 LTS
20.04                       focal,lts         20220824         Ubuntu 20.04 LTS
22.04                       jammy             20220902         Ubuntu 22.04 LTS
daily:22.10                 devel,kinetic     20220910         Ubuntu 22.10
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
anbox-cloud-appliance                         latest           Anbox Cloud Appliance
charm-dev                                     latest           A development and testing environment for charmers
docker                                        latest           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

From the output, there are several Ubuntu LTS versions. You can launch an instance from the list using the syntax below.

$ multipass launch --name test1-instance 22.04

This command will launch an instance for Ubuntu 22.04.

Create an Instance with Custorm Specifications.

Multipass by default will create a VM with 5 GB hard disk size, 1 CPU, and 1 GB RAM. However, this can be altered by making custom settings for the VM you want. This helps one create a VM meeting desired specifications and need.

For example in the below code, I will demonstrate how to create a VM with 2 CPUs, 4 GB RAM, and 15 GB storage space.

multipass launch -c 2 -m 4G -d 15G -n test2-instance

View info about the instance:

$ multipass info test2-instance
Name:           test2-instance
State:          Running
IPv4:           10.14.155.175
Release:        Ubuntu 20.04.3 LTS
Image hash:     97bb9f79af52 (Ubuntu 20.04 LTS)
Load:           0.47 0.31 0.12
Disk usage:     1.3G out of 14.4G
Memory usage:   149.0M out of 3.8G
Mounts:         --

Remember, the minimum allowed requirements are:

  • CPU- 1
  • Memory- 128 MB
  • Hard diks- 512 MB

Launch with custom network interface

List available networks:

$ multipass networks
Name     Type         Description
bridge0  bridge       Network bridge with en1, en2, en3, en4
en0      wifi         Wi-Fi (Wireless)
en1      thunderbolt  Thunderbolt 1
en2      thunderbolt  Thunderbolt 2
en3      thunderbolt  Thunderbolt 3
en4      thunderbolt  Thunderbolt 4

Launch an instance with specified network interface:

multipass launch -c 2 -m 4G -d 15G --network name=en0 -n test2-instance

Wait for instance to start then check available interfaces:

$ multipass shell test2-instance
ubuntu@test2-instance:~$ ip ad
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:7f:cb:cf brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 85884sec preferred_lft 85884sec
    inet6 fe80::5054:ff:fe7f:cbcf/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:43:43:b4 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.164/24 brd 192.168.100.255 scope global dynamic enp0s8
       valid_lft 85890sec preferred_lft 85890sec
    inet6 fe80::5054:ff:fe43:43b4/64 scope link
       valid_lft forever preferred_lft forever

Suspend running instances

To suspend instance on Multipass, run the command:

multipass suspend test-instance

Verify if the instance is suspended:

$ multipass info test-instance
Name:           test-instance
State:          Suspended
IPv4:           --
Release:        --
Image hash:     97bb9f79af52 (Ubuntu 20.04 LTS)
Load:           --
Disk usage:     --
Memory usage:   --
Mounts:         --

The command multipass info test-instanceis generally used to get information about an instance.

Step 3: Manage Ubuntu VMs on Multipass.

You can start and stop Ubuntu VMs on Multipass using the below commands:

###Stop a VM
multipass stop test-instance

###Start a VM
multipass start test-instance

Alternatively, you can manage your VMs using the Multipass Tray icon. This is done by launching Multipass GUI from the App Menu on the host system. From the tray icon, one can stop/start, open shell, disable and enable autostart of a VM and also quit Multipass.

Delete VMs

With intended tasks for the VM achieved, you can delete the VM if you no longer need it. First, you need to stop the VM.

multipass stop test-instance

Then delete it as below:

multipass delete test-instance
multipass purge

Mount and Unmount a local directory

To mount a local directory use the following command syntax:

multipass mount <source> <target> [<target> ...]

Example:

$ multipass list
Name                    State             IPv4             Image
ubuntu-focal            Running           N/A              Ubuntu 20.04 LTS

$ multipass mount ~/Downloads ubuntu-focal
$ multipass info ubuntu-focal
Name:           ubuntu-focal
State:          Running
IPv4:           N/A
Release:        Ubuntu 20.04.3 LTS
Image hash:     10f8ae579fbf (Ubuntu 20.04 LTS)
Load:           0.00 0.01 0.05
Disk usage:     1.3G out of 19.2G
Memory usage:   164.0M out of 1.9G
Mounts:         /Users/jmutai/Downloads => /Users/jmutai/Downloads
                    UID map: 501:default
                    GID map: 20:default

$ multipass ssh ubuntu-focal
$ ubuntu@ubuntu-focal:~$ df -hT
Filesystem                Type        Size  Used Avail Use% Mounted on
udev                      devtmpfs    977M     0  977M   0% /dev
tmpfs                     tmpfs       199M  968K  198M   1% /run
/dev/sda1                 ext4         20G  1.3G   18G   7% /
tmpfs                     tmpfs       994M     0  994M   0% /dev/shm
tmpfs                     tmpfs       5.0M     0  5.0M   0% /run/lock
tmpfs                     tmpfs       994M     0  994M   0% /sys/fs/cgroup
/dev/loop0                squashfs     56M   56M     0 100% /snap/core18/2128
/dev/loop1                squashfs     71M   71M     0 100% /snap/lxd/21029
/dev/loop2                squashfs     33M   33M     0 100% /snap/snapd/12883
/dev/sda15                vfat        105M  5.2M  100M   5% /boot/efi
tmpfs                     tmpfs       199M     0  199M   0% /run/user/1000
/dev/loop3                squashfs    128K  128K     0 100% /snap/bare/5
/dev/loop4                squashfs    1.2M  1.2M     0 100% /snap/multipass-sshfs/145
:/Users/jmmutai/Downloads fuse.sshfs 1000G     0 1000G   0% /Users/jmutai/Downloads

To unmount use the command:

$ multipass umount  ubuntu-focal
$ multipass info ubuntu-focal
Name:           ubuntu-focal
State:          Running
IPv4:           N/A
Release:        Ubuntu 20.04.3 LTS
Image hash:     10f8ae579fbf (Ubuntu 20.04 LTS)
Load:           0.00 0.00 0.04
Disk usage:     1.3G out of 19.2G
Memory usage:   159.8M out of 1.9G
Mounts:         --

In case you get stuck when using Multipass, there is a way out by getting help using the command:

$ multipass help
Usage: multipass [options] <command>
Create, control and connect to Ubuntu instances.

This is a command line utility for multipass, a
service that manages Ubuntu instances.

Options:
  -h, --help     Display this help
  -v, --verbose  Increase logging verbosity. Repeat the 'v' in the short option
                 for more detail. Maximum verbosity is obtained with 4 (or more)
                 v's, i.e. -vvvv.

Available commands:
  delete    Delete instances
  exec      Run a command on an instance
  find      Display available images to create instances from
  get       Get a configuration setting
  help      Display help about a command
  info      Display information about instances
  launch    Create and start an Ubuntu instance
  list      List all available instances
  mount     Mount a local directory in the instance
  networks  List available network interfaces
  purge     Purge all deleted instances permanently
  recover   Recover deleted instances
  restart   Restart instances
  set       Set a configuration setting
  shell     Open a shell on a running instance
  start     Start instances
  stop      Stop running instances
  suspend   Suspend running instances
  transfer  Transfer files between the host and instances
  umount    Unmount a directory from an instance
  version   Show version details

Conclusion.

Congratulations! That marks the end of this guide on how to run Ubuntu Virtual Machines on Linux and macOS using Multipass. We have seen how easy it is to create and run Ubuntu instances with Multipass. I hope this was helpful

See more:

8
392.806,95