This guide provides detailed instructions on how to compile the community version of SONiC (Software for Open Networking in the Cloud) Virtual Switch (VS). SONiC VS is a virtualized version of SONiC that allows for testing and development in a virtual environment. Follow these steps to set up and compile SONiC VS on Ubuntu 20.04.
Prerequisites
Any server can be a build image as long as it has:
- Multiple processor cores
- At least 8 GB of RAM
- 300 GB of free disk space
- KVM Virtualization support
Recommended:
- At least 8 cores
- 32 GB of RAM
- 500 GB of free disk space
What should You know?
There isn't a significant difference in performance between hardware configurations with 8 or more CPUs and the same applies to RAM. However, attempting to build with fewer than 8 cores and 8GB of RAM will result in a substantial slowdown.
Therefore, there is no benefit to using more than 8 cores and 32GB of RAM.
We made the tests with the following configurations:
4 vCPU, 16GB RAM, 500GB disk, SONIC_BUILD_JOBS=4
Test PASSED - total time: ~ 4h 4m
8 vCPU, 32GB RAM, 500GB disk, SONIC_BUILD_JOBS=8
Test PASSED - total time: ~ 2h 40m
16 vCPU, 64GB RAM, 500GB disk, SONIC_BUILD_JOBS=16
Test PASSED - total time: ~2h 2m
A good operating system for building SONiC VS is Ubuntu 20.04, as it provides a stable and compatible environment.
uname -a
Linux srv-lab 5.4.0-187-generic #207-Ubuntu SMP Mon Jun 10 08:16:10 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"
Installation
Once You have access to the installed system You need to download python3 and install jinga like this:
tsudo apt install -y python3-pip
pip3 install --user j2cli
Docker
Next You need to install docker like this:
Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install 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
Add the repository to Apt sources:
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
Now You can finish installing docker by doing this:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
You also need to add Your user to the docker group as sudo is not supported
sudo gpasswd -a ${USER} docker
Now, logout and login again.
If you are using Linux kernel 5.3 or newer, then you must use Docker 20.10.10 or newer. This is because older Docker versions did not allow the clone3 syscall, which is now used in Bookworm.
To check if docker is running properly You need to use:
docker run hello-world
The output should be "hello world"
Before building an image You should also run the following commands:
sudo mkdir -p /var/cache/sonic/artifacts
sudo chown $USER: /var/cache/sonic/artifacts
sudo chmod 777 /var/cache/sonic/artifacts
Building image
After the docker is installed and working You need to clone the repository containing sonic-buildimage:
git clone --recurse-submodules https://github.com/sonic-net/sonic-buildimage.git
Ensure the 'overlay' module is loaded on your development system:
sudo modprobe overlay
Enter the source directory:
cd sonic-buildimage
(Optional) Checkout a specific branch. By default, it uses master branch.
For example, to checkout the branch 201911, use "git checkout 201911"
Leave it as is if You just want to try it out:
git checkout master
Execute make init once after cloning the repo, or after fetching remote repo with submodule updates:
make init
Execute make configure once to configure ASIC, this may take a while:
make configure PLATFORM=vs
Build SONiC image with 4 jobs in parallel.
Note: You can set this higher, but 4 is a good number for most cases and is well-tested.
make SONIC_BUILD_JOBS=[NUMBER_OF_CORES_TO_USE] target/sonic-vs.img.gz
By following this guide, you should be able to successfully compile the community version of SONiC VS on Ubuntu system. This image allows for a virtualized environment to test and develop SONiC without the need for physical hardware.