Building Sonic -VS

之前一直想自行编译下Sonic,但总是没时间。这次正好赶上准备Sonic培训,所以就尝试了下,虽然官方文档介绍的很简单,但编译过一遍才发现,还是有些麻烦的。本篇总结会从干净的Ubuntu系统入手,从头搭建编译环境,以及通过PNET加载编译好的Sonic-VS;下面是官方编译Guide:https://github.com/sonic-net/sonic-buildimage

文档内标注了不同版本的编译情况,这个可以点进去看编译状态,看时间应该是一直在更新以验证社区代码是Ok的:

物理环境

我给编译服务器分配的资源如下:

  • CPU:4
  • Memory:8196
  • 硬盘:160G

注意硬盘一定要给足,我开始通过PNET分配的资源只有60多个G,后面直接报空间不足,后来废了半天劲才无损扩大160g,具体步骤可以参考这篇总结:https://www.zhaocs.info/install-eve-ng-in-esxi.html#ftoc-heading-14

Ubuntu版本如下:

$ uname -a
Linux ubuntu 5.15.0-69-generic #76-Ubuntu SMP Fri Mar 17 17:19:29 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"

网络环境

编译环境需要访问Github,而且编译过程中需要下载很多关联内容,为了顺利编译,需要设置代理才可以,否则直接无法编译,关于代理环境搭建,可以参考上一篇的总结:部署透明代理服务器

代理服务器Ready后,就可以进行编译了,不过需要注意编译过程中需要下载大量文件,这个如果是自己搭建的代理,要注意流量,我编译了4-5次吧,前几次是按Guide的配置“make SONIC_BUILD_JOBS=4 all”,后两次单独编译的“sonic-vs.bin” 和 “sonic-vs.img.gz”,总共用了26GB

依赖环境

安装 Python 相关包

$ sudo apt install -y python3-pip
$ sudo curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
$ pip3 install --user j2cli
$ reboot

安装 Docker

建议参考官方文档:https://docs.docker.com/engine/install/ubuntu/

本地用户加入 Docker组

$ sudo gpasswd -a ${USER} docker

编译

$ git clone --recurse-submodules https://github.com/sonic-net/sonic-buildimage.git
$ sudo modprobe overlay
$ cd sonic-buildimage/
$ git checkout
$ make init
$ make configure PLATFORM=vs
$ make target/sonic-vs.bin
$ make target/sonic-vs.img.gz

编译完的结果会放入target目录,如下:

下面是编译完后的硬盘占用情况,注意这个硬盘占用会根据编译过程变大或变小,我看到最大的时候是占用了97G:

$ df -H
Filesystem                 Size  Used Avail Use% Mounted on
tmpfs                      834M  1.1M  833M   1% /run
/dev/mapper/ubuntu--vg-lv  167G   81G   79G  51% /
tmpfs                      4.2G     0  4.2G   0% /dev/shm
tmpfs                      5.3M     0  5.3M   0% /run/lock
/dev/vda2                  2.1G  137M  1.8G   8% /boot
tmpfs                      834M  4.1k  834M   1% /run/user/1001

PNET加载Sonic-VS

img与bin的区别

有趣的问题来了,我开始编译的是.bin文件,通过quem-img转成了qcow2,让PNET启动,系统可以启动,但一直在找ZTP,然后就卡死了。网上使用PNET加载的Sonic都是img的,所以我才编译了第二个文件,也就是.img文件,经过验证,是可以正常boot的(具体步骤后面介绍),那么这两个文件到底有什么不同?.bin是二进制执行文件,.img是qemu 可启动的文件,这两个文件大小基本是一样的,所以里面的内容应该是类似的:

