How to run SONiC VS in KVM?

[stordis-toc]

Prerequisites

Downloaded SONiC image (Where to download the SONiC Virtual Switch (VS) community pre-built image? – STORDIS Support Portal)

 

Step 1: KVM installation on Ubuntu

Login on Ubuntu Server and install essential packages: 

sudo apt update sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager 

Check if KVM is active: 

kvm-ok # 

You should see:

"INFO: /dev/kvm exists" 

 

Step 2: Network configuration (Bridges) 

You need minimum 2 bridges (file /etc/netplan/*.yaml): 

br0 (Management): Connected with Ubuntu network card (access to real network). 

br1 (Internal): Isolated bridge for internal network (V-Lab). 

Configuration excample for Netplan: 

network: 
  version: 2 
  ethernets: 
    ens18: # Main network interface 
      dhcp4: no 
  bridges: 
    br0: 
      interfaces: [ens18] 
      dhcp4: yes # MGMT address for Ubuntu and SONiC 
    br1: 
      interfaces: [] 
      addresses: [10.0.0.1/24] # Optional IP for host in internal network 

Apply the changes: 

sudo netplan apply. 

 

Step 3: Create SONiC image

SONiC is delivered as .img file. Best way is to convert it to .qcow2:

sudo qemu-img convert -O qcow2 /home/stordis/sonic-vs.img /home/stordis/sonic-vs-new.qcow2

After this move image to libvirt folder:

sudo mv sonic-vs.qcow2 /var/lib/libvirt/images/ 

 

Step 4: SONiC instalation

You can use virt-install, to precisely define the specification of the machine (cpu, RAM, interfaces etc.). In our case:

  • RAM 4096 MB
  • vCPU - 2
  • Interfaces - the first card is Management (br0) and the second one is the first switch port (br1 internal network). 
sudo virt-install --name sonic-node1 --ram 4096 --vcpus 2 --os-variant debian10 --disk path=/var/lib/libvirt/images/sonic-vs.qcow2,bus=virtio --network bridge=br0,model=virtio --network bridge=br1,model=virtio --import --noautoconsole

 

Step 5: Now you can login to machine

sudo virsh --connect qemu:///system console sonic-vs

After running the command, press Enter; you can then log in to SONiC (the default credentials are admin/YourPaSsWoRd). You shold see this:

 

Congratulations!

You have successfully run SONiC VS on VKM!

 

 

 

Comments 0

Articles in this section