Skip to main content
Version: v4 (current)

VMs with Multipass (Basic)

Multipass is a light-weight Virtual Machine Manager for Linux, Windows and MacOS. It's designed for developers who want to quickly create a fresh Ubuntu environment with a single command. It uses the native hypervisor for whichever platform it is installed on (KVM on Linux, Hyper-V on Windows and HyperKit on MacOS) to run VMs with minimal overhead. It can also use VirtualBox on Windows and MacOS. The biggest limitation of Multipass is that it only creates Ubuntu VMs.

Installation

To install multipass on Linux use the commands below.

sudo apt-get install snapd
sudo snap install core
sudo snap install multipass

For installation on Windows and MacOS, refer to the official installation instructions:

Creating a VM

  • Set values

    # The name of the Virtual Machine
    export VM_NAME="gameci"

    # The name of the user to create
    export VM_USER="vmadmin"

    # Number of CPU cores to allocate to the VM
    export VM_CPUS="2"

    # Amount of Disk Space to allocate to the VM.
    # Cannot exceed available on host.
    export VM_DISK="32G"

    # Amount of RAM to allocate to the VM.
    # Cannot exceed available RAM on host.
    export VM_MEM="8G"

    # Set path on MacOS systems
    export PATH="$PATH:/usr/local/bin/multipass"

    # Set path on Linux system
    export PATH="$PATH:/snap/bin/multipass"
  • Create a password

    # Install the mkpasswd utility
    sudo apt install -y whois

    read PW_STRING
    export PASSWORD=$(mkpasswd -m sha-512 --rounds=4096 "$PW_STRING" -s "saltsaltlettuce")
  • Create an ssh-key for authenticating with the VM

    ssh-keygen -C $VM_USER -f runner
  • Add the public ssh-key and password to a cloud-init file

    See the cloud init official docs for more information about cloud-init. More advanced templates are available in the Host Provisioning directory.

    VM_KEY=$(cat runner.pub)

    cat << EOF > cloud-init.yaml
    #cloud-config
    groups:
    - docker
    users:
    - default
    - name: ${VM_USER}
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    groups: docker, admin, sudo, users
    no_ssh_fingerprints: true
    lock_passwd: false
    passwd: ${PASSWORD}
    ssh-authorized-keys:
    - ${VM_KEY}
    packages:
    - docker.io
    EOF
  • Start the VM

    See the multipass launch command docs for more information.

    export VERBOSITY="-vvvvvv"

    /snap/bin/multipass launch --name $VM_NAME \
    --cpus $VM_CPUS \
    --disk $VM_DISK \
    --mem $VM_MEM \
    --cloud-init cloud-init.yaml \
    $VERBOSITY
  • Get the VM's IP address

    VM_IP=$(/snap/bin/multipass list |grep "${VM_NAME}" |awk '{print $3}')
  • Connect to the VM via ssh or cli

    ssh:

    ssh -i runner $VM_USER@$VM_IP -o StrictHostKeyChecking=no -vvvv

    CLI:

    multipass shell $VM_NAME
  • Install the runner application

Cleanup

/snap/bin/multipass stop $VM_NAME
/snap/bin/multipass delete $VM_NAME
/snap/bin/multipass purge