$ ll |grep sonic-vs
-rwxr-xr-x  1 xxxxxxx xxxxxxx 854570990 Jan 23 14:25 sonic-vs.bin*
-rw-r--r--  1 xxxxxxx xxxxxxx    491580 Jan 23 11:19 sonic-vs.bin.log
-rw-r--r--  1 root    root    612478976 Jan 23 11:09 sonic-vs.bin__vs__rfs.squashfs
-rw-r--r--  1 xxxxxxx xxxxxxx    218352 Jan 23 11:09 sonic-vs.bin__vs__rfs.squashfs.log
-rwxr-xr-x  1 xxxxxxx xxxxxxx 870900705 Jan 23 14:34 sonic-vs.img.gz*
-rw-r--r--  1 xxxxxxx xxxxxxx    521115 Jan 23 14:38 sonic-vs.img.gz.log
-rw-r--r--  1 root    root    612478976 Jan 23 14:13 sonic-vs.img.gz__vs__rfs.squashfs
-rw-r--r--  1 xxxxxxx xxxxxxx    218171 Jan 23 14:13 sonic-vs.img.gz__vs__rfs.squashfs.log

根据“sonic-vs.bin.log” 和 “sonic-vs.img.gz.log”文件,我们可以找到具体区别,通过脚本把sonic-vs.bin安装(自解压),并转成可启动的kvm image,如下信息对比,如果编译sonic-vs.img.gz,会先编译.bin,所以前半部分基本一样,只有后半部分才会不一样:

