Lima运行Alpine Linux虚拟机

警告

我暂时没有解决如何在lima中运行 Alpine Linux ,也许我的操作系统确实太陈旧了,运行lima存在什么问题

待后续再排查

目前暂时改为采用 Rancher Desktop (同样基于 Lima 的企业级工具,类似 Docker Desktop )

实践是在古老的 MacBook Pro 15" Late 2013 完成,由于是早期的 x86_64 系统,不支持最新的 vz - Apple Virtualization.framework 的Go实现 ,所以需要通过 MacPorts 安装 QEMU ( MacPorts安装旧版本qemu )。

备注

虽然 Apple Virtualizationvz - Apple Virtualization.framework 的Go实现 性能更好,但是需要满足 macOS 13 才能激活,受限于我的笔记本操作系统(macOS Big Sur 11.7.10),所以只能退而求其次使用 QEMU

创建虚拟机

  • 创建 QEMU 类型虚拟机:

备注

Lima Templates 是官方提供的安装模版,包含了 Alpine Linux 可以直接使用。对于官方没有提供的模版,例如 FreeBSD 也可以通过修改现有模版来满足要求,例如 Lima运行FreeBSD虚拟机

创建alpine linux虚拟机
limactl create --name=ldev --vm-type=qemu template://alpine
  • 启动创建的虚拟机:

启动alpine linux虚拟机
limactl start ldev

这里遇到报错信息:

启动alpine linux虚拟机
INFO[0000] Using the existing instance "ldev"
INFO[0000] Starting the instance "ldev" with VM driver "qemu"
INFO[0001] [hostagent] hostagent socket created at /Users/admin/.lima/ldev/ha.sock
INFO[0002] [hostagent] Using system firmware ("/opt/local/share/qemu/edk2-x86_64-code.fd")
INFO[0002] [hostagent] Starting QEMU (hint: to watch the boot progress, see "/Users/admin/.lima/ldev/serial*.log")
INFO[0003] SSH Local Port: 64611
INFO[0002] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0090] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0179] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0267] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0357] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0446] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
INFO[0534] [hostagent] Waiting for the essential requirement 1 of 2: "ssh"
FATA[0600] did not receive an event with the "running" status

备注

上述报错看起来是虚拟机内部没有运行ssh服务,导致 limactl 无法创建ssh连接导致

怎么改正?

但是,执行 ps aux | grep qemu 却发现当前实际上是有qemu进程运行的:

当前进程存在qemu
admin            28052   0.4  0.2  8680904  36348 s000  S     9:36pm   0:05.31 /opt/local/bin/qemu-system-x86_64 -m 4096 -cpu host,-avx512vl,-pdpe1gb -machine q35,accel=hvf -smp 4,sockets=1,cores=4,threads=1 ...

此时执行 limactl list 检查,也能够看到正在运行的 ldev :

当前有 ldev 虚拟机运行
NAME    STATUS     SSH                VMTYPE    ARCH      CPUS    MEMORY    DISK      DIR
ldev    Running    127.0.0.1:64611    qemu      x86_64    4       4GiB      100GiB    ~/.lima/ldev
  • 安装 socat 来连接 ~/.lima/ldev/serial.sock ,查看控制台输出:

安装 socat
sudo port install socat
  • 连接控制台:

连接 serial.sock
socat -,echo=0,icanon=0 unix-connect:/Users/admin/.lima/ldev/serial.sock

但是当前没有任何输出信息

使用

待续...