Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/driver/flatcar: Update the script #425

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 49 additions & 21 deletions pkg/driver/distro/flatcar.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,57 @@ import (
)

const flatcarRelocateScript = `
local -a tools=(
scripts/basic/fixdep
scripts/mod/modpost
tools/objtool/objtool
)
local -r hostld=$(ls /host/usr/lib64/ld-linux-*.so.*)
local -r kdir=/lib/modules/$(ls /lib/modules/)/build
echo "** Found host dl interpreter: ${hostld}"
for host_tool in ${tools[@]}; do
t=${host_tool}
tool=$(basename $t)
tool_dir=$(dirname $t)
host_tool=${kdir}/${host_tool}
if [ ! -f ${host_tool} ]; then
set -euo pipefail

shopt -s nullglob

hostlds=( /host/usr/lib64/ld-linux-*.so.* )
if [[ ${#hostlds[@]} -eq 0 ]]; then
echo "** no dynamic loaders found"
exit 1
fi
if [[ ${#hostlds[@]} -gt 1 ]]; then
echo "** more than one fitting dynamic loader found, picking first"
fi
hostld=${hostlds[0]}
echo "** Found host dynamic loader: ${hostld}"

kdirs=( /host/lib/modules/*/build )
if [[ ${#kdirs[@]} -eq 0 ]]; then
echo "** no kernel module tools directories found"
exit 1
fi
if [[ ${#kdirs[@]} -gt 1 ]]; then
echo "** more than one fitting kernel module tools directory found, picking first"
fi
kdir=${kdirs[0]}
echo "** Found kernel tools directory: ${kdir}"

tools=(
scripts/basic/fixdep
scripts/mod/modpost
tools/objtool/objtool
)

tmp_dir=$(mktemp -d)
for tool in "${tools[@]}"; do
host_tool=${kdir}/${tool}
if [[ ! -f ${host_tool} ]]; then
echo "${tool@Q} not found in ${kdir@Q}, not patching"
continue
fi
umount ${host_tool} 2>/dev/null || true
mkdir -p /tmp/${tool_dir}/
cp -a ${host_tool} /tmp/${tool_dir}/
echo "** Setting host dl interpreter for $host_tool"
patchelf --set-interpreter ${hostld} --set-rpath /host/usr/lib64 /tmp/${tool_dir}/${tool}
mount -o bind /tmp/${tool_dir}/${tool} ${host_tool}
umount "${host_tool}" 2>/dev/null || true
tmp_tool=${tmp_dir}/${tool}
mkdir -p "$(dirname "${tmp_tool}")"
cp -a "${host_tool}" "${tmp_tool}"
echo "** Setting host dynamic loader for ${tool@Q}"
patchelf \
--set-interpreter "${hostld}" \
--set-rpath /host/usr/lib64 \
"${tmp_tool}"
mount -o bind "${tmp_tool}" "${host_tool}"
done
rm -rf "${tmp_dir}"
`

func init() {
Expand Down Expand Up @@ -94,7 +122,7 @@ func (f *flatcar) customizeBuild(ctx context.Context,
return nil, nil
}
printer.Logger.Info("Flatcar detected; relocating kernel tools.", printer.Logger.Args("version", f.versionID))
out, err := exec.CommandContext(ctx, "/bin/bash", "-c", flatcarRelocateScript).Output()
out, err := exec.CommandContext(ctx, "/bin/bash", "-c", flatcarRelocateScript).CombinedOutput()
if err != nil {
printer.DefaultText.Print(string(out))
}
Expand Down