Booting the VM

Getting Started with Napatech Link-Virtualization™ Software

Platform
Napatech SmartNIC
Content Type
Getting Started Guide
Capture Software Version
Link-Virtualization™ Software 4.4

About this task

When the installation procedure Building a VM is complete, qemu can be used to boot the VM from the command line as described in this procedure.

Procedure

  1. Start two VMs, each with one virtual channel.
    For example:
    #!/bin/bash
    
    # vmid = 1
    taskset -c 4,6 /opt/qemu/x86_64-softmmu/qemu-system-x86_64 \
     -enable-kvm -cpu host -m 4G -smp 2 \
     -object memory-backend-file,id=mem,size=4G,mem-path=/mnt/huge,share \
     -chardev socket,id=char1,path=/usr/local/var/run/stdvio5,server \
     -netdev type=vhost-user,id=mynet1,chardev=char1 \
     -device virtio-net-pci,netdev=mynet1,mac=52:54:00:00:01:01,rx_queue_size=1024,tx_queue_size=1024 \
     -numa node,memdev=mem -mem-prealloc \
     -net user,hostfwd=tcp::10021-:22 \
     -net nic,macaddr=FE:ED:BE:EF:01:01 \
     -vnc 0:1 -hda /opt/images/vm1.img -snapshot &
    
    # vmid = 2
    taskset -c 8,10 /opt/qemu/x86_64-softmmu/qemu-system-x86_64 \
     -enable-kvm -cpu host -m 4G -smp 2 \
     -object memory-backend-file,id=mem,size=4G,mem-path=/mnt/huge,share \
     -chardev socket,id=char1,path=/usr/local/var/run/stdvio6,server \
     -netdev type=vhost-user,id=mynet1,chardev=char1 \
     -device virtio-net-pci,netdev=mynet1,mac=52:54:00:00:01:02,rx_queue_size=1024,tx_queue_size=1024 \
     -numa node,memdev=mem -mem-prealloc \
     -net user,hostfwd=tcp::10022-:22 \
     -net nic,macaddr=FE:ED:BE:EF:01:02 \
     -vnc 0:2 -hda /opt/images/vm1.img -snapshot &
    The breakdown of this code example is as follows:
    • -chardev socket,id=char0,path=/usr/local/var/run/stdvio<n>,server
      specifies a virtio control socket that is needed to attach to the virtual port, instead of going through OVS. The path is autogenerated.

      <n> is the virtual port number, for example, stdvio5 for port 5, as specified in --vdev=eth_ntvp0,port=5 in the dpdk-extra configuration.

    • -netdev type=vhost-user,id=mynet<i>,chardev=char<i> \
      -device \
       virtio-net-pci,netdev=mynet<i>,mac=<virt_port_MAC_addr>,rx_queue_size=1024,tx_queue_size=1024 \
      sets up the virtual port. virt_port_MAC_address is the MAC of the virtio interface in the VM. Choose a unique value for this MAC address.
    • -net user,hostfwd=tcp::<port>-:22 \
      -net nic,macaddr=<mgmt_port_MAC_addr> \
      This creates a management port and sets up TCP forwarding for ssh access.

      Use ssh localhost -p <port> to connect to the management port of the VM.

      mgmt_port_MAC_address is the MAC of the management port. Choose any unique value for this MAC address.

    • -hda /opt/images/<vm_img> -snapshot
      where vm.img is the name of the VM img that you installed, for example, fedora.img.

      The -snapshot flag creates a temporary snapshot image so you don’t need to create a separate .img file for each VM. Any changes made to the virtual machine while it is running are written to temporary files and deleted when the virtual machine is turned off. No changes are saved to the original .img file.

  2. Add more virtio ports in the VM by specifying the following for each port.
    -chardev socket,id=char<i>,path=/usr/local/var/run/stdvio<n>,server \
    -netdev type=vhost-user,id=mynet<i>,chardev=char<i> \
    -device virtio-net-pci,netdev=mynet<i>,mac=<virt_port_MAC_addr>,rx_queue_size=1024,tx_queue_size=1024 \

    Ensure that the chardev, netdev and mac parameters use different values for the virtio ports in one VM.

    • chardev socket path must be unique for every instance in the same host system
    • mac address must be unique in the L2 broadcast domain
    This is an example script for starting 2 VMs, each with 2 virtio channels.
    #!/bin/bash
    
    # vmid = 1
    taskset -c 4,6 /opt/qemu/x86_64-softmmu/qemu-system-x86_64 \
     -enable-kvm -cpu host -m 4G -smp 2 \
     -object memory-backend-file,id=mem,size=4G,mem-path=/mnt/huge,share \
     -chardev socket,id=char1,path=/usr/local/var/run/stdvio5,server \
     -netdev type=vhost-user,id=mynet1,chardev=char1 \
     -device virtio-net-pci,netdev=mynet1,mac=52:54:00:00:01:01,rx_queue_size=1024,tx_queue_size=1024 \
     -chardev socket,id=char2,path=/usr/local/var/run/stdvio6,server \
     -netdev type=vhost-user,id=mynet2,chardev=char2 \
     -device virtio-net-pci,netdev=mynet2,mac=52:54:00:00:01:02,rx_queue_size=1024,tx_queue_size=1024 \
     -numa node,memdev=mem -mem-prealloc \
     -net user,hostfwd=tcp::10021-:22 \
     -net nic,macaddr=FE:ED:BE:EF:01:01 \
     -vnc 0:1 -hda /opt/images/vm1.img -snapshot &
    
    # vmid = 2
    taskset -c 8,10 /opt/qemu/x86_64-softmmu/qemu-system-x86_64 \
     -enable-kvm -cpu host -m 4G -smp 2 \
     -object memory-backend-file,id=mem,size=4G,mem-path=/mnt/huge,share \
     -chardev socket,id=char1,path=/usr/local/var/run/stdvio7,server \
     -netdev type=vhost-user,id=mynet1,chardev=char1 \
     -device virtio-net-pci,netdev=mynet1,mac=52:54:00:00:01:03,rx_queue_size=1024,tx_queue_size=1024 \
     -chardev socket,id=char2,path=/usr/local/var/run/stdvio8,server \
     -netdev type=vhost-user,id=mynet2,chardev=char2 \
     -device virtio-net-pci,netdev=mynet2,mac=52:54:00:00:01:04,rx_queue_size=1024,tx_queue_size=1024 \
     -numa node,memdev=mem -mem-prealloc \
     -net user,hostfwd=tcp::10022-:22 \
     -net nic,macaddr=FE:ED:BE:EF:01:03 \
     -vnc 0:2 -hda /opt/images/vm1.img -snapshot &