QEMU Aarch64 和网络连接

QEMU Aarch64 和网络连接

我刚刚使用 QEMU 设置了 ARM64 映像,并尝试从二进制文件中访问互联网。主机操作系统(Ubuntu)从eth0接口接收互联网。我已经tap0设置好界面了我已将tap0和添加eth0virbr0.

$ brctl show virbr0
bridge name bridge id       STP enabled interfaces
virbr0      8000.080027c9997e   yes     eth0
                                        tap0

现在,我尝试按如下方式启动虚拟机:-

sudo qemu-system-aarch64 -machine virt -cpu cortex-a57 -nographic -smp 1 -m 512 \
    -global virtio-blk-device.scsi=off -device virtio-scsi-device,id=scsi \
    -drive file=ubuntu-core-14.04.1-core-arm64.img,id=coreimg,cache=unsafe,if=none -device scsi-hd,drive=coreimg \
    -kernel vmlinuz-3.13.0-55-generic \
    -initrd initrd.img-3.13.0-55-generic \
    -netdev user,id=unet -device virtio-net-device,netdev=unet \
    -net nic -net tap,ifname=tap0,script=no,downscript=no \
    --append "console=ttyAMA0 root=/dev/sda"

主机上 ifconfig 的输出如下:-

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:c9:99:7e
          inet6 addr: fe80::a00:27ff:fec9:997e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2942 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7889 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:239227 (239.2 KB)  TX bytes:557156 (557.1 KB)

tap0      Link encap:Ethernet  HWaddr 8e:3d:c3:0e:58:36
          inet6 addr: fe80::8c3d:c3ff:fe0e:5836/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:412 errors:0 dropped:427 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:0 (0.0 B)  TX bytes:21432 (21.4 KB)

virbr0    Link encap:Ethernet  HWaddr 08:00:27:c9:99:7e
          inet addr:10.0.2.15  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2928 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2940 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:195163 (195.1 KB)  TX bytes:236587 (236.5 KB)

启动虚拟机后,ifconfig 的输出如下。

root@localhost:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:57
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fe12:3457/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:846 (846.0 B)  TX bytes:3320 (3.3 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

但是,我似乎无法 ping 任何远程地址(例如:8.8.8.8)。为什么会发生这种情况?我怎样才能解决这个问题?

[编辑] 启动虚拟机时,我收到以下警告。

W: /etc/qemu-ifup: no bridge for guest interface found
Warning: hub port hub0port0 has no peer
Warning: vlan 0 with no nics
Warning: netdev hub0port0 has no peer
Warning: requested NIC (anonymous, model unspecified) was not created (not supported by this machine?)

答案1

当我使用过时的选项时,我收到了相同的警告-net。然后我把它改成了这样:

-netdev tap,ifname=tap0,script=no,downscript=no,id=my_net_id \
-device driver=virtio-net,netdev=my_net_id

它解决了问题。

相关内容