public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [RFC PATCH] meta/classes: Add strip-image
@ 2025-09-03 15:20 'Quirin Gylstorff' via isar-users
  2025-09-03 16:19 ` 'Jan Kiszka' via isar-users
  0 siblings, 1 reply; 7+ messages in thread
From: 'Quirin Gylstorff' via isar-users @ 2025-09-03 15:20 UTC (permalink / raw)
  To: isar-users

From: Quirin Gylstorff <quirin.gylstorff@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.gylstorff@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

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20250903152055.1353354-1-Quirin.Gylstorff%40siemens.com.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-09-05  8:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-03 15:20 [RFC PATCH] meta/classes: Add strip-image 'Quirin Gylstorff' via isar-users
2025-09-03 16:19 ` 'Jan Kiszka' via isar-users
2025-09-03 17:13   ` 'Quirin Gylstorff' via isar-users
2025-09-04  8:37     ` 'Jan Kiszka' via isar-users
2025-09-04  9:43       ` 'Quirin Gylstorff' via isar-users
2025-09-05  7:30         ` Andreas Naumann
2025-09-05  8:43           ` 'Jan Kiszka' via isar-users

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox