]>
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
4 # SPDX-License-Identifier: LGPL-2.1-or-later
6 # This file is part of systemd.
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 INITRD_OPTIONS_START
="5"
27 if ! [[ $KERNEL_INSTALL_MACHINE_ID ]]; then
31 if ! [[ -d "$ENTRY_DIR_ABS" ]]; then
35 MACHINE_ID
=$KERNEL_INSTALL_MACHINE_ID
37 BOOT_ROOT
=${ENTRY_DIR_ABS%/$MACHINE_ID/$KERNEL_VERSION}
38 BOOT_MNT
=$
(stat
-c %m
$BOOT_ROOT)
39 ENTRY_DIR
=${ENTRY_DIR_ABS#$BOOT_MNT}
41 if [[ $COMMAND == remove
]]; then
42 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
43 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
47 if ! [[ $COMMAND == add
]]; then
51 if ! [[ $KERNEL_IMAGE ]]; then
55 if [[ -f /etc
/os-release
]]; then
57 elif [[ -f /usr
/lib
/os-release
]]; then
61 if ! [[ $PRETTY_NAME ]]; then
62 PRETTY_NAME
="Linux $KERNEL_VERSION"
65 if [[ -f /etc
/kernel
/cmdline
]]; then
66 read -r -d '' -a BOOT_OPTIONS
< /etc
/kernel
/cmdline
67 elif [[ -f /usr
/lib
/kernel
/cmdline
]]; then
68 read -r -d '' -a BOOT_OPTIONS
< /usr
/lib
/kernel
/cmdline
70 declare -a BOOT_OPTIONS
72 read -r -d '' -a line
< /proc
/cmdline
73 for i
in "${line[@]}"; do
74 [[ "${i#initrd=*}" != "$i" ]] && continue
75 [[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
80 if [[ -f /etc
/kernel
/tries
]]; then
81 read -r TRIES
</etc
/kernel
/tries
82 if ! [[ "$TRIES" =~ ^
[0-9]+$
]] ; then
83 echo "/etc/kernel/tries does not contain an integer." >&2
86 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
88 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
91 cp "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" &&
92 chown root
:root
"$ENTRY_DIR_ABS/linux" &&
93 chmod 0644 "$ENTRY_DIR_ABS/linux" ||
{
94 echo "Could not copy '$KERNEL_IMAGE to '$ENTRY_DIR_ABS/linux'." >&2
98 INITRD_OPTIONS
=( "${@:${INITRD_OPTIONS_START}}" )
100 for initrd
in "${INITRD_OPTIONS[@]}"; do
101 if [[ -f "${initrd}" ]]; then
102 initrd_basename
="$(basename ${initrd})"
103 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
104 echo "Installing $ENTRY_DIR_ABS/${initrd_basename}"
105 cp "${initrd}" "$ENTRY_DIR_ABS/${initrd_basename}" &&
106 chown root
:root
"$ENTRY_DIR_ABS/${initrd_basename}" &&
107 chmod 0644 "$ENTRY_DIR_ABS/${initrd_basename}" ||
{
108 echo "Could not copy '${initrd}' to '$ENTRY_DIR_ABS/${initrd_basename}'." >&2
114 # If no initrd option is supplied, fall back to "initrd" which is
115 # the name used by dracut when generating it in its kernel-install hook
116 [[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS
=( initrd
)
118 mkdir
-p "${LOADER_ENTRY%/*}" ||
{
119 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
123 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
124 echo "Creating $LOADER_ENTRY"
126 echo "title $PRETTY_NAME"
127 echo "version $KERNEL_VERSION"
128 echo "machine-id $MACHINE_ID"
129 echo "options ${BOOT_OPTIONS[*]}"
130 echo "linux $ENTRY_DIR/linux"
131 for initrd
in "${INITRD_OPTIONS[@]}"; do
132 [[ -f $ENTRY_DIR_ABS/$
(basename ${initrd}) ]] && \
133 echo "initrd $ENTRY_DIR/$(basename ${initrd})"
136 } > "$LOADER_ENTRY" ||
{
137 echo "Could not create loader entry '$LOADER_ENTRY'." >&2