From 2dfb8bc54928de224f57908a2277035d1ef35b40 Mon Sep 17 00:00:00 2001 From: Pavel Mores Date: Thu, 13 Aug 2020 19:16:30 +0200 Subject: [PATCH] rootfs-builder: fix unbootable dracut-based initramfs on Fedora This is a forward port of Kata 1.x PR's https://github.com/kata-containers/osbuilder/pull/480 and https://github.com/kata-containers/osbuilder/pull/494 . Fixes #646 Signed-off-by: Pavel Mores --- .../osbuilder/image-builder/image_builder.sh | 25 +++++++++++++------ tools/osbuilder/rootfs-builder/rootfs.sh | 3 +-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/osbuilder/image-builder/image_builder.sh b/tools/osbuilder/image-builder/image_builder.sh index 6fd8c3ef55..1cc18552c9 100755 --- a/tools/osbuilder/image-builder/image_builder.sh +++ b/tools/osbuilder/image-builder/image_builder.sh @@ -186,14 +186,20 @@ check_rootfs() { OK "init is installed" - systemd_path="/lib/systemd/systemd" - systemd="${rootfs}${systemd_path}" + candidate_systemd_paths="/usr/lib/systemd/systemd /lib/systemd/systemd" # check agent or systemd case "${AGENT_INIT}" in "no") - if [ ! -x "${systemd}" ] && [ ! -L "${systemd}" ]; then - error "${systemd_path} is not installed in ${rootfs}" + for systemd_path in $candidate_systemd_paths; do + systemd="${rootfs}${systemd_path}" + if [ -x "${systemd}" ] || [ -L "${systemd}" ]; then + found="yes" + break + fi + done + if [ ! $found ]; then + error "None of ${candidate_systemd_paths} is installed in ${rootfs}" return 1 fi OK "init is systemd" @@ -207,10 +213,13 @@ check_rootfs() { return 1 fi # checksum must be different to system - if [ -f "${systemd}" ] && cmp -s "${systemd}" "${agent}"; then - error "The agent is not the init process. ${agent_path} is systemd" - return 1 - fi + for systemd_path in $candidate_systemd_paths; do + systemd="${rootfs}${systemd_path}" + if [ -f "${systemd}" ] && cmp -s "${systemd}" "${agent}"; then + error "The agent is not the init process. ${agent_path} is systemd" + return 1 + fi + done OK "Agent installed" ;; diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index 9800d9d8ce..5996f6c22a 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -441,8 +441,7 @@ prepare_overlay() # we were passed a pre-populated rootfs directory if [ ! -e ./sbin/init ]; then ln -sf ./usr/lib/systemd/systemd ./init - ln -sf ../../init ./lib/systemd/systemd - ln -sf ../init ./sbin/init + ln -sf /init ./sbin/init fi # Kata systemd unit file