How to install a Ubuntu server VM on M1 mac

I have started to learn Linux. I wan't to learn more about the DevOps space. With supply chain shortages getting hold of a Raspberry Pi is hard work, I was hoping to run a linux server on a Pi you see. I'm also worried about generating large costs in a cloud platform like AWS or GCP, even with a free tier there is that worry.

Get an instant Ubuntu VM with a single command. Multipass can launch and run virtual machines and configure them with cloud-init like a public cloud.

Instead I came across multipass which seems to be just want I need to run VMs on a M1 mac. You see VirtualBox by Oracle doesn't support the M1 acrhitecture, therefore I'm unable to run a VM with the likes of Ubuntu desktop or Kali Linux, which is a shame but not the end of the world.

Installing Multipass

The easiest way I found to install multipass was to use Homebrew the good ol' trusty package manager for mac.

brew install --cask multipass

Once complete you can create your first instance.

Creating an instance

The quickest way to create an instance is to run

multipass launch

This will create an instance with a random name, very much like Docker does when starting containers. You can then list all your instances with the following multipass list that will give you something like below.

Name                    State             IPv4             Image
clear-slug              Stopped           --               Ubuntu 20.04 LTS
supple-cattle           Stopped           --               Ubuntu 20.04 LTS

You can find info about each instance by running multipass info <instance-name> so something like:

multipass info clear-slug

The following information will be printed out to the terminal.

Name:           clear-slug
State:          Running
IPv4:           192.168.64.8
Release:        Ubuntu 20.04.4 LTS
Image hash:     a12805170d70 (Ubuntu 20.04 LTS)
Load:           0.00 0.00 0.00
Disk usage:     1.3G out of 4.7G
Memory usage:   139.7M out of 969.8M
Mounts:         --

Logging into your instance

To gain access into your instance the easiest way is to run

multipass shell <instance-name>

This will be like using SSH. Happy days there is a tone more to mutlipass the docs are great, which can be found here.

Tips

Every developer wishes they could write less code, therefore I suggest creating some aliases in your shell config file. These are mine...

alias mp="multipass"
alias mpla="multipass launch --name $1"
alias mps="multipass shell $1"
alias mpli="multipass list"
alias mpi="multipass info $1"
alias mpstr="multipass start $1"
alias mpstp="multipass stop $1"
alias mpr="multipass restart $1"
alias mpd="multipass delete $1"

This saves me time always writing multipass or whel I want to SSH into my instance.