mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-27 11:31:05 +00:00
rootfs: delete systemd units/files from rootfs.sh
Move the deletion of unnecessary systemd units and files from image_builder.sh into rootfs.sh. The files being deleted can be applicable to other image file formats too, not just to the rootfs-image format created by image_builder.sh. Also, image_builder.sh was deleting these files *after* it calculated the size of the rootfs files, thus missing out on the opportunity to possibly create a smaller image file. Signed-off-by: Dan Mihai <dmihai@microsoft.com>
This commit is contained in:
parent
2d9baf899a
commit
a49d0fb343
@ -49,30 +49,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-udevd"
|
||||
"systemd-udevd-control"
|
||||
"systemd-udevd-kernel"
|
||||
"systemd-udev-trigger"
|
||||
"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}
|
||||
@ -455,21 +431,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"
|
||||
}
|
||||
|
@ -66,6 +66,29 @@ if [ "${CROSS_BUILD}" == "true" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
# 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-udevd"
|
||||
"systemd-udevd-control"
|
||||
"systemd-udevd-kernel"
|
||||
"systemd-udev-trigger"
|
||||
"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="${?}"
|
||||
@ -768,6 +791,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}"
|
||||
}
|
||||
@ -807,6 +832,25 @@ 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 \
|
||||
\( -name "${u}.service" -o -name "${u}.socket" \) \
|
||||
-exec rm -f {} \;
|
||||
done
|
||||
|
||||
info "Removing unneeded systemd files"
|
||||
for u in "${systemd_files[@]}"; do
|
||||
find "${ROOTFS_DIR}" \
|
||||
-type f \
|
||||
-name "${u}" \
|
||||
-exec rm -f {} \;
|
||||
done
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
parse_arguments $*
|
||||
|
Loading…
Reference in New Issue
Block a user