Generate /etc/kernel/cmdline if it does not exist

Don't fall back to reading /proc/cmdline: that will likely reflect the
installer environment which will result in a non-booting kernel entry.

See-also: rhbz#1940288
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
This commit is contained in:
Robbie Harwood 2023-01-17 11:33:21 -05:00
parent c33643ba10
commit 77693cd7eb

View File

@ -76,16 +76,24 @@ case "$COMMAND" in
if [[ ! -f /sbin/new-kernel-pkg || -d "${BLS_DIR}" ]]; then
declare -a BOOT_OPTIONS
if [[ ! -f /etc/kernel/cmdline ]]; then
last=''
for entry in "${BLS_DIR}"/*.conf; do
last="$entry"
done
if [[ ! -z "$last" ]]; then
args="$(awk '/options/{$1="";$0=$0;$1=$1;print}' $last)"
echo "$args" > /etc/kernel/cmdline
fi
fi
if [[ -f /etc/kernel/cmdline ]]; then
read -r -d '' -a BOOT_OPTIONS < /etc/kernel/cmdline
fi
if ! [[ ${BOOT_OPTIONS[*]} ]]; then
read -r -d '' -a line < /proc/cmdline
for i in "${line[@]}"; do
[[ "${i#initrd=*}" != "$i" || "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
BOOT_OPTIONS+=("$i")
done
echo "Could not determine the kernel command line parameters." >&2
echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
exit 1
fi
[[ -d "$BLS_DIR" ]] || mkdir -m 0700 -p "$BLS_DIR"