This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Examples

Running Linux commands

lima sudo apt-get install -y neofetch
lima neofetch

Accessing host files

By default, the VM has read-only accesses to /Users/<USERNAME> and read-write accesses to /tmp/lima.

To allow writing to /Users/<USERNAME>:

limactl edit --mount-writable --mount-type=virtiofs

Specifying --mount-type=virtiofs is not necessary here, but it is highly recommended for the best performance and stability.

Running containers

nerdctl.lima run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine
limactl start template://docker
export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock')
docker run -d --name nginx -p 127.0.0.1:8080:80 nginx:alpine
limactl start template://k8s
export KUBECONFIG=$(limactl list k8s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
kubectl apply -f ...

Advanced configuration

limactl start \
  --name=default \
  --cpus=4 \
  --memory=8 \
  --vm-type=vz \
  --rosetta \
  --mount-type=virtiofs \
  --mount-writable \
  --network=vzNAT \
  template://fedora
  • --name=default: Set the instance name to “default”
  • --cpus=4: Set the number of the CPUs to 4
  • --memory=8: Set the amount of the memory to 8 GiB
  • --vm-type=vz: Use Apple’s Virtualization.framework (vz) to enable Rosetta, virtiofs, and vzNAT
  • --rosetta: Allow running Intel (AMD) binaries on ARM
  • --mount-type=virtiofs: Use virtiofs for better performance
  • --mount-writable: Make the home mount (/Users/<USERNAME>) writable
  • --network=vzNAT: Make the VM reachable from the host by its IP address
  • template://fedora: Use Fedora

1 - GitHub Actions

Running Lima on GitHub Actions

On GitHub Actions, Lima is useful for:

  • Running commands on non-Ubuntu operating systems (e.g., Fedora for testing SELinux)
  • Emulating multiple hosts

While these tasks can be partially accomplished with containers like Docker, those containers still rely on the Ubuntu host’s kernel and cannot utilize features missing in Ubuntu, such as SELinux.

In contrast, Lima runs virtual machines that do not depend on the Ubuntu host’s kernel.

The following GitHub Actions workflow illustrates how to run multiple instances of Fedora using Lima. The instances are connected by the user-v2 network.

name: Fedora

on:
  workflow_dispatch:
  pull_request:

jobs:
  fedora:
    runs-on: ubuntu-24.04
    steps:
    - name: Check out code
      uses: actions/checkout@v4

    - name: "Install QEMU"
      run: |
        set -eux
        sudo apt-get update
        sudo apt-get install -y --no-install-recommends ovmf qemu-system-x86 qemu-utils
        sudo modprobe kvm
        # `sudo usermod -aG kvm $(whoami)` does not take an effect on GHA
        sudo chown $(whoami) /dev/kvm        

    - name: "Install Lima"
      env:
        GITHUB_TOKEN: ${{ github.token }}  # required by `gh attestation verify`
      run: |
        set -eux
        LIMA_VERSION=$(curl -fsSL https://api.github.com/repos/lima-vm/lima/releases/latest | jq -r .tag_name)
        FILE="lima-${LIMA_VERSION:1}-Linux-x86_64.tar.gz"
        curl -fOSL https://github.com/lima-vm/lima/releases/download/${LIMA_VERSION}/${FILE}
        gh attestation verify --owner=lima-vm "${FILE}"
        sudo tar Cxzvf /usr/local "${FILE}"
        rm -f "${FILE}"        

    - name: "Cache ~/.cache/lima"
      uses: actions/cache@v4
      with:
        path: ~/.cache/lima
        key: lima-${{ env.LIMA_VERSION }}

    - name: "Start an instance of Fedora"
      run: |
        set -eux
        limactl start --name=default --cpus=1 --memory=1 --network=lima:user-v2 template://fedora
        lima sudo dnf install -y httpd
        lima sudo systemctl enable --now httpd        

    - name: "Start another instance of Fedora"
      run: |
        set -eux
        limactl start --name=another --cpus=1 --memory=1 --network=lima:user-v2 template://fedora
        limactl shell another curl http://lima-default.internal        

Plain mode

The --plain mode is useful when you want the VM instance to be as close as possible to a physical host:

    - name: "Start Fedora"
      # --plain is set to disable file sharing, port forwarding, built-in containerd, etc.
      run: limactl start --plain --name=default --cpus=1 --memory=1 --network=lima:user-v2 template://fedora

    - name: "Initialize Fedora"
      # plain old rsync and ssh are used for the initialization of the guest,
      # so that people who are not familiar with Lima can understand the initialization steps.
      run: |
        set -eux -o pipefail
        # Initialize SSH
        mkdir -p -m 0700 ~/.ssh
        cat ~/.lima/default/ssh.config >> ~/.ssh/config
        # Sync the current directory to /tmp/repo in the guest
        rsync -a -e ssh . lima-default:/tmp/repo
        # Install packages
        ssh lima-default sudo dnf install -y httpd        

Full examples