Skip to content

[202305] Add build option to reduce final image size#16948

Merged
StormLiangMS merged 1 commit intosonic-net:202305from
Staphylo:202305-reduce-image-size
Oct 24, 2023
Merged

[202305] Add build option to reduce final image size#16948
StormLiangMS merged 1 commit intosonic-net:202305from
Staphylo:202305-reduce-image-size

Conversation

@Staphylo
Copy link
Collaborator

Why I did it

Running SONiC releases past 202012 has become really challenging on system with small storage devices (4GB).
Some of these devices can also be limited by only having 4GB of RAM which complicates mitigations.
The main contributor to these issues is the SONiC image growth.
Being able to reduce it by some decent amount should allow these systems to run SONiC longer.
It would also reduce some impacts related to space savings mitigations.

Work item tracking
  • Microsoft ADO (number only):

How I did it

Add a build option to reduce the image size.
The image reduction process is affecting the builds in 2 ways:

  • change some packages that are installed in the rootfs
  • apply a rootfs reduction script

The script itself will perform a few steps:

  • remove file duplication by leveraging hardlinks
    • under /usr/share/sonic since the symlinks under the device folder are lost during the build.
    • under /var/lib/docker since the files there will only be mounted ro
  • remove some extra files (man, docs, licenses, ...)
  • some image specific space reduction (only for aboot images currently)

The script can later be improved but for now it's reducing the rootfs size by ~30%.

How to verify it

Compare the size of an image with this option enabled and this option enabled.
Expect the fully extracted content to be ~30% less.

Which release branch to backport (provide reason below if selected)

This is a backport of #16729

Description for the changelog

Add build option to reduce final image size

@Staphylo
Copy link
Collaborator Author

@StormLiangMS @lipxu this is the backport of #16729 for 202305 since the introduction staged debian build conflicts

@Staphylo Staphylo force-pushed the 202305-reduce-image-size branch from 6011e42 to 878aba7 Compare October 19, 2023 12:29
@StormLiangMS
Copy link
Contributor

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Add a build option to reduce the image size.
The image reduction process is affecting the builds in 2 ways:
 - change some packages that are installed in the rootfs
 - apply a rootfs reduction script

The script itself will perform a few steps:
 - remove file duplication by leveraging hardlinks
   - under /usr/share/sonic since the symlinks under the device folder are lost during the build.
   - under /var/lib/docker since the files there will only be mounted ro
 - remove some extra files (man, docs, licenses, ...)
 - some image specific space reduction (only for aboot images currently)

The script can later be improved but for now it's reducing the rootfs
size by ~30%.
Copy link
Contributor

@StormLiangMS StormLiangMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@StormLiangMS StormLiangMS merged commit 274e929 into sonic-net:202305 Oct 24, 2023
@thovikeerthi
Copy link

thovikeerthi commented Oct 31, 2023

@Staphylo , Please inform does this image size reduction feature is applicable for all platform builds (i.e. VS, Broadcom, Marvell etc) or restricted to particular version of platform/ASIC in 202305 release ?

@thovikeerthi
Copy link

thovikeerthi commented Nov 1, 2023

Hi @Staphylo / @StormLiangMS , I tried to generate Virtual Switch VM build from 202305 source with this build option. But, didn't notice any difference in the final image size (i.e. sonic-vs.img.gz).
Request to please suggest, does this build option is supported/applicable for SONiC VS VM image (sonic-vs.img.gz) ?

Steps followed:
Step1: Clone 202305 source code (31-10-2023)
Step2: enable 'BUILD_REDUCE_IMAGE_SIZE' in '~/sonic-buildimage/rules/config' file
Step3: Follow normal build options to generate 'sonic-vs.img.gz' binary.

  • make init
  • make configure PLATFORM=vs
  • make target/sonic-vs.img.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants