Install and Use Lima on Apple Silicon(M1) Computers - flomesh-io/osm GitHub Wiki

Install

If you haven't had HomeBrew installed on your computer, please install it first:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then, install Lima

brew install lima

Run VM

Run with Embedded Template

List available templates

Just list all available templates by limactl start --list-templates:

❯ limactl start --list-templates
almalinux
alpine
archlinux
buildkit
debian
default
docker
faasd
fedora
k3s
k8s
nomad
opensuse
oraclelinux
podman
rocky
singularity
ubuntu-lts
ubuntu
vmnet

Start a VM

Then you can choose a template, for example ubuntu-lts, and start it by:

limactl start template://ubuntu-lts

Select Proceed with the current configuration and press Enter key when you see the prompt:

❯ limactl start template://ubuntu-lts
? Creating an instance "ubuntu-lts"  [Use arrows to move, type to filter]
> Proceed with the current configuration
  Open an editor to review or modify the current configuration
  Choose another example (docker, podman, archlinux, fedora, ...)
  Exit

Just waiting for several minutes, it downloads the VM image upon first provisoning:

❯ limactl start template://ubuntu-lts
? Creating an instance "ubuntu-lts" Proceed with the current configuration
INFO[0003] Attempting to download the image from "https://cloud-images.ubuntu.com/releases/20.04/release-20220302/ubuntu-20.04-server-cloudimg-arm64.img"  digest="sha256:fb2b4efdbf0011bd2a9fd49e9d31efdd252966c889f07b5d246351ec5734a329"
INFO[0004] Using cache "/Users/linyang/Library/Caches/lima/download/by-url-sha256/aeaa5e92686f077ffc3e3ea281dd7e52f73ce250176a9923597fd44567bd6735/data"
INFO[0004] Attempting to download the nerdctl archive from "https://github.com/containerd/nerdctl/releases/download/v0.17.1/nerdctl-full-0.17.1-linux-arm64.tar.gz"  digest="sha256:b773a0db178af9d0963b7c84df88ee434e0c1986fe7491dc1de3231e071e3921"
INFO[0004] Using cache "/Users/linyang/Library/Caches/lima/download/by-url-sha256/ec04f07c11877cda079581d4ac1865088c83d3c1e8be89b1adb61756f716ad77/data"
INFO[0005] [hostagent] Starting QEMU (hint: to watch the boot progress, see "/Users/linyang/.lima/ubuntu-lts/serial.log")
INFO[0005] SSH Local Port: 55425
INFO[0005] [hostagent] Waiting for the essential requirement 1 of 5: "ssh"
INFO[0070] [hostagent] The essential requirement 1 of 5 is satisfied
INFO[0070] [hostagent] Waiting for the essential requirement 2 of 5: "user session is ready for ssh"
INFO[0070] [hostagent] The essential requirement 2 of 5 is satisfied
INFO[0070] [hostagent] Waiting for the essential requirement 3 of 5: "sshfs binary to be installed"
INFO[0070] [hostagent] The essential requirement 3 of 5 is satisfied
INFO[0070] [hostagent] Waiting for the essential requirement 4 of 5: "/etc/fuse.conf to contain \"user_allow_other\""
INFO[0074] [hostagent] The essential requirement 4 of 5 is satisfied
INFO[0074] [hostagent] Waiting for the essential requirement 5 of 5: "the guest agent to be running"
INFO[0074] [hostagent] The essential requirement 5 of 5 is satisfied
INFO[0074] [hostagent] Mounting "/Users/linyang"
INFO[0074] [hostagent] Mounting "/tmp/lima"
INFO[0074] [hostagent] Waiting for the optional requirement 1 of 2: "systemd must be available"
INFO[0074] [hostagent] Forwarding "/run/lima-guestagent.sock" (guest) to "/Users/linyang/.lima/ubuntu-lts/ga.sock" (host)
INFO[0074] [hostagent] The optional requirement 1 of 2 is satisfied
INFO[0074] [hostagent] Waiting for the optional requirement 2 of 2: "containerd binaries to be installed"
INFO[0074] [hostagent] Not forwarding TCP 127.0.0.53:53
INFO[0074] [hostagent] Not forwarding TCP 0.0.0.0:22
INFO[0074] [hostagent] Not forwarding TCP [::]:22
INFO[0077] [hostagent] The optional requirement 2 of 2 is satisfied
INFO[0077] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished"
INFO[0087] [hostagent] The final requirement 1 of 1 is satisfied
INFO[0087] READY. Run `limactl shell ubuntu-lts` to open the shell.

