]>
git.proxmox.com Git - 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 if [[ $BOOT_MNT == '/' ]]; then
40 ENTRY_DIR
=$ENTRY_DIR_ABS
42 ENTRY_DIR
=${ENTRY_DIR_ABS#$BOOT_MNT}
45 if [[ $COMMAND == remove
]]; then
46 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
47 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
51 if ! [[ $COMMAND == add
]]; then
55 if ! [[ $KERNEL_IMAGE ]]; then
59 if [[ -f /etc
/os-release
]]; then
61 elif [[ -f /usr
/lib
/os-release
]]; then
65 if ! [[ $PRETTY_NAME ]]; then
66 PRETTY_NAME
="Linux $KERNEL_VERSION"
69 if [[ -f /etc
/kernel
/cmdline
]]; then
70 read -r -d '' -a BOOT_OPTIONS
< /etc
/kernel
/cmdline
71 elif [[ -f /usr
/lib
/kernel
/cmdline
]]; then
72 read -r -d '' -a BOOT_OPTIONS
< /usr
/lib
/kernel
/cmdline
74 declare -a BOOT_OPTIONS
76 read -r -d '' -a line
< /proc
/cmdline
77 for i
in "${line[@]}"; do
78 [[ "${i#initrd=*}" != "$i" ]] && continue
79 [[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
84 if [[ -f /etc
/kernel
/tries
]]; then
85 read -r TRIES
</etc
/kernel
/tries
86 if ! [[ "$TRIES" =~ ^
[0-9]+$
]] ; then
87 echo "/etc/kernel/tries does not contain an integer." >&2
90 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
92 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
95 install -g root
-o root
-m 0644 "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" ||
{
96 echo "Could not copy '$KERNEL_IMAGE' to '$ENTRY_DIR_ABS/linux'." >&2
100 INITRD_OPTIONS
=( "${@:${INITRD_OPTIONS_START}}" )
102 for initrd
in "${INITRD_OPTIONS[@]}"; do
103 if [[ -f "${initrd}" ]]; then
104 initrd_basename
="$(basename ${initrd})"
105 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
106 echo "Installing $ENTRY_DIR_ABS/${initrd_basename}"
107 install -g root
-o root
-m 0644 "${initrd}" "$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