1. 前端使用virtio-net驅動,后端是tap設備,vhost-net方式。這樣VM啟動后,主機上ifconfig可以查到tap0接口,如果想要VM動態獲取IP需要主機上將tap0接口添加到virbr0網橋上,即運行sudo brctl addif virbr0 tap0
sudo qemu-system-x86_64 -enable-kvm -kernel ./bzImage -hda ./intel-x86-64-rootfs.ext4 -m 2048 -nographic -netdev tap,id=hn2,br=virbr0,vhost=on -device virtio-net,netdev=hn2 \
-append "console=ttyS0,115200 ip=dhcp root=/dev/sda init=/sbin/init clock=pit oprofile.timer=1 UMA=1"
2.#e1000 as front-end connect to backend of type tap, backend with id hn2.
sudo qemu-system-x86_64 -nographic -netdev tap,id=hn2 -device e1000,netdev=hn2 -drive format=raw,file=xx.img
3.#boot from nfs
sudo kvm -kernel ./bzImage -m 2048 -netdev tap,id=hn2 -device e1000,netdev=hn2,mac=11:22:33:44:55:66 -nographic -append "console=ttyS0,115200 root=/dev/nfs nfsroot=127.0.0.1:/home/${USER}/nfs-server-qemu init=/sbin/init"