How to build the community version of SONiC Virtual Switch (SONiC VS) image?

Build the community version of the SONiC Virtual Switch image

[stordis-toc]

Introduction

SONiC Virtual Switch (SONiC VS) is a version of SONiC that operates as a virtual machine. Use it for labs, tests and development without physical switches.

This guide shows how to build the SONiC VS image from the community source code. If you do not need your own build, download a pre-built image (refer to the links at the end of this guide).

Prerequisites

Resource Minimum Recommended
CPU Multiple cores 8 cores
RAM 8 GB 32 GB
Free disk space 300 GB 500 GB
Virtualization KVM support (the file /dev/kvm exists)
Operating system Ubuntu 22.04 or Ubuntu 24.04

 Our build tests

More than 8 cores and 32 GB of RAM do not make the build much faster. With fewer than 8 cores and 8 GB of RAM, the build is much slower.

vCPU RAM Disk SONIC_BUILD_JOBS Result Build time
4 16 GB 500 GB 4 Passed approx. 4 h 4 min
8 32 GB 500 GB 8 Passed approx. 2 h 40 min
16 64 GB 500 GB 16 Passed approx. 2 h 2 min

Tests done in 2024 on Ubuntu 20.04.


Build script generator

Select your settings. The generator makes the commands of Steps 1–5 for your build host. It also shows the approximate build time from our tests. The generator operates only in your browser.

The script generator needs JavaScript. Use the commands in Steps 1–5.


Step 1: Install the Python tools

The build needs the j2 command from the jinjanator package. The older package j2cli does not operate with Python 3.12 and later.

Ubuntu 22.04 Ubuntu 24.04
sudo apt install -y python3-pip
pip3 install --user jinjanator

If the shell does not find the j2 command, log out and log in again. Then ~/.local/bin is in your PATH.


Step 2: Install Docker

  1. Add the Docker GPG key:
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
  1. Add the Docker repository:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
  1. Install Docker:
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Add your user to the docker group. The build does not operate with sudo.
sudo gpasswd -a ${USER} docker
  1. Log out and log in again, or start a new shell with the new group:
newgrp docker
  1. Make sure that Docker operates. The command shows Hello from Docker!
docker run hello-world

With Linux kernel 5.3 or later, you need Docker 20.10.10 or later. The Docker repository above installs a current version.


Step 3: Prepare the build host

  1. Create the cache directory for build artifacts:
sudo mkdir -p /var/cache/sonic/artifacts
sudo chown $USER: /var/cache/sonic/artifacts
  1. Load the overlay kernel module:
sudo modprobe overlay

Step 4: Get the source code

  1. Clone the repository with its submodules:
git clone --recurse-submodules https://github.com/sonic-net/sonic-buildimage.git
cd sonic-buildimage
  1. Select the branch. The default is master: the newest development code. For a stable image, use a release branch.
git branch -r
git checkout <branch_name>

Example: git checkout 202411. The command git branch -r shows all branches on the server.


Step 5: Build the image

  1. Initialize the submodules. Do this after the first clone and after each branch change:
make init
  1. Configure the build for the virtual switch. This can take some time:
make configure PLATFORM=vs
  1. Build the image. Replace 8 with the number of CPU cores that the build can use:
make SONIC_BUILD_JOBS=8 target/sonic-vs.img.gz

When the build is complete, the image is in the file target/sonic-vs.img.gz.

 Pro Tip

The build takes some hours. Start it in tmux or screen. Then the build continues if the SSH connection stops.


Procedure completion

Congratulations!

You have successfully built the community version of SONiC VS. Now you can use the image in GNS3, KVM, Proxmox or ContainerLab.

Happy networking!

 

Useful links:

Where to download the SONiC Virtual Switch (VS) community pre-built image?

How to install and use qemu-img on Windows and Linux?

How to create a new GNS3 appliance template to work with SONiC using GNS3 Web UI?

 

For more free resources, visit: https://stordis.com/free-resources/

 

SONiC® is a registered trademark of Linux Foundation. STORDIS is not affiliated with, endorsed by, or sponsored by Linux Foundation.
All trademarks belong to their respective owners.

Comments 0

Articles in this section