Run with Config File

In case you want more control of the VM and install additional software when starting the VM, you can achieve it by creating a config file.

Create VM Config

Before starting a Lima VM, you need to create a config file, the following is an example of Ubuntu 20.04, copy and save it to a file named ubuntu.yaml in home directory:

# This example requires Lima v0.7.0 or later.

# ===================================================================== #
# BASIC CONFIGURATION
# ===================================================================== #

# Arch: "default", "x86_64", "aarch64".
# "default" corresponds to the host architecture.
arch: "default"

# An image must support systemd and cloud-init.
# Ubuntu and Fedora are known to work.
# Image is set to focal (20.04 LTS) for long-term stability
# Default: none (must be specified)
images:
  # Try to use a local image first.
  - location: "~/Downloads/ubuntu-20.04-server-cloudimg-amd64.img"
    arch: "x86_64"
  - location: "~/Downloads/ubuntu-20.04-server-cloudimg-arm64.img"
    arch: "aarch64"

  # Download the file from the internet when the local file is missing.
  # Hint: run `limactl prune` to invalidate the "current" cache
  - location: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img"
    arch: "x86_64"
  - location: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-arm64.img"
    arch: "aarch64"

# CPUs: if you see performance issues, try limiting cpus to 1.
# Default: 4
cpus: 4

# Memory size
# Default: "4GiB"
memory: "8GiB"

# Disk size
# Default: "100GiB"
disk: "80GiB"

# Expose host directories to the guest, the mount point might be accessible from all UIDs in the guest
# Default: none
mounts:
  - location: "~"
    # CAUTION: `writable` SHOULD be false for the home directory.
    # Setting `writable` to true is possible, but untested and dangerous.
    writable: false
  - location: "/tmp/lima"
    writable: true

ssh:
  # A localhost port of the host. Forwarded to port 22 of the guest.
  # Default: 0 (automatically assigned to a free port)
  localPort: 0
  # Load ~/.ssh/*.pub in addition to $LIMA_HOME/_config/user.pub .
  # This option is useful when you want to use other SSH-based
  # applications such as rsync with the Lima instance.
  # If you have an insecure key under ~/.ssh, do not use this option.
  # Default: true
  loadDotSSHPubKeys: true
  # Forward ssh agent into the instance.
  # Default: false
  forwardAgent: false

# containerd is managed by k3s, not by Lima, so the values are set to false here.
containerd:
  system: false
  user: false

Start VM

New VM

Run the VM with the config just created:

limactl start ~/ubuntu.yaml

You'll see something like this:

❯ limactl start ~/ubuntu.yaml
? Creating an instance "ubuntu"  [Use arrows to move, type to filter]
> Proceed with the current configuration
  Open an editor to review or modify the current configuration
  Choose another example (docker, podman, archlinux, fedora, ...)
  Exit

Just select Proceed with the current configuration and press Enter key. Wait for provisioning the VM:

