From 734e7e8c54da115b18caf5c9e9b538f2d621af3f Mon Sep 17 00:00:00 2001 From: Greg Kurz Date: Tue, 8 Apr 2025 08:49:28 +0200 Subject: [PATCH] rootfs: Don't remove files from the rootfs by default Recent PR #10732 moved the deletion of systemd files and units that were deemed uneccessary by 02b3b3b97766 from `image_builder.sh` to `rootfs.sh`. This unfortunately broke `rootfs.sh centos` and `rootfs.sh -r` as used by some other downstream users like fedora and RHEL, with the following error : Warning FailedCreatePodSandBox 1s (x5 over 63s) kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = CreateContainer failed: Establishing a D-Bus connection Caused by: 0: I/O error: Connection reset by peer (os error 104) 1: Connection reset by peer (os error 104) This is because the aforementioned distros use dbus-broker [1] that requires systemd-journald to be present. It is questionable that systemd units or files should be deemed unnecessary for _all_ distros but this has been around since 2019. There's now also a long-standing expectation from CI that `make rootfs && make image` does remove these files. In order to accomodate all the expectations, add a `-d` flag to `rootfs.sh` to delete the systemd files and have `make rootfs` to use it. [1] https://github.com/bus1/dbus-broker Reported-by: Niteesh Dubey Signed-off-by: Greg Kurz --- tools/osbuilder/Makefile | 2 +- tools/osbuilder/rootfs-builder/rootfs.sh | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/osbuilder/Makefile b/tools/osbuilder/Makefile index 91979e99c5..1b3aa4217a 100644 --- a/tools/osbuilder/Makefile +++ b/tools/osbuilder/Makefile @@ -93,7 +93,7 @@ rootfs-%: $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX) .PRECIOUS: $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX) $(ROOTFS_BUILD_DEST)/.%$(ROOTFS_MARKER_SUFFIX):: rootfs-builder/% - $(call silent_run,Creating rootfs for "$*",$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*) + $(call silent_run,Creating rootfs for "$*",$(ROOTFS_BUILDER) -o $(VERSION_COMMIT) -d -r $(ROOTFS_BUILD_DEST)/$*_rootfs $*) @touch $@ # To generate a dracut rootfs, we first generate a dracut initrd and then diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index bab6ac03f1..4ec5429e9f 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -106,6 +106,8 @@ readonly -a systemd_files=( "systemd-tmpfiles-cleanup.timer" ) +typeset should_delete_unnecessary_files="no" + handle_error() { local exit_code="${?}" local line_number="${1:-}" @@ -158,6 +160,7 @@ $(get_distros | tr "\n" " ") Options: -a Specify the agent version. Overrides the AGENT_VERSION environment variable. + -d Delete unnecessary systemd units and files -h Show this help message. -l List the supported Linux distributions and exit immediately. -o Specify the version of osbuilder to embed in the rootfs @@ -818,7 +821,9 @@ EOF info "Create /etc/resolv.conf file in rootfs if not exist" touch "$dns_file" - delete_unnecessary_files + if [[ "${should_delete_unnecessary_files}" == "yes" ]]; then + delete_unnecessary_files + fi info "Creating summary file" create_summary_file "${ROOTFS_DIR}" @@ -828,10 +833,11 @@ parse_arguments() { [ "$#" -eq 0 ] && usage && return 0 - while getopts a:hlo:r:t: opt + while getopts a:dhlo:r:t: opt do case $opt in a) AGENT_VERSION="${OPTARG}" ;; + d) should_delete_unnecessary_files="yes" ;; h) usage ;; l) get_distros | sort && exit 0;; o) OSBUILDER_VERSION="${OPTARG}" ;;