]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/kernel-install/90-loaderentry.install
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
9 INITRD_OPTIONS_START
="5"
11 if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
15 if ! [[ -d "$ENTRY_DIR_ABS" ]]; then
19 MACHINE_ID
=$KERNEL_INSTALL_MACHINE_ID
21 ENTRY_DIR
="/$MACHINE_ID/$KERNEL_VERSION"
22 BOOT_ROOT
=${ENTRY_DIR_ABS%$ENTRY_DIR}
24 if [[ $COMMAND == remove
]]; then
25 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
26 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
30 if ! [[ $COMMAND == add
]]; then
34 if ! [[ $KERNEL_IMAGE ]]; then
38 if [[ -f /etc
/os-release
]]; then
40 elif [[ -f /usr
/lib
/os-release
]]; then
44 if ! [[ $PRETTY_NAME ]]; then
45 PRETTY_NAME
="Linux $KERNEL_VERSION"
48 if [[ -f /etc
/kernel
/cmdline
]]; then
49 read -r -d '' -a BOOT_OPTIONS
< /etc
/kernel
/cmdline
50 elif [[ -f /usr
/lib
/kernel
/cmdline
]]; then
51 read -r -d '' -a BOOT_OPTIONS
< /usr
/lib
/kernel
/cmdline
53 declare -a BOOT_OPTIONS
55 read -r -d '' -a line
< /proc
/cmdline
56 for i
in "${line[@]}"; do
57 [[ "${i#initrd=*}" != "$i" ]] && continue
62 if [[ -f /etc
/kernel
/tries
]]; then
63 read -r TRIES
</etc
/kernel
/tries
64 if ! [[ "$TRIES" =~ ^
[0-9]+$
]] ; then
65 echo "/etc/kernel/tries does not contain an integer." >&2
68 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
70 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
73 cp "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" &&
74 chown root
:root
"$ENTRY_DIR_ABS/linux" &&
75 chmod 0644 "$ENTRY_DIR_ABS/linux" ||
{
76 echo "Could not copy '$KERNEL_IMAGE to '$ENTRY_DIR_ABS/linux'." >&2
80 INITRD_OPTIONS
=( "${@:${INITRD_OPTIONS_START}}" )
82 for initrd
in "${INITRD_OPTIONS[@]}"; do
83 if [[ -f "${initrd}" ]]; then
84 initrd_basename
="$(basename ${initrd})"
85 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
86 echo "Installing $ENTRY_DIR_ABS/${initrd_basename}"
87 cp "${initrd}" "$ENTRY_DIR_ABS/${initrd_basename}" &&
88 chown root
:root
"$ENTRY_DIR_ABS/${initrd_basename}" &&
89 chmod 0644 "$ENTRY_DIR_ABS/${initrd_basename}" ||
{
90 echo "Could not copy '${initrd}' to '$ENTRY_DIR_ABS/${initrd_basename}'." >&2
96 # If no initrd option is supplied, fallback to "initrd" which is
97 # the name used by dracut when generating it in its kernel-install hook
98 [[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS
=( initrd
)
100 mkdir
-p "${LOADER_ENTRY%/*}" ||
{
101 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
105 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
106 echo "Creating $LOADER_ENTRY"
108 echo "title $PRETTY_NAME"
109 echo "version $KERNEL_VERSION"
110 echo "machine-id $MACHINE_ID"
111 echo "options ${BOOT_OPTIONS[*]}"
112 echo "linux $ENTRY_DIR/linux"
113 for initrd
in "${INITRD_OPTIONS[@]}"; do
114 [[ -f $ENTRY_DIR_ABS/$
(basename ${initrd}) ]] && \
115 echo "initrd $ENTRY_DIR/$(basename ${initrd})"
118 } > "$LOADER_ENTRY" ||
{
119 echo "Could not create loader entry '$LOADER_ENTRY'." >&2