Skip to content

Commit 38da2cc

Browse files
xumiapull[bot]
authored andcommitted
[Build]: Support to use symbol links for lazy installation targets to reduce the image size (#10923)
Why I did it Support to use symbol links in platform folder to reduce the image size. The current solution is to copy each lazy installation targets (xxx.deb files) to each of the folders in the platform folder. The size will keep growing when more and more packages added in the platform folder. For cisco-8000 as an example, the size will be up to 2G, while most of them are duplicate packages in the platform folder. How I did it Create a new folder in platform/common, all the deb packages are copied to the folder, any other folders where use the packages are the symbol links to the common folder. Why platform.tar? We have implemented a patch for it, see #10775, but the problem is the the onie use really old unzip version, cannot support the symbol links. The current solution is similar to the PR 10775, but make the platform folder into a tar package, which can be supported by onie. During the installation, the package.tar will be extracted to the original folder and removed.
1 parent ae5f1f4 commit 38da2cc

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

build_debian.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -647,5 +647,5 @@ fi
647647
pushd $FILESYSTEM_ROOT && sudo tar czf $OLDPWD/$FILESYSTEM_DOCKERFS -C ${DOCKERFS_PATH}var/lib/docker .; popd
648648

649649
## Compress together with /boot, /var/lib/docker and $PLATFORM_DIR as an installer payload zip file
650-
pushd $FILESYSTEM_ROOT && sudo zip $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/ $PLATFORM_DIR/; popd
650+
pushd $FILESYSTEM_ROOT && sudo tar czf platform.tar.gz -C $PLATFORM_DIR . && sudo zip -n .gz $OLDPWD/$ONIE_INSTALLER_PAYLOAD -r boot/ platform.tar.gz; popd
651651
sudo zip -g -n .squashfs:.gz $ONIE_INSTALLER_PAYLOAD $FILESYSTEM_SQUASHFS $FILESYSTEM_DOCKERFS

files/Aboot/boot0.j2

+6-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,12 @@ extract_image() {
348348

349349
info "Extracting swi content"
350350
## Unzip the image except boot0 and dockerfs archive
351-
unzip -oq "$swipath" -x boot0 "$dockerfs" -d "$image_path"
351+
unzip -oq "$swipath" -x boot0 "$dockerfs" "platform.tar.gz" -d "$image_path"
352+
353+
## Extract the platform.tar.gz
354+
info "Extracting platform.tar.gz"
355+
mkdir -p "$image_path/platform"
356+
unzip -oqp "$swipath" "platform.tar.gz" | tar xzf - -C "$image_path/platform" $TAR_EXTRA_OPTION
352357

353358
## detect rootfs type
354359
local mountstr="$(grep " $target_path " /proc/mounts)"

files/build_templates/sonic_debian_extension.j2

+3-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,9 @@ sudo LANG=C chroot $FILESYSTEM_ROOT depmod -a {{kversion}}
614614
sudo dpkg --root=$FILESYSTEM_ROOT -i {{deb}} || sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f --download-only
615615

616616
sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}
617-
sudo cp {{ deb }} $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/
617+
sudo mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/common
618+
sudo cp {{ deb }} $FILESYSTEM_ROOT/$PLATFORM_DIR/common/
619+
sudo ln -sf "../common/{{ debfilename }}" "$FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/{{ debfilename }}"
618620
for f in $(find $FILESYSTEM_ROOT/var/cache/apt/archives -name "*.deb"); do
619621
sudo mv $f $FILESYSTEM_ROOT/$PLATFORM_DIR/{{dev}}/
620622
done

installer/arm64/install.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ fi
155155
# Decompress the file for the file system directly to the partition
156156
if [ x"$docker_inram" = x"on" ]; then
157157
# when disk is small, keep dockerfs.tar.gz in disk, expand it into ramfs during initrd
158-
unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir
158+
unzip -o $ONIE_INSTALLER_PAYLOAD -x "platform.tar.gz" -d $demo_mnt/$image_dir
159159
else
160-
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir
160+
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" "platform.tar.gz" -d $demo_mnt/$image_dir
161161

162162
if [ "$install_env" = "onie" ]; then
163163
TAR_EXTRA_OPTION="--numeric-owner"
@@ -168,6 +168,8 @@ else
168168
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
169169
fi
170170

171+
mkdir -p $demo_mnt/$image_dir/platform
172+
unzip -op $ONIE_INSTALLER_PAYLOAD "platform.tar.gz" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/platform
171173

172174
if [ "$install_env" = "onie" ]; then
173175
# Store machine description in target file system

installer/armhf/install.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ fi
155155
# Decompress the file for the file system directly to the partition
156156
if [ x"$docker_inram" = x"on" ]; then
157157
# when disk is small, keep dockerfs.tar.gz in disk, expand it into ramfs during initrd
158-
unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir
158+
unzip -o $ONIE_INSTALLER_PAYLOAD -x "platform.tar.gz" -d $demo_mnt/$image_dir
159159
else
160-
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir
160+
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" "platform.tar.gz" -d $demo_mnt/$image_dir
161161

162162
if [ "$install_env" = "onie" ]; then
163163
TAR_EXTRA_OPTION="--numeric-owner"
@@ -168,6 +168,8 @@ else
168168
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
169169
fi
170170

171+
mkdir -p $demo_mnt/$image_dir/platform
172+
unzip -op $ONIE_INSTALLER_PAYLOAD "platform.tar.gz" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/platform
171173

172174
if [ "$install_env" = "onie" ]; then
173175
# Store machine description in target file system

installer/x86_64/install.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@ fi
536536
# Decompress the file for the file system directly to the partition
537537
if [ x"$docker_inram" = x"on" ]; then
538538
# when disk is small, keep dockerfs.tar.gz in disk, expand it into ramfs during initrd
539-
unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir
539+
unzip -o $ONIE_INSTALLER_PAYLOAD -x "platform.tar.gz" -d $demo_mnt/$image_dir
540540
else
541-
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir
541+
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" "platform.tar.gz" -d $demo_mnt/$image_dir
542542
543543
if [ "$install_env" = "onie" ]; then
544544
TAR_EXTRA_OPTION="--numeric-owner"
@@ -549,6 +549,9 @@ else
549549
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
550550
fi
551551
552+
mkdir -p $demo_mnt/$image_dir/platform
553+
unzip -op $ONIE_INSTALLER_PAYLOAD "platform.tar.gz" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/platform
554+
552555
if [ "$install_env" = "onie" ]; then
553556
# Store machine description in target file system
554557
if [ -f /etc/machine-build.conf ]; then

0 commit comments

Comments
 (0)