From: Quirin Gylstorff <
quirin.g...@siemens.com>
This class provides the optional functionality to strip packages
and files from a image. This allows the user to reduce the image
size.
IMPORTANT: This is an expert feature and can lead to broken images.
Signed-off-by: Quirin Gylstorff <
quirin.g...@siemens.com>
---
The default settings will reduce the space around 40MB. It is currently
a RFC to collect information about the usage.
Should we integrate by default or should the user add this on demand?
For a default integration I would drop the deletion:
- /vmlinuz*
- /boot
- /usr/include
- initramfs-tools
meta/classes/strip-image.bbclass | 64 ++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
create mode 100644 meta/classes/strip-image.bbclass
diff --git a/meta/classes/strip-image.bbclass b/meta/classes/strip-image.bbclass
new file mode 100644
index 00000000..edff3fd4
--- /dev/null
+++ b/meta/classes/strip-image.bbclass
@@ -0,0 +1,64 @@
+# strip image helper
+#
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2025
+#
+# SPDX-License-Identifier: MIT
+# This class provides functions to remove pacakges and files
+# from the image
+
+# Default list of files to be removed:
+# - remove kernel and initrd
+# - remove all documentation
+# - remove all include files
+IMAGE_STRIP_FILES += " \
+ /vmlinuz* \
+ /boot \
+ /usr/share/doc \
+ /usr/share/info \
+ /usr/share/man \
+ /usr/include \
+"
+
+do_strip_files_from_image[vardeps] = "${IMAGE_STRIP_FILES}"
+do_strip_files_from_image[network] = "${TASK_USE_SUDO}"
+do_strip_files_from_image() {
+i if [ -n "${IMAGE_STRIP_FILES}" ]; then
+ cat <<EOF | sudo tee "${IMAGE_ROOTFS}/purge.sh"
+#!/usr/bin/env sh
+set -x
+for elem in ${IMAGE_STRIP_FILES}; do
+ find \$elem ! -type d -exec rm -rf {} \;
+done
+rm -f /purge.sh
+EOF
+ sudo chmod 755 "${IMAGE_ROOTFS}/purge.sh"
+ sudo -E chroot "${IMAGE_ROOTFS}" "/purge.sh"
+ fi
+}
+addtask strip_files_from_image before do_rootfs_finalize after do_generate_initramfs
+IMAGE_STRIP_PACKAGES += " \
+ initramfs-tools \
+ initramfs-tools-core \
+ locales \
+"
+do_strip_packages_from_image[vardeps] = "${IMAGE_STRIP_PACKAGES}"
+do_strip_packages_from_image[network] = "${TASK_USE_SUDO}"
+do_strip_packages_from_image() {
+ bbnote "IMAGE_PACKAGES_REMOVE: ${IMAGE_PACKAGES_REMOVE}"
+ if [ -n "${IMAGE_STRIP_PACKAGES}" ]; then
+ RMPKGS=$(dpkg-query \
+ --admindir=${IMAGE_ROOTFS}/var/lib/dpkg/ \
+ -f '${Package}\n' \
+ -W ${IMAGE_STRIP_PACKAGES} 2>/dev/null || true)
+
+ if [ -n "${RMPKGS}" ]; then
+ bbnote "Removing packages: ${RMPKGS}"
+ sudo -E chroot "${IMAGE_ROOTFS}" \
+ dpkg --purge --force-depends --force-remove-essential ${RMPKGS}
+ else
+ bbnote "Packages have already been purged or could not be found"
+ fi
+ fi
+}
+addtask strip_packages_from_image before do_strip_files_from_image do_rootfs_finalize after do_rootfs_postprocess
--
2.50.1