超簡單就可以直接在 M1 上有類似 WSL 體驗的 x86_64 Ubuntu , Lima 是透過 QEMU 進行執行的,所以嚴格來說他是一種虛擬機,不太像 WSL 是微軟大大的黑魔法。
安裝
brew install lima
準備一個 Yaml,這邊我是直接抄官方的 Example,並修改,增加第一行的 arch,根據官方文件表示,增加 arch 就能直接指定 CPU 型態
arch: "x86_64"
images:
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220712/ubuntu-22.04-server-cloudimg-amd64.img"
arch: "x86_64"
digest: "sha256:86481acb9dbd62e3e93b49eb19a40c66c8aa07f07eff10af20ddf355a317e29f"
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20220712/ubuntu-22.04-server-cloudimg-arm64.img"
arch: "aarch64"
digest: "sha256:e1ce033239f0038dca5ef09e582762ba0d0dfdedc1d329bc51bb0e9f5057af9d"
# Fallback to the latest release image.
# Hint: run `limactl prune` to invalidate the cache
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-arm64.img"
arch: "aarch64"
mounts:
- location: "~"
- location: "/tmp/lima"
writable: true
Build 環境
這邊的 ./ubuntu.yaml 就是前面準備的內容,而 –name 則是帶之後要給他的名字
limactl start ./ubuntu.yaml --name ubuntu-amd64
並選擇 “Proceed with the current configuration”
使用
limactl shell ubuntu-amd64 # 進入 Shell
limactl stop ubuntu-amd64 # 關閉機器
limactl delete ubuntu-amd64 # 刪除機器