Skip to content

Commit fbd036a

Browse files
authored
Merge pull request #1239 from c-po/compress-kernel-modules
Kernel: T5641: enable module compression to save disk space
2 parents 5e2e9a3 + 2fde86f commit fbd036a

7 files changed

Lines changed: 96 additions & 14 deletions

File tree

scripts/package-build/linux-kernel/build-accel-ppp-ng.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ cmake -DBUILD_IPOE_DRIVER=TRUE \
5858
-DCPACK_TYPE=Debian12 ..
5959
CPATH="${VPP_INCLUDE_PATH}" LIBRARY_PATH="${VPP_LIBRARY_PATH}" make
6060

61-
# Sign generated Kernel modules
62-
${CWD}/sign-modules.sh .
61+
# Sign generated Kernel modules. Keep the uncompressed .ko next to the
62+
# resulting .ko.xz: cpack's DEB packaging re-runs "make all" as part of
63+
# its install step, and if the .ko CMake tracks as a build output were
64+
# removed by compression, it would be silently rebuilt unsigned before
65+
# being packaged.
66+
${CWD}/sign-modules.sh . --keep
6367

6468
cpack -G DEB
6569

scripts/package-build/linux-kernel/build-ipt-netflow.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ fpm --input-type dir --output-type deb --name vyos-ipt-netflow \
7272
--description "ipt_NETFLOW module" \
7373
--depends linux-image-${KERNEL_VERSION}${KERNEL_SUFFIX} \
7474
--license "GPL2" -C ${IPT_NETFLOW_SRC}/tmp --after-install ${DEBIAN_POSTINST} \
75-
ipt_NETFLOW.ko=/lib/modules/${KERNEL_VERSION}${KERNEL_SUFFIX}/extra/ipt_NETFLOW.ko \
75+
ipt_NETFLOW.ko.xz=/lib/modules/${KERNEL_VERSION}${KERNEL_SUFFIX}/extra/ipt_NETFLOW.ko.xz \
7676
libipt_NETFLOW.so=/lib/$(uname -m)-linux-gnu/xtables/libipt_NETFLOW.so \
7777
libip6t_NETFLOW.so=/lib/$(uname -m)-linux-gnu/xtables/libip6t_NETFLOW.so

scripts/package-build/linux-kernel/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def build_nat_rtsp(commit_id, scm_url):
274274
arg_parser.add_argument('--config', default='package.toml', help='Path to the package configuration file')
275275
arg_parser.add_argument('--packages', nargs='+', help='Names of packages to build (default: all)', default=[])
276276
arg_parser.add_argument('--install-dependencies', '-i', help='Only install build dependencies', action='store_true')
277+
arg_parser.add_argument('--keep-kernel', '-k', help='Keep kernel intermediate objects and not create source tar-ball', action='store_true')
277278
args = arg_parser.parse_args()
278279

279280
# Load package configuration
@@ -311,7 +312,7 @@ def build_nat_rtsp(commit_id, scm_url):
311312
# Copy generated .deb packages to parent directory
312313
copy_packages(Path(package['name']))
313314

314-
if linux_kernel_tarball:
315+
if linux_kernel_tarball and not args.keep_kernel:
315316
source_dir = linux_kernel_tarball['source_dir']
316317
trusted_keys = f'{source_dir}/trusted_keys.pem'
317318
if os.path.exists(trusted_keys):

scripts/package-build/linux-kernel/config/02-module-signing.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ CONFIG_SYSTEM_TRUSTED_KEYRING=y
2222
CONFIG_MODULE_SIG_KEY="certs/signing_key.pem"
2323
CONFIG_MODULE_SIG_KEY_TYPE_RSA=y
2424
# CONFIG_MODULE_SIG_KEY_TYPE_ECDSA is not set
25+
CONFIG_MODULE_COMPRESS=y
26+
# CONFIG_MODULE_COMPRESS_GZIP is not set
27+
CONFIG_MODULE_COMPRESS_XZ=y
28+
# CONFIG_MODULE_COMPRESS_ZSTD is not set
29+
CONFIG_MODULE_COMPRESS_ALL=y
30+
CONFIG_MODULE_DECOMPRESS=y

