tap设备创建

$ ip tuntap add dev tap1 mod tap
$ ip tuntap add dev tap2 mod tap
$ ifconfig tap1 up
$ ifconfig tap2 up

bridge设备创建

$ brctl addbr br0
$ ifconfig br0 up
$ brctl addif br0 tap1
$ brctl addif br0 tap2

qemu 启动 linux 内核

这里内核可参照编译AARCH64 LINUX内核并基于QEMU运行中的方法编译。

# start the first qemu
$ qemu-system-aarch64 -machine virt -cpu cortex-a57 \
        -machine type=virt -nographic -smp 1 \
        -m 2048 \
        -kernel ./arch/arm64/boot/Image \
        --append "console=ttyAMA0" \
        -netdev tap,id=mynet1,script=no,downscript=no,ifname=tap1 \
        -device virtio-net-device,netdev=mynet1,mac=xx:xx:xx:xx:xx:xx,mrg_rxbuf=off,csum=off,guest_csum=off,gso=off,guest_tso4=off,guest_tso6=off,guest_ecn=off,guest_ufo=off \
        $1 $2

# start the second qemu
$ qemu-system-aarch64 -machine virt -cpu cortex-a57 \
        -machine type=virt -nographic -smp 1 \
        -m 2048 \
        -kernel ./arch/arm64/boot/Image \
        --append "console=ttyAMA0" \
        -netdev tap,id=mynet2,script=no,downscript=no,ifname=tap2 \
        -device virtio-net-device,netdev=mynet2,mac=xx:xx:xx:xx:xx:xx,mrg_rxbuf=off,csum=off,guest_csum=off,gso=off,guest_tso4=off,guest_tso6=off,guest_ecn=off,guest_ufo=off \
        $1 $2

网络测试

$ ifconfig eth0 xxx.xxx.xxx.xxx # 对两个虚拟机,都配置好 ip
$ ping xxx.xxx.xxx.xxx

参考文档