Skip to content

Instantly share code, notes, and snippets.

@khenidak
Last active October 15, 2018 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khenidak/0d219019532f883800bb9e4ba6b45a1e to your computer and use it in GitHub Desktop.
Save khenidak/0d219019532f883800bb9e4ba6b45a1e to your computer and use it in GitHub Desktop.
kernel dev network (virsh based). and sample qemu vm on it
<network>
<name>kernel-net</name>
<uuid>5618453a-d6af-42f5-b77d-eb1727371b73</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='kerneldevbr0' stp='on' delay='0'/>
<mac address='42:ef:c9:0b:a4:f1'/>
<ip address='192.168.124.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.124.2' end='192.168.124.254'/>
</dhcp>
</ip>
</network>
# create the above network with `virsh net-create ./network.xml`
# Generating mac here. in reality you probably want to use static mac
# if you want to assign static ip for discovery
# check: https://libvirt.org/formatnetwork.html
sudo qemu-system-x86_64 \
-smp 4 \
-m 8192 \
-enable-kvm
-nographic \
--drive file=${IMG_DISK},if=virtio,cache=writethrough,index=0 \
--netdev bridge,br=kerneldevbr0,id=deb001 --device virtio-net-pci,netdev=deb001,id=nicdeb001,mac=$(printf '52-54-00-%02X-%02X-%02X\n' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]) \
-append ' root=/dev/vda console=ttyS0' \
-kernel ./vmlinuz-4.4.0-127-generic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment