]>
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 "$BOOT_DIR_ABS" ]]; then
19 MACHINE_ID
=$KERNEL_INSTALL_MACHINE_ID
21 BOOT_DIR
="/$MACHINE_ID/$KERNEL_VERSION"
22 BOOT_ROOT
=${BOOT_DIR_ABS%$BOOT_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 declare -a BOOT_OPTIONS
50 if [[ -f /etc
/kernel
/cmdline
]]; then
51 read -r -d '' -a BOOT_OPTIONS
< /etc
/kernel
/cmdline
54 if ! [[ ${BOOT_OPTIONS[*]} ]]; then
55 read -r -d '' -a line
< /proc
/cmdline
56 for i
in "${line[@]}"; do
57 [[ "${i#initrd=*}" != "$i" ]] && continue
62 if ! [[ ${BOOT_OPTIONS[*]} ]]; then
63 echo "Could not determine the kernel command line parameters." >&2
64 echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
68 if [[ -f /etc
/kernel
/tries
]]; then
69 read -r TRIES
</etc
/kernel
/tries
70 if ! [[ "$TRIES" =~ ^
[0-9]+$
]] ; then
71 echo "/etc/kernel/tries does not contain an integer." >&2
74 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
76 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
79 cp "$KERNEL_IMAGE" "$BOOT_DIR_ABS/linux" &&
80 chown root
:root
"$BOOT_DIR_ABS/linux" &&
81 chmod 0644 "$BOOT_DIR_ABS/linux" ||
{
82 echo "Could not copy '$KERNEL_IMAGE to '$BOOT_DIR_ABS/linux'." >&2
86 INITRD_OPTIONS
=( "${@:${INITRD_OPTIONS_START}}" )
88 for initrd
in "${INITRD_OPTIONS[@]}"; do
89 if [[ -f "${initrd}" ]]; then
90 initrd_basename
="$(basename ${initrd})"
91 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
92 echo "Installing $BOOT_DIR_ABS/${initrd_basename}"
93 cp "${initrd}" "$BOOT_DIR_ABS/${initrd_basename}" &&
94 chown root
:root
"$BOOT_DIR_ABS/${initrd_basename}" &&
95 chmod 0644 "$BOOT_DIR_ABS/${initrd_basename}" ||
{
96 echo "Could not copy '${initrd}' to '$BOOT_DIR_ABS/${initrd_basename}'." >&2
102 # If no initrd option is supplied, fallback to "initrd" which is
103 # the name used by dracut when generating it in its kernel-install hook
104 [[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS
=( initrd
)
106 mkdir
-p "${LOADER_ENTRY%/*}" ||
{
107 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
111 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
112 echo "Creating $LOADER_ENTRY"
114 echo "title $PRETTY_NAME"
115 echo "version $KERNEL_VERSION"
116 echo "machine-id $MACHINE_ID"
117 echo "options ${BOOT_OPTIONS[*]}"
118 echo "linux $BOOT_DIR/linux"
119 for initrd
in "${INITRD_OPTIONS[@]}"; do
120 [[ -f $BOOT_DIR_ABS/$
(basename ${initrd}) ]] && \
121 echo "initrd $BOOT_DIR/$(basename ${initrd})"
124 } > "$LOADER_ENTRY" ||
{
125 echo "Could not create loader entry '$LOADER_ENTRY'." >&2