+ generate_kvm_image
+ NUM_ASIC=
+ '[' == 4 ']'
./build_image.sh: line 31: [: ==: unary operator expected
+ '[' == 6 ']'
./build_image.sh: line 34: [: ==: unary operator expected
+ KVM_IMAGE=target/sonic-vs.img
+ RECOVERY_ISO=target/files/bookworm/onie-recovery-x86_64-kvm_x86_64-r0.iso
+ NUM_ASIC=1
+ echo 'Build 1-asic KVM image'
Build 1-asic KVM image
+ KVM_IMAGE_DISK=target/sonic-vs.img
+ sudo rm -f target/sonic-vs.img target/sonic-vs.img.gz
+ SONIC_USERNAME=admin
+ PASSWD=YourPaSsWoRd
+ sudo -E ./scripts/build_kvm_image.sh target/sonic-vs.img target/files/bookworm/onie-recovery-x86_64-kvm_x86_64-r0.iso target/sonic-vs.bin 16
+ MEM=8192
+ DISK=target/sonic-vs.img
+ ONIE_RECOVERY_ISO=target/files/bookworm/onie-recovery-x86_64-kvm_x86_64-r0.iso
+ INSTALLER=target/sonic-vs.bin
+ DISK_SIZE=16
+ INSTALLER_DISK=./sonic-installer.img
+ KVM_PORT=9000
+ apt-get install -y net-tools
Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  net-tools
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 243 kB of archives.
After this operation, 1001 kB of additional disk space will be used.
Get:1 http://debian-archive.trafficmanager.net/debian bookworm/main amd64 net-tools amd64 2.10-0.1 [243 kB]
Fetched 243 kB in 2s (128 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 203801 files and directories currently installed.)
Preparing to unpack .../net-tools_2.10-0.1_amd64.deb ...
Unpacking net-tools (2.10-0.1) ...
Setting up net-tools (2.10-0.1) ...
Processing triggers for man-db (2.11.2-2) ...
+ create_disk
+ echo 'Creating SONiC kvm disk : target/sonic-vs.img of size 16 GB'
Creating SONiC kvm disk : target/sonic-vs.img of size 16 GB
+ qemu-img create -f qcow2 target/sonic-vs.img 16G
Formatting 'target/sonic-vs.img', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=17179869184 lazy_refcounts=off refcount_bits=16
+ prepare_installer_disk
+ fallocate -l 4096M ./sonic-installer.img
+ mkfs.vfat ./sonic-installer.img
mkfs.fat 4.2 (2021-01-31)
++ mktemp -d
+ tmpdir=/tmp/tmp.AHqfjkHUNA
+ mount -o loop ./sonic-installer.img /tmp/tmp.AHqfjkHUNA
+ cp target/sonic-vs.bin /tmp/tmp.AHqfjkHUNA/onie-installer.bin
+ umount /tmp/tmp.AHqfjkHUNA
+ echo 'Prepare memory for KVM build: yes'
Prepare memory for KVM build: yes
+ mount proc /proc -t proc
+ free -m
               total        used        free      shared  buff/cache   available
Mem:            7951         567        1111           3        6583        7384
Swap:           3922          68        3854
+ [[ yes == \y\e\s ]]
+ bash -c 'echo 1 > /proc/sys/vm/drop_caches'
+ [[ -w /proc/sys/vm/compact_memory ]]
+ bash -c 'echo 1 > /proc/sys/vm/compact_memory'
+ free -m
               total        used        free      shared  buff/cache   available
Mem:            7951         581        6773           3         906        7370
Swap:           3922          68        3854
++ mktemp
+ kvm_log=/tmp/tmp.YdGy77kqXZ
+ trap on_exit EXIT
+ trap on_error ERR
+ echo 'Installing SONiC'
Installing SONiC
+ kvm_pid=117097
+ wait_kvm_ready
+ local count=30
+ local waiting_in_seconds=2.0
+ (( i=1 ))
+ (( i<=30 ))
+ sleep 2.0
+ /usr/bin/kvm -m 8192 -name onie -boot order=cd,once=d -cdrom target/files/bookworm/onie-recovery-x86_64-kvm_x86_64-r0.iso -device e1000,netdev=onienet -netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 -vnc 0.0.0.0:0 -vga std -drive file=target/sonic-vs.img,media=disk,if=virtio,index=0 -drive file=./sonic-installer.img,if=virtio,index=1 -serial telnet:127.0.0.1:9000,server

因此对于.bin文件,可以找个有 ONIE 环境的设备,直接installe应该就可以使用了,只是由于VS没有硬件部分,所以只能测试上层的功能:

ONIE:/ # onie-nos-install sonic-vs.bin

PNET加载Img

直接把img改qcow2扩展名,放入对应文件夹中,即可通过PNET启动:

root@pnetlab:/opt# mkdir /opt/unetlab/addons/qemu/sonicsw-20240123
root@pnetlab:/opt# gunzip sonic-vs.img.gz 
root@pnetlab:/opt# mv sonic-vs.img /opt/unetlab/addons/qemu/sonicsw-20240123
root@pnetlab:/opt# more /opt/unetlab/html/templates/intel/sonicsw.yml 
admin@sonic:~$ show ver
  
SONiC Software Version: SONiC.master.0-da0f4ace7
SONiC OS Version: 12
Distribution: Debian 12.4
Kernel: 6.1.0-11-2-amd64
Build commit: da0f4ace7
Build date: Tue Jan 23 14:14:09 UTC 2024
Built by: xxxxxxx@ubuntu

Platform: x86_64-kvm_x86_64-r0
HwSKU: Force10-S6000
ASIC: vs
ASIC Count: 1
Serial Number: N/A
Model Number: N/A
Hardware Revision: N/A
Uptime: 03:16:37 up 1 day, 11:50,  2 users,  load average: 0.31, 0.40, 0.36
Date: Thu 25 Jan 2024 03:16:37

Docker images:
REPOSITORY                    TAG                  IMAGE ID       SIZE
docker-macsec                 latest               1458f4539520   333MB
docker-dhcp-relay             latest               1cb5fd9a26d1   312MB
docker-teamd                  latest               1450c20edd7a   330MB
docker-teamd                  master.0-da0f4ace7   1450c20edd7a   330MB
docker-syncd-vs               latest               98b53b6a79f0   319MB
docker-syncd-vs               master.0-da0f4ace7   98b53b6a79f0   319MB
docker-sonic-gnmi             latest               b3255f0ad31a   391MB
docker-sonic-gnmi             master.0-da0f4ace7   b3255f0ad31a   391MB
docker-snmp                   latest               eb98d0f69575   341MB
docker-snmp                   master.0-da0f4ace7   eb98d0f69575   341MB
docker-sflow                  latest               be4245486eda   332MB
docker-sflow                  master.0-da0f4ace7   be4245486eda   332MB
docker-router-advertiser      latest               dbd30eb2b76a   302MB
docker-router-advertiser      master.0-da0f4ace7   dbd30eb2b76a   302MB
docker-platform-monitor       latest               2f497bc635ab   424MB
docker-platform-monitor       master.0-da0f4ace7   2f497bc635ab   424MB
docker-orchagent              latest               2edc3149dcd4   342MB
docker-orchagent              master.0-da0f4ace7   2edc3149dcd4   342MB
docker-nat                    latest               fc4a52bbcc8c   333MB
docker-nat                    master.0-da0f4ace7   fc4a52bbcc8c   333MB
docker-mux                    latest               35c8b71e8c97   351MB
docker-mux                    master.0-da0f4ace7   35c8b71e8c97   351MB
docker-lldp                   latest               c363c770c8a1   345MB
docker-lldp                   master.0-da0f4ace7   c363c770c8a1   345MB
docker-gbsyncd-vs             latest               55ba30d6fbda   314MB
docker-gbsyncd-vs             master.0-da0f4ace7   55ba30d6fbda   314MB
docker-fpm-frr                latest               a9d8c9af5e6e   362MB
docker-fpm-frr                master.0-da0f4ace7   a9d8c9af5e6e   362MB
docker-eventd                 latest               8730fc5860d2   302MB
docker-eventd                 master.0-da0f4ace7   8730fc5860d2   302MB
docker-database               latest               1090adb08906   302MB
docker-database               master.0-da0f4ace7   1090adb08906   302MB
docker-sonic-mgmt-framework   latest               cbccfe41844c   387MB
docker-sonic-mgmt-framework   master.0-da0f4ace7   cbccfe41844c   387MB
admin@sonic:~$ docker ps -a
CONTAINER ID   IMAGE                                COMMAND                  CREATED        STATUS        PORTS     NAMES
83ee9419f7e8   docker-snmp:latest                   "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             snmp
4e397c50114a   docker-platform-monitor:latest       "/usr/bin/docker_ini…"   36 hours ago   Up 36 hours             pmon
7bcf7ba5cbc8   docker-sonic-mgmt-framework:latest   "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             mgmt-framework
bf6e5d97820b   docker-lldp:latest                   "/usr/bin/docker-lld…"   36 hours ago   Up 36 hours             lldp
14502f766279   docker-sonic-gnmi:latest             "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             gnmi
01b12f84aa86   docker-gbsyncd-vs:latest             "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             gbsyncd
18cc73e6405d   docker-fpm-frr:latest                "/usr/bin/docker_ini…"   36 hours ago   Up 36 hours             bgp
6d51d03cd27a   docker-router-advertiser:latest      "/usr/bin/docker-ini…"   36 hours ago   Up 36 hours             radv
ae6eb5713878   docker-syncd-vs:latest               "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             syncd
79bd59d48e5d   docker-teamd:latest                  "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             teamd
97623fa2379c   docker-orchagent:latest              "/usr/bin/docker-ini…"   36 hours ago   Up 36 hours             swss
add48708bf15   docker-eventd:latest                 "/usr/local/bin/supe…"   36 hours ago   Up 36 hours             eventd
e12c8c8ca9cd   docker-database:latest               "/usr/local/bin/dock…"   36 hours ago   Up 36 hours             database

本文出自 Frank's Blog

版权声明:


本文链接:Building Sonic -VS
版权声明:本文为原创文章,仅代表个人观点,版权归 Frank Zhao 所有,转载时请注明本文出处及文章链接
你可以留言,或者trackback 从你的网站

留言哦

blonde teen swallows load.xxx videos