Skip to content

Commit

Permalink
Merge pull request #299 from microsoft/danmihai1/delete-from-rootfs
Browse files Browse the repository at this point in the history
rootfs: minor systemd file deletion cleanup
  • Loading branch information
danmihai1 authored Jan 27, 2025
2 parents 6058c26 + a3ca1b5 commit 1ee72c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
35 changes: 0 additions & 35 deletions tools/osbuilder/image-builder/image_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,6 @@ readonly dax_header_sz=2
# [2] - https://nvdimm.wiki.kernel.org/2mib_fs_dax
readonly dax_alignment=2

# The list of systemd units and files that are not needed in Kata Containers
readonly -a systemd_units=(
"systemd-coredump@"
"systemd-journald"
"systemd-journald-dev-log"
"systemd-journal-flush"
"systemd-random-seed"
"systemd-timesyncd"
"systemd-tmpfiles-setup"
"systemd-update-utmp"
)

readonly -a systemd_files=(
"systemd-bless-boot-generator"
"systemd-fstab-generator"
"systemd-getty-generator"
"systemd-gpt-auto-generator"
"systemd-tmpfiles-cleanup.timer"
)

# Set a default value
AGENT_INIT=${AGENT_INIT:-no}
SELINUX=${SELINUX:-no}
Expand Down Expand Up @@ -443,21 +423,6 @@ setup_selinux() {
}

setup_systemd() {
local mount_dir="$1"

info "Removing unneeded systemd services and sockets"
for u in "${systemd_units[@]}"; do
find "${mount_dir}" -type f \( \
-name "${u}.service" -o \
-name "${u}.socket" \) \
-exec rm -f {} \;
done

info "Removing unneeded systemd files"
for u in "${systemd_files[@]}"; do
find "${mount_dir}" -type f -name "${u}" -exec rm -f {} \;
done

info "Creating empty machine-id to allow systemd to bind-mount it"
touch "${mount_dir}/etc/machine-id"
}
Expand Down
43 changes: 43 additions & 0 deletions tools/osbuilder/rootfs-builder/rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ ARCH=${ARCH:-$(uname -m)}
TARGET_OS=${TARGET_OS:-linux}
[ "${CROSS_BUILD}" == "true" ] && BUILDX=buildx && PLATFORM="--platform=${TARGET_OS}/${TARGET_ARCH}"

# The list of systemd units and files that are not needed in Kata Containers
readonly -a systemd_units=(
"systemd-coredump@"
"systemd-journald"
"systemd-journald-dev-log"
"systemd-journal-flush"
"systemd-random-seed"
"systemd-timesyncd"
"systemd-tmpfiles-setup"
"systemd-update-utmp"
)

readonly -a systemd_files=(
"systemd-bless-boot-generator"
"systemd-fstab-generator"
"systemd-getty-generator"
"systemd-gpt-auto-generator"
"systemd-tmpfiles-cleanup.timer"
)

handle_error() {
local exit_code="${?}"
local line_number="${1:-}"
Expand Down Expand Up @@ -678,6 +698,8 @@ EOF
info "Create /etc/resolv.conf file in rootfs if not exist"
touch "$dns_file"

delete_unnecessary_files

info "Creating summary file"
create_summary_file "${ROOTFS_DIR}"
}
Expand Down Expand Up @@ -721,6 +743,27 @@ detect_host_distro()
esac
}

delete_unnecessary_files()
{
info "Removing unneeded systemd services and sockets"
for u in "${systemd_units[@]}"; do
find "${ROOTFS_DIR}" \
\( -type f -o -type l \) \
\( -name "${u}.service" -o -name "${u}.socket" \) \
-exec echo "deleting {}" \; \
-exec rm -f {} \;
done

info "Removing unneeded systemd files"
for u in "${systemd_files[@]}"; do
find "${ROOTFS_DIR}" \
\( -type f -o -type l \) \
-name "${u}" \
-exec echo "deleting {}" \; \
-exec rm -f {} \;
done
}

main()
{
parse_arguments $*
Expand Down

0 comments on commit 1ee72c4

Please sign in to comment.