From 5686f7bc81eeb1a3db1c88f044f5252d5ccad57f Mon Sep 17 00:00:00 2001 From: Daniel Zatovic Date: Thu, 23 Oct 2025 10:25:23 +0200 Subject: [PATCH] sysext: Add OS-dependent sysext compression We removed the sysext compression, because we double-compression is redundant for sysexts stored in already coimpressed BTRFS /usr. However, OS-dependent sysexts that are downloaded on-demand were now also uncompressed. This commit brings back the compression via SYSTEMD_REPART_MKFS_OPTIONS_EROFS option. Signed-off-by: Daniel Zatovic --- build_library/sysext_prod_builder | 4 ++++ build_library/vm_image_util.sh | 4 ++++ build_sysext | 33 ++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/build_library/sysext_prod_builder b/build_library/sysext_prod_builder index 87599feb80..8e57080630 100755 --- a/build_library/sysext_prod_builder +++ b/build_library/sysext_prod_builder @@ -63,11 +63,15 @@ create_prod_sysext() { # The --install_root_basename="${name}-base-sysext-rootfs" flag is # important - it sets the name of a rootfs directory, which is used # to determine the package target in coreos/base/profile.bashrc + # + # Built-in sysexts are stored in the compressed /usr partition, so we + # disable compression to avoid double-compression. sudo -E "FLATCAR_BUILD_ID=$FLATCAR_BUILD_ID" "${SCRIPTS_DIR}/build_sysext" \ --board="${BOARD}" \ --image_builddir="${workdir}/sysext-build" \ --squashfs_base="${base_sysext}" \ --generate_pkginfo \ + --compression=none \ --install_root_basename="${name}-base-sysext-rootfs" \ "${build_sysext_opts[@]}" \ "${name}" "${grp_pkg[@]}" diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 159fede04e..73eb43b812 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -585,11 +585,15 @@ install_oem_sysext() { # important - it sets the name of a rootfs directory, which is # used to determine the package target in # coreos/base/profile.bashrc + # + # OEM sysexts are stored in the compressed partition, so we disable + # compression to avoid double-compression. local build_sysext_flags=( --board="${BOARD}" --squashfs_base="${VM_SRC_SYSEXT_IMG}" --image_builddir="${built_sysext_dir}" --metapkgs="${metapkg}" + --compression=none --install_root_basename="${VM_IMG_TYPE}-oem-sysext-rootfs" ) local overlay_path mangle_fs diff --git a/build_sysext b/build_sysext index be7e504774..0b7ea4d5f3 100755 --- a/build_sysext +++ b/build_sysext @@ -35,10 +35,10 @@ DEFINE_boolean generate_pkginfo "${FLAGS_FALSE}" \ "Generate an additional squashfs '_pkginfo.raw' with portage package meta-information (/var/db ...). Useful for creating sysext dependencies; see 'base_pkginfo' below." DEFINE_string base_pkginfo "" \ "Colon-separated list of pkginfo squashfs paths / files generated via 'generate_pkginfo' to base this sysext on. The corresponding base sysexts are expected to be merged with the sysext generated." -DEFINE_string compression "zstd" \ - "Compression to use for sysext squashfs. One of 'gzip', 'lzo', 'lz4', 'xz', or 'zstd'. Must be supported by the Flatcar squashfs kernel module in order for the sysext to work." -DEFINE_string mksquashfs_opts "" \ - "Additional command line options to pass to mksquashfs. See 'man 1 mksquashfs'. If is 'zstd' (the default), this option defaults to '-Xcompression-level 22 -b 512K'. Otherwise the default is empty." +DEFINE_string compression "lz4hc" \ + "Compression to use for sysext EROFS image. Options: 'lz4', 'lz4hc', 'zstd', or 'none'. Default is 'lz4hc'." +DEFINE_string mkerofs_opts "" \ + "Additional mkfs.erofs options to pass via SYSTEMD_REPART_MKFS_OPTIONS_EROFS. If not specified, defaults are used based on compression type." DEFINE_boolean ignore_version_mismatch "${FLAGS_FALSE}" \ "Ignore version mismatch between SDK board packages and base squashfs. DANGEROUS." DEFINE_string install_root_basename "${default_install_root_basename}" \ @@ -112,10 +112,6 @@ fi BUILD_DIR=$(realpath "${FLAGS_image_builddir}") mkdir -p "${BUILD_DIR}" -if [[ "${FLAGS_compression}" = "zstd" && -z "${FLAGS_mksquashfs_opts}" ]] ; then - FLAGS_mksquashfs_opts="-Xcompression-level 22 -b 512k" -fi - source "${BUILD_LIBRARY_DIR}/toolchain_util.sh" || exit 1 source "${BUILD_LIBRARY_DIR}/board_options.sh" || exit 1 source "${BUILD_LIBRARY_DIR}/reports_util.sh" || exit 1 @@ -248,7 +244,7 @@ if [[ "$FLAGS_generate_pkginfo" = "${FLAGS_TRUE}" ]] ; then mkdir -p "${BUILD_DIR}/img-pkginfo/var/db" cp -R "${BUILD_DIR}/${FLAGS_install_root_basename}/var/db/pkg" "${BUILD_DIR}/img-pkginfo/var/db/" mksquashfs "${BUILD_DIR}/img-pkginfo" "${BUILD_DIR}/${SYSEXTNAME}_pkginfo.raw" \ - -noappend -xattrs-exclude '^btrfs.' -comp "${FLAGS_compression}" ${FLAGS_mksquashfs_opts} + -noappend -xattrs-exclude '^btrfs.' -comp zstd -Xcompression-level 22 -b 512k fi info "Writing ${SYSEXTNAME}_packages.txt" @@ -304,6 +300,25 @@ if [[ -n "${invalid_files}" ]]; then die "Invalid file ownership: ${invalid_files}" fi +# Set up EROFS compression options based on compression type +if [[ "${FLAGS_compression}" != "none" ]]; then + export SYSTEMD_REPART_MKFS_OPTIONS_EROFS="-z${FLAGS_compression}" + + if [[ -n "${FLAGS_mkerofs_opts}" ]]; then + # User provided custom options + export SYSTEMD_REPART_MKFS_OPTIONS_EROFS="${SYSTEMD_REPART_MKFS_OPTIONS_EROFS} ${FLAGS_mkerofs_opts}" + elif [[ "${FLAGS_compression}" = "lz4hc" ]]; then + # Default options for lz4hc + export SYSTEMD_REPART_MKFS_OPTIONS_EROFS="${SYSTEMD_REPART_MKFS_OPTIONS_EROFS},12 -C65536 -Efragments,ztailpacking" + elif [[ "${FLAGS_compression}" = "zstd" ]]; then + # Default options for zstd + export SYSTEMD_REPART_MKFS_OPTIONS_EROFS="${SYSTEMD_REPART_MKFS_OPTIONS_EROFS},level=22 -C524288 -Efragments,ztailpacking" + fi + info "Building sysext with ${FLAGS_compression} compression" +else + info "Building sysext without compression (built-in sysexts)" +fi + systemd-repart \ --private-key="${SYSEXT_SIGNING_KEY_DIR}/sysexts.key" \ --certificate="${SYSEXT_SIGNING_KEY_DIR}/sysexts.crt" \