]>
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 BOOT_ROOT
=${ENTRY_DIR_ABS%/$MACHINE_ID/$KERNEL_VERSION}
22 BOOT_MNT
=$
(stat
-c %m
$BOOT_ROOT)
23 ENTRY_DIR
=/${ENTRY_DIR_ABS#$BOOT_MNT}
25 if [[ $COMMAND == remove
]]; then
26 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
27 rm -f "$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+"*".conf"
31 if ! [[ $COMMAND == add
]]; then
35 if ! [[ $KERNEL_IMAGE ]]; then
39 if [[ -f /etc
/os-release
]]; then
41 elif [[ -f /usr
/lib
/os-release
]]; then
45 if ! [[ $PRETTY_NAME ]]; then
46 PRETTY_NAME
="Linux $KERNEL_VERSION"
49 if [[ -f /etc
/kernel
/cmdline
]]; then
50 read -r -d '' -a BOOT_OPTIONS
< /etc
/kernel
/cmdline
51 elif [[ -f /usr
/lib
/kernel
/cmdline
]]; then
52 read -r -d '' -a BOOT_OPTIONS
< /usr
/lib
/kernel
/cmdline
54 declare -a BOOT_OPTIONS
56 read -r -d '' -a line
< /proc
/cmdline
57 for i
in "${line[@]}"; do
58 [[ "${i#initrd=*}" != "$i" ]] && continue
59 [[ "${i#BOOT_IMAGE=*}" != "$i" ]] && continue
64 if [[ -f /etc
/kernel
/tries
]]; then
65 read -r TRIES
</etc
/kernel
/tries
66 if ! [[ "$TRIES" =~ ^
[0-9]+$
]] ; then
67 echo "/etc/kernel/tries does not contain an integer." >&2
70 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION+$TRIES.conf"
72 LOADER_ENTRY
="$BOOT_ROOT/loader/entries/$MACHINE_ID-$KERNEL_VERSION.conf"
75 cp "$KERNEL_IMAGE" "$ENTRY_DIR_ABS/linux" &&
76 chown root
:root
"$ENTRY_DIR_ABS/linux" &&
77 chmod 0644 "$ENTRY_DIR_ABS/linux" ||
{
78 echo "Could not copy '$KERNEL_IMAGE to '$ENTRY_DIR_ABS/linux'." >&2
82 INITRD_OPTIONS
=( "${@:${INITRD_OPTIONS_START}}" )
84 for initrd
in "${INITRD_OPTIONS[@]}"; do
85 if [[ -f "${initrd}" ]]; then
86 initrd_basename
="$(basename ${initrd})"
87 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
88 echo "Installing $ENTRY_DIR_ABS/${initrd_basename}"
89 cp "${initrd}" "$ENTRY_DIR_ABS/${initrd_basename}" &&
90 chown root
:root
"$ENTRY_DIR_ABS/${initrd_basename}" &&
91 chmod 0644 "$ENTRY_DIR_ABS/${initrd_basename}" ||
{
92 echo "Could not copy '${initrd}' to '$ENTRY_DIR_ABS/${initrd_basename}'." >&2
98 # If no initrd option is supplied, fallback to "initrd" which is
99 # the name used by dracut when generating it in its kernel-install hook
100 [[ ${#INITRD_OPTIONS[@]} == 0 ]] && INITRD_OPTIONS
=( initrd
)
102 mkdir
-p "${LOADER_ENTRY%/*}" ||
{
103 echo "Could not create loader entry directory '${LOADER_ENTRY%/*}'." >&2
107 [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \
108 echo "Creating $LOADER_ENTRY"
110 echo "title $PRETTY_NAME"
111 echo "version $KERNEL_VERSION"
112 echo "machine-id $MACHINE_ID"
113 echo "options ${BOOT_OPTIONS[*]}"
114 echo "linux $ENTRY_DIR/linux"
115 for initrd
in "${INITRD_OPTIONS[@]}"; do
116 [[ -f $ENTRY_DIR_ABS/$
(basename ${initrd}) ]] && \
117 echo "initrd $ENTRY_DIR/$(basename ${initrd})"
120 } > "$LOADER_ENTRY" ||
{
121 echo "Could not create loader entry '$LOADER_ENTRY'." >&2