Lima虚拟机初体验二

本文最后更新于 1245 天前, 如有失效请评论区留言.

接上文 Lima 虚拟机初体验一在 M1 上玩转 Lima

快速开始

M1 系统信息

# brew install m-cli
➜  ~ m info
ProductName:	macOS
ProductVersion:	11.5.2
BuildVersion:	20G95

m1 patch

# 安装构建依赖
brew update
brew install libffi gettext glib pkg-config autoconf automake pixman ninja
# 下载源码
git clone https://github.com/qemu/qemu
cd qemu
git checkout 3c93dfa42c394fdd55684f2fbf24cf2f39b97d47
curl https://patchwork.kernel.org/series/485309/mbox/ | git am
# build
mkdir build && cd build
../configure --target-list=aarch64-softmmu --enable-hvf --disable-gnutls
make -j8 
# 安装
sudo make install

注意一点:

可能通过 brew 安装的 qemu,会识别默认该路径下的 /opt/homebrew/bin/qemu-system-aarch64, 而 patch 生成的则在 /usr/local/bin/qemu-system-aarch64

rm /opt/homebrew/bin/qemu-system-aarch64

测试 patch

wget https://mirrors.tuna.tsinghua.edu.cn/debian-cd/current/arm64/iso-cd/debian-11.0.0-arm64-netinst.iso

qemu-img create -f qcow2 virtual-disk.qcow2 8G

cp $(dirname $(which qemu-img))/../share/qemu/edk2-aarch64-code.fd .

dd if=/dev/zero conv=sync bs=1m count=64 of=ovmf_vars.fd

/usr/local/bin/qemu-system-aarch64 \
  -machine virt,accel=hvf,highmem=off \
  -cpu cortex-a72 -smp 4 -m 4G \
  -device virtio-gpu-pci \
  -device virtio-keyboard-pci \
  -drive "format=raw,file=edk2-aarch64-code.fd,if=pflash,readonly=on" \
  -drive "format=raw,file=ovmf_vars.fd,if=pflash" \
  -drive "format=qcow2,file=virtual-disk.qcow2" \
  -cdrom debian-11.0.0-arm64-netinst.iso

成功启动虚拟机表示 patch 成功了,可以通过 lima 启动管理虚拟机了

安装 Lima 并启动

安装 lima

brew install lima

启动 lima

# 下载专用debian配置
wget https://sh.ysicing.me/lima/debian.yml
# 启动debian虚拟机
limactl start ./debian.yml

附录阅读

Sponsor

Like this article? $1 reward

Comments