2

i need help about one issue that i cannot understand. I have some virtual machines that runs on an embedded device, i create dynamically one vm and after i start this one for load some parameters inside that. The network take an ip from dhcp server without problem, you can see the qemu command that i use:

qemu-system-aarch64  \
-cpu host \
-machine type=virt \
-enable-kvm \
-nographic \
-smp 1 \
-m 64 \
-serial stdio \
-monitor telnet:127.0.0.1:4448,server,nowait \
-kernel ./Image \
-append 'console=ttyAMA0 earlyprintk=pl011,0x1c090000 loglevel=9 root=/dev/vda rw rootwait' \
-drive file=./rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
-netdev tap,id=eth0,script=no,ifname=tap0 \
-device virtio-net-pci,netdev=eth0,mac=00:16:35:AF:94:00

Before to start the vm i create one tap interface connected to a bridge, where the phisical interface eth0 is also connected to bridge. Everything is working with qemu, but i need to use libvirt to manage the vms and i don't understand how can i use my tap interface with libvirt. I try to use the default bridge which is generated from virtual manager, it's working but libvirt generate a random mac address for the internal interface of vm. And I need to set manually the mac address like qemu command.

angelo93
  • 31
  • 1
  • 4
  • You've not shown what current libvirt XML configuration you've tried to create, so we can't tell you what is still missing. The 'virt-install' command has an "--import" argument to aid in configuring a libvirt guest with a pre-existing disk image that should get you started in the right direction. – DanielB Mar 26 '18 at 09:02

1 Answers1

1

Thank you Daniel, i solved the problems and this is my actually configuration: You have to be sure the /etc/sysctl.conf contains the following lines

net.ipv4.ip_forward = 1
net.ipv4.conf.all.proxy_arp = 1
net.ipv6.conf.all.forwarding = 1

Than i have created new macvtap interface

sudo ip link add link eth0 name macvtap0 type macvtap mode bridge
sudo ip link set macvtap0 address 1a:46:0b:ca:bc:7b up
sudo ip link show macvtap0

Qemu command for x86_64 vm with macvtap network

qemu-system-aarch64  \
 -cpu host \
 -machine type=virt \
 -enable-kvm \
 -nographic \
 -smp 1 \
 -m 64 \
 -serial stdio \
 -monitor telnet:127.0.0.1:4448,server,nowait \
 -kernel ./Image \
 -append 'console=ttyAMA0 earlyprintk=pl011,0x1c090000 loglevel=9 root=/dev/vda rw rootwait' \
 -drive file=./rootfs.ext4,if=none,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 \
 -netdev tap,id=eth0,script=no,ifname=tap9 \
 -device virtio-net-pci,netdev=eth0,mac=00:16:35:AF:94:4B

Where tap9 in my case is the tap that is been created from macvtap interface. So with qemu-kvm it's working. Now I show you the xml that i have created for libvirt

<domain type="kvm">
<name>vmdhcp</name>
<memory unit='KiB'>55200</memory>
<currentMemory unit='KiB'>55200</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
  <type arch='aarch64' machine='virt'>hvm</type>
  <kernel>/var/lib/libvirt/images/Image</kernel>
  <cmdline>root=/dev/vda</cmdline>
  <boot dev='hd'/>
</os>
<cpu mode='custom' match='exact'>
  <model fallback='allow'>host</model>
</cpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
  <emulator>/usr/bin/qemu-system-aarch64</emulator>
  <disk type='file' device='disk'>
    <source file='/var/lib/libvirt/images/rootfs.ext4'/>
    <target dev='vda' bus='virtio'/>
  </disk>
  <interface type='direct'>
    <mac address='00:16:00:7b:4b:8c'/> 
    <source dev='eth0' mode='bridge'/>
    <model type='virtio'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  </interface>
  <serial type='pty'>
    <target port='0'/>
  </serial>
  <console type='pty'>
    <target type='serial' port='0'/>
  </console>
</devices>

With libvirt you don't need to create manually macvtap interfaces, because with this configuration libvirt create automatically one macvtap interface connected to eth0 physical interface, one for each vm running. So, i hope that this explanation is helpful for other users.

angelo93
  • 31
  • 1
  • 4