Skip to contentSkip to conversation

Make unneeded packages for read-only rootfs configurable

PATCH New Peter Kjellerstedt 1 participant 2 messages Mar 31, 2016

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 image.bbclass: Make unneeded packages for a read-only rootfs configurable

In reply to Peter Kjellerstedt

Previously the list of packages that are considered unneeded for a read-only rootfs was hardcoded. This made it impossible to, e.g., have shadow installed on a system with a read-only rootfs, but where /etc is mounted writable.

This also lists ${VIRTUAL-RUNTIME_update-alternatives} rather than update-alternatives (as was previously the case) since this should actually remove the intended package.

---
 meta/classes/image.bbclass |  6 +++++-
 meta/lib/oe/rootfs.py      | 23 +++++------------------
 2 files changed, 10 insertions(+), 19 deletions(-)
meta/classes/image.bbclass +5 -1
index 62ff07e..894ff99 100644
@@ -33,6 +33,10 @@ IMAGE_GEN_DEBUGFS ?= "0"
 # rootfs bootstrap install
 ROOTFS_BOOTSTRAP_INSTALL = "${@bb.utils.contains("IMAGE_FEATURES", "package-management", "", "${ROOTFS_PKGMANAGE_BOOTSTRAP}",d)}"
 
+# These packages will be removed from a read-only rootfs after all other
+# packages have been installed
+ROOTFS_RO_UNNEEDED = "update-rc.d base-passwd shadow ${VIRTUAL-RUNTIME_update-alternatives} ${ROOTFS_BOOTSTRAP_INSTALL}"
+
 # packages to install from features
 FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
 FEATURE_INSTALL[vardepvalue] = "${FEATURE_INSTALL}"
@@ -114,7 +118,7 @@ def rootfs_variables(d):
                  'IMAGE_ROOTFS_MAXSIZE','IMAGE_NAME','IMAGE_LINK_NAME','IMAGE_MANIFEST','DEPLOY_DIR_IMAGE','RM_OLD_IMAGE','IMAGE_FSTYPES','IMAGE_INSTALL_COMPLEMENTARY','IMAGE_LINGUAS',
                  'MULTILIBRE_ALLOW_REP','MULTILIB_TEMP_ROOTFS','MULTILIB_VARIANTS','MULTILIBS','ALL_MULTILIB_PACKAGE_ARCHS','MULTILIB_GLOBAL_VARIANTS','BAD_RECOMMENDATIONS','NO_RECOMMENDATIONS',
                  'PACKAGE_ARCHS','PACKAGE_CLASSES','TARGET_VENDOR','TARGET_ARCH','TARGET_OS','OVERRIDES','BBEXTENDVARIANT','FEED_DEPLOYDIR_BASE_URI','INTERCEPT_DIR','USE_DEVFS',
-                 'COMPRESSIONTYPES', 'IMAGE_GEN_DEBUGFS']
+                 'COMPRESSIONTYPES', 'IMAGE_GEN_DEBUGFS', 'ROOTFS_RO_UNNEEDED']
     variables.extend(rootfs_command_variables(d))
     variables.extend(variable_depends(d))
     return " ".join(variables)
meta/lib/oe/rootfs.py +5 -18
index 0f835d3..bfae1d8 100644
@@ -238,28 +238,13 @@ class Rootfs(object):
                                       self.d.getVar('IMAGE_ROOTFS', True),
                                       "run-postinsts", "remove"])
 
-        runtime_pkgmanage = bb.utils.contains("IMAGE_FEATURES", "package-management",
-                         True, False, self.d)
-        sysvcompat_in_distro = bb.utils.contains("DISTRO_FEATURES", [ "systemd", "sysvinit" ],
-                         True, False, self.d)
         image_rorfs = bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs",
-                         True, False, self.d)
-        if sysvcompat_in_distro and not image_rorfs:
-            pkg_to_remove = ""
-        else:
-            pkg_to_remove = "update-rc.d"
+                                        True, False, self.d)
         if image_rorfs:
             # Remove components that we don't need if it's a read-only rootfs
+            unneeded_pkgs = self.d.getVar("ROOTFS_RO_UNNEEDED", True).split()
             pkgs_installed = image_list_installed_packages(self.d)
-            pkgs_to_remove = list()
-            for pkg in pkgs_installed:
-                if pkg in ["update-rc.d",
-                        "base-passwd",
-                        "shadow",
-                        "update-alternatives", pkg_to_remove,
-                        self.d.getVar("ROOTFS_BOOTSTRAP_INSTALL", True)
-                        ]:
-                    pkgs_to_remove.append(pkg)
+            pkgs_to_remove = [pkg for pkg in pkgs_installed if pkg in unneeded_pkgs]
 
             if len(pkgs_to_remove) > 0:
                 self.pm.remove(pkgs_to_remove, False)
@@ -273,6 +258,8 @@ class Rootfs(object):
         post_uninstall_cmds = self.d.getVar("ROOTFS_POSTUNINSTALL_COMMAND", True)
         execute_pre_post_process(self.d, post_uninstall_cmds)
 
+        runtime_pkgmanage = bb.utils.contains("IMAGE_FEATURES", "package-management",
+                                              True, False, self.d)
         if not runtime_pkgmanage:
             # Remove the package manager data files
             self.pm.remove_packaging_data()
Signature · 1 line
2.1.0
#0 lore raw

cover Make unneeded packages for read-only rootfs configurable

We use a read-only rootfs (i.e., we have read-only-rootfs set in IMAGE_FEATURES). However, we mount /etc from a separate writable flash partition. But because of how some packages are considered unneeded and subsequently removed from the rootfs if it is read-only, we cannot enable, e.g., shadow in our image. The list of unneeded packages is hardcoded in lib/oe/rootfs.py, making it near impossible to override this.

With this change the list of unneeded packages is moved to a variable (ROOTFS_RO_UNNEEDED) in image.bbclass, which makes it easy to adopt it as needed.

There was code in lib/oe/rootfs.py which was meant to not add update-rc.d to the list of unneeded packages if both systemd and sysvinit are enabled in DISTRO_FEATURES. I have removed this code since a) it is no longer needed (as it only made sense when the unneeded packages were removed based on whether package-management was enabled or not), and b) it can never have worked as intended (because the explicit addition of update-rc.d to the list of unneeded packages was not removed when the conditional addition was introduced...)

//Peter

The following changes since commit 53b5dc0dda3fa7703e8f6a68b05b565ecee9e41f:

gcc: Fix musl ldso name for mips64 (2016-03-30 21:24:02 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib pkj/unneeded_packages
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=pkj/unneeded_packages

Peter Kjellerstedt (1):
image.bbclass: Make unneeded packages for a read-only rootfs
configurable

 meta/classes/image.bbclass |  6 +++++-
 meta/lib/oe/rootfs.py      | 23 +++++------------------
 2 files changed, 10 insertions(+), 19 deletions(-)
Signature · 1 line
2.1.0