![在 QEmu 中识别 virtio2 和 virtio3 等设备](https://linux22.com/image/124655/%E5%9C%A8%20QEmu%20%E4%B8%AD%E8%AF%86%E5%88%AB%20virtio2%20%E5%92%8C%20virtio3%20%E7%AD%89%E8%AE%BE%E5%A4%87.png)
我正在 QEmu 中运行虚拟机。来宾虚拟机中的以下命令
cat /proc/interrupts | egrep 'virtio.*(input|output)'
给出以下输出:
26: 0 3376 0 0 0 0 0 0 PCI-MSI-edge virtio2-input
27: 0 1 0 0 0 0 0 0 PCI-MSI-edge virtio2-output
29: 0 3368 0 0 0 0 0 0 PCI-MSI-edge virtio3-input
30: 0 2 0 0 0 0 0 0 PCI-MSI-edge virtio3-output
32: 0 3490 0 0 0 0 0 0 PCI-MSI-edge virtio4-input
33: 0 1 0 0 0 0 0 0 PCI-MSI-edge virtio4-output
35: 0 4995 0 0 0 0 0 0 PCI-MSI-edge virtio5-input
36: 0 1 0 0 0 0 0 0 PCI-MSI-edge virtio5-output
38: 0 1818743 0 0 0 0 0 0 PCI-MSI-edge virtio6-input
39: 0 1 0 0 0 0 0 0 PCI-MSI-edge virtio6-output
41: 0 1822784 0 0 0 0 0 0 PCI-MSI-edge virtio7-input
42: 0 1 0 0 0 0 0 0 PCI-MSI-edge virtio7-output
44: 0 2470 0 0 0 0 0 0 PCI-MSI-edge virtio8-input
45: 0 0 2 0 0 0 0 0 PCI-MSI-edge virtio8-output
47: 0 0 94 0 0 0 0 0 PCI-MSI-edge virtio9-input
48: 0 0 1 0 0 0 0 0 PCI-MSI-edge virtio9-output
virtio2
...virtio9
好像是8块网卡。但是,我无法弄清楚其中哪一个对应于哪张卡。有没有办法获取 MAC 地址virtio3
,或者以其他方式识别网卡?
答案1
我有一个方法(前几次在另一个论坛上采取过)
# vm mac address list
for vm in $(virsh list | grep running | awk '{print $2}'); do \
echo -n "$vm "; \
virsh dumpxml $vm| grep -oP "52:54:[\da-f:]+" ;
done > vm_mac.list
# vm ip list
arp -i virbr0 | grep '52:' | while read addr ; do \
ip=$(echo $addr | awk '{print $1}'); \
mac=$(echo $addr | awk '{print $3}'); \
vm=$(grep "$mac" vm_mac.list | awk '{print $1}'); \
echo "$vm $ip $mac"; \
done | sort