public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "'Quirin Gylstorff' via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Subject: [RFC PATCH] meta/classes: Add strip-image
Date: Wed,  3 Sep 2025 17:20:50 +0200	[thread overview]
Message-ID: <20250903152055.1353354-1-Quirin.Gylstorff@siemens.com> (raw)

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.

             reply	other threads:[~2025-09-03 15:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-03 15:20 'Quirin Gylstorff' via isar-users [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250903152055.1353354-1-Quirin.Gylstorff@siemens.com \
    --to=isar-users@googlegroups.com \
    --cc=Quirin.Gylstorff@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox