我正在尝试在我的 macOS Catalina 10.15.1 机器上使用 QEMU ARM 模拟器模拟 Raspberry Pi。主要遵循本指南我一直在使用最新的 Raspbian Lite (4.19 Buster) 和 buster 内核这个 GitHub 仓库。为了在我的 macOS 主机上实现虚拟网络,我安装了通塔普。这给了我一个 /dev/tap0 上的虚拟网络接口。我一直用这个命令运行 pi:
sudo qemu-system-arm \
-kernel kernel-qemu-4.19.50-buster \
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
-hda raspbian-buster-lite.qcow \
-cpu arm1176 -m 256 \
-M versatilepb -dtb versatile-pb.dtb \
-no-reboot -serial stdio \
-net nic -net user \
-net tap,ifname=tap0,script=no,downscript=no \
-netdev user,id=tap0,hostfwd=tcp::5555-:22 \
-device e1000,mac=00:00:ab:c9:df:03
上述命令成功启动了 pi,但奇怪的是它没有任何互联网功能。我在 /etc/hosts 中添加了 8.8.8.8 作为名称服务器。如果我 ping google.com,它似乎能够解析主机名,但它会无限期挂起,直到我按 Ctrl+C 退出:
pi@raspberrypi:~$ ping google.com
PING google.com (172.217.4.206) 56(84) bytes of data.
启动服务后,我尝试从主机通过 ssh 登陆(使用sudo service ssh start
),结果如下:
$ ssh -v 10.0.2.15 -p 5555
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/redacted/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: Connecting to 10.0.2.15 [10.0.2.15] port 5555.
debug1: Connection established.
debug1: identity file /Users/redacted/.ssh/id_rsa type 0
debug1: identity file /Users/redacted/.ssh/id_rsa-cert type -1
debug1: identity file /Users/redacted/.ssh/id_dsa type -1
debug1: identity file /Users/redacted/.ssh/id_dsa-cert type -1
debug1: identity file /Users/redacted/.ssh/id_ecdsa type -1
debug1: identity file /Users/redacted/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/redacted/.ssh/id_ed25519 type -1
debug1: identity file /Users/redacted/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/redacted/.ssh/id_xmss type -1
debug1: identity file /Users/redacted/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
ssh_exchange_identification: read: Connection reset by peer
在谷歌上搜索该问题后,我发现了线索这里,这里, 和这里,但我运气不佳,因为我在 RPI 上的系统配置文件基本上是默认的,而我的 macOS 主机在创建桥接方面很困难。我一直在与QEMU 维基了解一下情况,但我还没能从这一点继续前进。你们知道怎么解决这个问题吗?
答案1
对我有用的命令如下(在 Debian 10 上):
sudo qemu-system-arm \
-machine versatilepb \
-cpu arm1176 \
-m 256 \
-dtb ~/qemu-rpi-kernel/versatile-pb-buster.dtb \
-kernel ~/qemu-rpi-kernel/kernel-qemu-4.19.50-buster \
-append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' \
-no-reboot \
-serial stdio \
-net nic \
-net user,hostfwd=tcp::5022-:22 \
-net tap,ifname=vnet0,script=no,downscript=no \
-drive format=raw,file=qemu.img
准备: