Run an Ubuntu VM on Apple Silicon
Tags: linux, apple, ubuntu, arm64
Published: 2023-01-25 06:54:59

VirtualBox does not support ARM-based architectures like the [Apple silicon](https://developer.apple.com/videos/play/wwdc2020/10686/) on [these](https://support.apple.com/en-us/HT211814) Macs yet so we'll need another option. [Multipass](https://multipass.run) from Canonical can launch and run virtual machines (instances) and configure them with [cloud-init](https://cloudinit.readthedocs.io/en/latest/topics/examples.html) like a public cloud. In fact it's my preferred way to launch Ubuntu instances regardless of whether VirtualBox is available for my system.

Get it with [Homebrew](https://brew.sh):
```shell
brew install multipass
```
See the list of images available:
```shell
multipass find
```

{% details Useful commands when managing instances. %} ```shell
multipass help
multipass list
multipass start
multipass restart
multipass mount /Volumes/USB primary
multipass stop
multipass delete --all
multipass purge
``` 
{% enddetails %}

<br>

We will:
* Create an instance from the Ubuntu 22.04 LTS (Jammy Jellyfish) image. 
* Specify the number of CPUs, disk space, and amount of memory to allocate.
* Give it a name. If the name is `primary` the user's home directory is mounted inside the newly launched instance, in `Home`. Without any arguments, commands for managing instances will apply to the primary instance.
* Install a desktop environment and a Remote Desktop server.


## Launch the instance
You can do this with `cloud-init` or without it (manual configuration).

### With cloud-init

Create a configuration file. It will update/upgrade the system, install the packages we need, and create a new user (`cloudy`) with a password for us to log in with Remote Desktop. This example uses a plain text password for simplicity but adjust it to your environment's security needs.
```shell
cat << EOF > cloud-config.yaml
package_upgrade: true
packages:
  - ubuntu-desktop
  - xrdp
  - xsel
users:
  - default
  - name: cloudy
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    lock_passwd: false
    plain_text_passwd: 'supersecretpwd'
EOF
```
Launch the instance using the configuration file we created:
```shell
multipass launch jammy --cloud-init cloud-config.yaml --name primary --cpus 4 --disk 15G --memory 8G
```

### Without cloud-init

You could also configure the instance manually instead. In this case we don't need to create a new user, we'll just manually set a password for the default user and use that one.
```shell
multipass launch lts --name primary --cpus 4 --disk 15G --memory 8G
```

Connect to the instance to install a desktop environment and a Remote Desktop server.
```shell
multipass shell
```

```shell
sudo apt update && sudo apt upgrade -y
sudo apt install ubuntu-desktop xrdp -y
```

Set a password for the default `ubuntu` OS user.
```shell
sudo passwd ubuntu
```

## Access the instance's desktop

To access the newly-installed desktop we need the IP address of the instance. Find it either by running the `ip addr` command within the Ubuntu shell or by running `multipass list` on your Mac host. 

Then use that IP address to connect with an RDP client like Microsoft Remote Desktop (available on the App Store). You can use the default user `ubuntu` if you manually set its password or the user cloud-init created with the password you specified.