Intel-on-ARM / ARM-on-Intel
Lima 支持几种运行 Intel-on-ARM 和 ARM-on-Intel 的模式:
慢速模式:ARM 主机上的 Intel VM / Intel 主机上的 ARM VM
| ⚡ Requirement | QEMU, lima-additional-guestagents |
|---|
Lima can run a VM with a foreign architecture, using QEMU.
For port forwarding, the lima-additional-guestagents package has to be installed on the host.
An example configuration:
limactl start --vm-type=qemu --arch=x86_64 --plain
See the YAML tab for the explanation of the corresponding CLI flags.
# Starting with Lima v2.0, `vmType` has to be expclitly set to "qemu" on non-Linux hosts.
vmType: "qemu"
# Supported architectures:
# Non-experimental: aarch64, x86_64
# Experimental: armv7l, ppc64le, riscv64, s390x
#
# containerd is not automatically installed for the experimental architectures.
arch: "x86_64"
# A slow host may need `plain` to disable mounts, port forwards, and containerd, so as to avoid timeout.
plain: true
base:
- template://_images/ubuntu
Running a VM with a foreign architecture is extremely slow. Consider using Fast mode or Fast mode 2 whenever possible.
快速模式:ARM 主机上的 ARM VM 上的 Intel 容器 / Intel 主机上的 Intel VM 上的 ARM 容器
此模式使用 QEMU 用户模式仿真。 QEMU 用户模式仿真明显比 QEMU 系统模式仿真快,但它通常牺牲兼容性。
设置:
lima sudo systemctl start containerd
lima sudo nerdctl run --privileged --rm tonistiigi/binfmt:qemu-v10.0.4-56@sha256:30cc9a4d03765acac9be2ed0afc23af1ad018aed2c28ea4be8c2eb9afe03fbd1 --install all
运行容器:
$ lima nerdctl run --platform=amd64 --rm alpine uname -m
x86_64
$ lima nerdctl run --platform=arm64 --rm alpine uname -m
aarch64
构建和推送容器镜像:
lima nerdctl build --platform=amd64,arm64 -t example.com/foo:latest .
lima nerdctl push --all-platforms example.com/foo:latest
另请参阅 https://github.com/containerd/nerdctl/blob/main/docs/multi-platform.md
快速模式 2 (Rosetta):ARM 主机上的 ARM VM 上的 Intel 容器
| ⚡ 要求 | Lima >= 0.14, macOS >= 13.0, ARM |
|---|
众所周知,Rosetta 比 QEMU 用户模式仿真快得多。 Rosetta 可用于 ARM 主机上的 VZ 实例。
limactl start --vm-type=vz --rosetta
vmType: "vz"
rosetta:
# 为 Linux 启用 Rosetta。
# 提示:如果 Lima 卡在 `Installing rosetta...`,请尝试 `softwareupdate --install-rosetta`
enabled: true
# 将 rosetta 注册到 /proc/sys/fs/binfmt_misc
binfmt: true
使用 CDI 规范启用 Rosetta AOT 缓存
| ⚡ 要求 | Lima >= 2.0, macOS >= 14.0, ARM |
|---|
Rosetta AOT 缓存通过保存翻译后的二进制文件来加速容器,这样它们就不需要再次翻译。 了解更多:WWDC2023 视频
如何使用 Rosetta AOT 缓存:
运行容器:
在你的docker run命令中添加--device=lima-vm.io/rosetta=cached:docker run --platform=linux/amd64 --device=lima-vm.io/rosetta=cached ...构建镜像:
在你的 Dockerfile 顶部添加# syntax=docker/dockerfile:1-labs以启用--device选项。 在你的RUN命令中使用--device=lima-vm.io/rosetta=cached:# syntax=docker/dockerfile:1-labs FROM ... ... RUN --device=lima-vm.io/rosetta=cached <your amd64 command>检查缓存是否工作:
在 VM 中查找缓存文件:limactl shell {{.Name}} ls -la /var/cache/rosettad docker run --platform linux/amd64 --device=lima-vm.io/rosetta=cached ubuntu echo hello limactl shell {{.Name}} ls -la /var/cache/rosettad # 你应该在这里看到 *.aotcache 文件检查 Docker 是否识别 CDI 设备:
在docker info的输出中查找 CDI 信息:docker info ... CDI spec directories: /etc/cdi /var/run/cdi Discovered Devices: cdi: lima-vm.io/rosetta=cached了解更多关于 CDI 的信息:
CDI 规范文档