ClawKit Logo
ClawKitReliability Toolkit
Back to Registry
Official Verified

sonic-build

Build SONiC (Software for Open Networking in the Cloud) switch images from sonic-buildimage. Use when building VS/ASIC images, configuring build parallelism/memory/caching, debugging build failures, managing submodules, cleaning artifacts, or optimizing build performance. Covers all platforms (VS, broadcom, mellanox, marvell, nvidia-bluefield).

skill-install — Terminal

Install via CLI (Recommended)

clawhub install openclaw/skills/skills/rustiqly/sonic-build
Or

SONiC Image Build

Quick Start

cd sonic-buildimage
make init
make configure PLATFORM=vs   # or broadcom, mellanox, etc.
make SONIC_BUILD_JOBS=4 target/sonic-vs.img.gz

For dev builds (skip tests): add BUILD_SKIP_TEST=y.

Build Architecture

Two-phase build via GNU Make → slave.mk → sonic-slave Docker container:

  1. Bookworm phase — compile all packages (debs, python wheels, Docker images) into target/debs/bookworm/
  2. Trixie phase — assemble final image from phase 1 packages into target/debs/trixie/

Makefile invokes Makefile.work with different BLDENV per phase. The configure target creates per-distro directories.

Configuration

All knobs in rules/config. Override in rules/config.user (gitignored, persists across rebases).

Key Knobs

KnobDefaultRecommendedEffect
SONIC_CONFIG_BUILD_JOBS14Parallel top-level package builds
SONIC_CONFIG_MAKE_JOBS$(nproc)defaultCompiler threads per package
BUILD_SKIP_TESTny (dev)Skip unit tests
SONIC_BUILD_MEMORYunset24gDocker --memory — contains OOM in container
SONIC_DPKG_CACHE_METHODnonerwcacheCache .deb packages for incremental builds
DEFAULT_BUILD_LOG_TIMESTAMPnonesimpleTimestamps in build logs
SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILDunsetyHost Docker daemon instead of DinD

Recommended rules/config.user

SONIC_CONFIG_BUILD_JOBS = 4
BUILD_SKIP_TEST = y
SONIC_BUILD_MEMORY = 24g
DEFAULT_BUILD_LOG_TIMESTAMP = simple

Parallelism

Rule of thumb: JOBS × 6GB ≤ available RAM.

  • JOBS=1: ~3h VS build, ~10GB RAM
  • JOBS=4: significant speedup, ~20GB RAM
  • JOBS=8: OOM risk on <48GB RAM

Why JOBS=1 is slow: 64/194 packages depend on libswsscommon (critical path bottleneck). JOBS=1 leaves most cores idle.

Memory Protection

Without limits, parallel builds can trigger the kernel OOM killer on any host process.

# Container-scoped OOM (host stays healthy):
SONIC_BUILD_MEMORY = 24g
# Or via CLI:
make SONIC_BUILDER_EXTRA_CMDLINE="--memory=24g" ...

Caching

DPKG cache (package-level)

SONIC_DPKG_CACHE_METHOD = rwcache
SONIC_DPKG_CACHE_SOURCE = /var/cache/sonic/artifacts

Version cache (downloads)

SONIC_VERSION_CACHE_METHOD = cache

Rebuilding a Single Package

make target/debs/bookworm/sonic-utilities_1.2-1_all.deb
make target/docker-syncd-vs.gz
ls target/debs/bookworm/ | grep <name>

Clean Builds

When to clean: after branch switch, rebase, or unexplained failures.

rm -rf target/*   # always full clean, not selective
make configure PLATFORM=vs
make SONIC_BUILD_JOBS=4 target/sonic-vs.img.gz

Stale artifacts (.bin, squashfs) confuse make into skipping phases.

Submodules

Metadata

Author@rustiqly
Stars1133
Views0
Updated2026-02-18
View Author Profile
AI Skill Finder

Not sure this is the right skill?

Describe what you want to build — we'll match you to the best skill from 16,000+ options.

Find the right skill
Add to Configuration

Paste this into your clawhub.json to enable this plugin.

{
  "plugins": {
    "official-rustiqly-sonic-build": {
      "enabled": true,
      "auto_update": true
    }
  }
}
Safety NoteClawKit audits metadata but not runtime behavior. Use with caution.