scripts/package-build/linux-kernel/config/arm64/vyos_defconfig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
780780
CONFIG_MODVERSIONS=y
781781
CONFIG_ASM_MODVERSIONS=y
782782
# CONFIG_MODULE_SRCVERSION_ALL is not set
783-
CONFIG_MODULE_SIG=y
784-
CONFIG_MODULE_SIG_FORCE=y
785-
CONFIG_MODULE_SIG_ALL=y
786-
# CONFIG_MODULE_SIG_SHA1 is not set
787-
# CONFIG_MODULE_SIG_SHA256 is not set
788-
# CONFIG_MODULE_SIG_SHA384 is not set
789-
CONFIG_MODULE_SIG_SHA512=y
790-
CONFIG_MODULE_SIG_HASH="sha512"
791783
# CONFIG_MODULE_ALLOW_MISSING_NAMESPACE_IMPORTS is not set
792784
CONFIG_MODPROBE_PATH="/sbin/modprobe"
793785
# CONFIG_TRIM_UNUSED_KSYMS is not set
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
From: Christian Breunig <christian@vyos.io>
2+
Date: Sun, 5 Jul 2026 00:00:00 +0200
3+
Subject: [PATCH] cmake: package signed/compressed kernel modules
4+
5+
sign-modules.sh signs the built ipoe/vlan_mon/pptp kernel modules and,
6+
if the target kernel's .config enables CONFIG_MODULE_COMPRESS_XZ,
7+
compresses them to .ko.xz before cpack packages the Debian archive.
8+
The Debian packaging rules installed the drivers by their exact
9+
pre-sign build path (*.ko) unconditionally, so a compressed build
10+
never actually shipped the compressed module. Mirror sign-modules.sh's
11+
own .config check to pick the extension that actually ends up on disk.
12+
13+
---
14+
cmake/debian/debian.cmake | 16 ++++++++++++++--
15+
1 file changed, 14 insertions(+), 2 deletions(-)
16+
17+
diff --git a/cmake/debian/debian.cmake b/cmake/debian/debian.cmake
18+
index 8db274a..64b8f7d 100644
19+
--- a/cmake/debian/debian.cmake
20+
+++ b/cmake/debian/debian.cmake
21+
@@ -9,6 +9,18 @@ if (NOT DEFINED MODULES_KDIR)
22+
)
23+
endif()
24+
25+
+# sign-modules.sh signs the built .ko files and, if the target kernel's
26+
+# .config has module compression enabled, xz-compresses them in place.
27+
+# Mirror that check here so we install whichever artifact actually ends
28+
+# up on disk.
29+
+SET(KMOD_EXT ".ko")
30+
+IF (DEFINED KDIR AND EXISTS "${KDIR}/.config")
31+
+ FILE(STRINGS "${KDIR}/.config" _ACCEL_PPP_KMOD_COMPRESS_XZ REGEX "^CONFIG_MODULE_COMPRESS_XZ=y$")
32+
+ IF (_ACCEL_PPP_KMOD_COMPRESS_XZ)
33+
+ SET(KMOD_EXT ".ko.xz")
34+
+ ENDIF ()
35+
+ENDIF ()
36+
+
37+
if (BUILD_PPTP_DRIVER)
38+
if (BUILD_DRIVER_ONLY)
39+
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
40+
@@ -21,7 +33,7 @@ if (BUILD_PPTP_DRIVER)
41+
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/cmake/debian-kmod/postinst")
42+
endif ()
43+
#INSTALL(DIRECTORY lib/modules/${DEBIAN_KDIR}/extra)
44+
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/driver/driver/pptp.ko DESTINATION /lib/modules/${MODULES_KDIR}/extra)
45+
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/driver/driver/pptp${KMOD_EXT} DESTINATION /lib/modules/${MODULES_KDIR}/extra)
46+
#SET(CPACK_DEBIAN_PACKAGE_DEPENDS "linux-image (= ${LINUX_IMAGE})")
47+
endif (BUILD_PPTP_DRIVER)
48+
49+
@@ -33,7 +45,7 @@ if (BUILD_IPOE_DRIVER)
50+
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "")
51+
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/cmake/debian-kmod/postinst")
52+
endif ()
53+
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/drivers/ipoe/driver/ipoe.ko DESTINATION /lib/modules/${MODULES_KDIR}/extra)
54+
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/drivers/ipoe/driver/ipoe${KMOD_EXT} DESTINATION /lib/modules/${MODULES_KDIR}/extra)
55+
endif (BUILD_IPOE_DRIVER)
56+
57+
if (BUILD_VLAN_MON_DRIVER)
58+
@@ -44,7 +56,7 @@ if (BUILD_VLAN_MON_DRIVER)
59+
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "")
60+
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/cmake/debian-kmod/postinst")
61+
endif ()
62+
- INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/drivers/vlan_mon/driver/vlan_mon.ko DESTINATION /lib/modules/${MODULES_KDIR}/extra)
63+
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/drivers/vlan_mon/driver/vlan_mon${KMOD_EXT} DESTINATION /lib/modules/${MODULES_KDIR}/extra)
64+
endif (BUILD_VLAN_MON_DRIVER)
65+
66+
if (NOT BUILD_DRIVER_ONLY)

scripts/package-build/linux-kernel/sign-modules.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
#!/bin/sh
1+
#!/bin/sh -x
22

33
BASE_DIR=$(dirname $0)
44
MODULE_DIR=$1
5+
# Pass "--keep" as $2 to retain the uncompressed, signed .ko next to the
6+
# .ko.xz it produces. Needed by callers whose build system tracks the
7+
# uncompressed .ko as a build output (e.g. CMake custom commands) and
8+
# would otherwise consider it missing and regenerate an unsigned copy.
9+
KEEP_UNCOMPRESSED=$2
510
. ${BASE_DIR}/kernel-vars
611

712
SIGN_FILE="${KERNEL_DIR}/scripts/sign-file"
13+
CONFIG_FILE="${KERNEL_DIR}/.config"
814

915
if [ -f ${EPHEMERAL_KEY} ] && [ -f ${EPHEMERAL_CERT} ]; then
1016
find ${MODULE_DIR} -type f -name \*.ko | while read MODULE; do
1117
echo "I: Signing ${MODULE} ..."
1218
${SIGN_FILE} sha512 ${EPHEMERAL_KEY} ${EPHEMERAL_CERT} ${MODULE}
19+
if [ -f "$CONFIG_FILE" ] && grep -qx "CONFIG_MODULE_COMPRESS_XZ=y" "$CONFIG_FILE"; then
20+
if [ "${KEEP_UNCOMPRESSED}" = "--keep" ]; then
21+
xz --compress --keep ${MODULE}
22+
else
23+
xz --compress ${MODULE}
24+
fi
25+
fi
1326
done
27+
find ${MODULE_DIR}
1428
fi
15-

0 commit comments

Comments
 (0)