❯ limactl start ~/ubuntu.yaml
? Creating an instance "ubuntu" Proceed with the current configuration
INFO[0213] Attempting to download the image from "~/Downloads/focal-server-cloudimg-arm64.img"  digest=
INFO[0213] Attempting to download the image from "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img"  digest=
INFO[0214] Using cache "/Users/linyang/Library/Caches/lima/download/by-url-sha256/ae20df823d41d1dd300f8866889804ab25fb8689c1a68da6b13dd60a8c5c9e35/data"
INFO[0214] [hostagent] Starting QEMU (hint: to watch the boot progress, see "/Users/linyang/.lima/ubuntu/serial.log")
INFO[0215] SSH Local Port: 54057
INFO[0215] [hostagent] Waiting for the essential requirement 1 of 5: "ssh"
INFO[0261] [hostagent] The essential requirement 1 of 5 is satisfied
INFO[0261] [hostagent] Waiting for the essential requirement 2 of 5: "user session is ready for ssh"
INFO[0261] [hostagent] The essential requirement 2 of 5 is satisfied
INFO[0261] [hostagent] Waiting for the essential requirement 3 of 5: "sshfs binary to be installed"
INFO[0267] [hostagent] The essential requirement 3 of 5 is satisfied
INFO[0267] [hostagent] Waiting for the essential requirement 4 of 5: "/etc/fuse.conf to contain \"user_allow_other\""
INFO[0270] [hostagent] The essential requirement 4 of 5 is satisfied
INFO[0270] [hostagent] Waiting for the essential requirement 5 of 5: "the guest agent to be running"
INFO[0270] [hostagent] The essential requirement 5 of 5 is satisfied
INFO[0270] [hostagent] Mounting "/Users/linyang"
INFO[0271] [hostagent] Mounting "/tmp/lima"
INFO[0271] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished"
INFO[0271] [hostagent] Forwarding "/run/lima-guestagent.sock" (guest) to "/Users/linyang/.lima/ubuntu/ga.sock" (host)
INFO[0271] [hostagent] The final requirement 1 of 1 is satisfied
INFO[0271] READY. Run `limactl shell ubuntu` to open the shell.

Existing VM

Please remember by default the name of config file is the name of VM, so we can start an existing stopped VM by name:

limactl start ubuntu

SSH to VM

Just ssh to the VM by name:

limactl shell ubuntu

You'll see the prompt:

❯ limactl shell ubuntu
linyang@lima-ubuntu:/Users/linyang$
linyang@lima-ubuntu:/Users/linyang$ uname -a
Linux lima-ubuntu 5.4.0-104-generic #118-Ubuntu SMP Wed Mar 2 19:03:41 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux

Then you're ready to use the VM or install any other software.

Stop VM

Exit to host machine:

linyang@lima-ubuntu:/Users/linyang$ exit
logout

Then stop the VM by:

limactl stop ubuntu

The output is like below:

❯ limactl stop ubuntu
INFO[0000] Sending SIGINT to hostagent process 6885
INFO[0000] Waiting for the host agent and the qemu processes to shut down
INFO[0000] [hostagent] Received SIGINT, shutting down the host agent
INFO[0000] [hostagent] Shutting down the host agent
INFO[0000] [hostagent] Stopping forwarding "/run/lima-guestagent.sock" (guest) to "/Users/linyang/.lima/ubuntu/ga.sock" (host)
INFO[0000] [hostagent] Unmounting "/Users/linyang"
INFO[0000] [hostagent] Unmounting "/tmp/lima"
INFO[0000] [hostagent] Shutting down QEMU with ACPI
INFO[0000] [hostagent] Sending QMP system_powerdown command
INFO[0000] [hostagent] QEMU has exited

Delete VM

It's pretty simple:

limactl delete ubuntu

You'll see it's destroyed and deleted:

❯ limactl delete ubuntu
INFO[0000] The QEMU process seems already stopped
INFO[0000] The host agent process seems already stopped
INFO[0000] Removing *.pid *.sock under "/Users/linyang/.lima/ubuntu"
INFO[0000] Removing "/Users/linyang/.lima/ubuntu/ha.sock"
INFO[0000] Deleted "ubuntu" ("/Users/linyang/.lima/ubuntu")

More Examples

There's more examples of Lime template in the examples folder, please refer to it if you want to create other VMs.