3 # This script is called automatically by new-kernel-pkg as
4 # /etc/kernel/postinst.d/loader-postinst.sh (Fedora)
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation; either version 2.1 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # Copyright (C) 2012 Harald Hoyer <harald@redhat.com>
17 # Copyright (C) 2012 Kay Sievers <kay@vrfy.org>
19 if (( $# != 2 )); then
20 echo "Usage: $0 <KERNEL_VERSION> <KERNEL_IMAGE>" >&2
27 if ! [[ -f $KERNEL_IMAGE ]]; then
28 echo "Can't find file $KERNEL_IMAGE!" >&2
32 if [[ -d /boot/loader/entries ]]; then
34 elif [[ -d /boot/efi/loader/entries ]]; then
38 if ! [[ $EFI_DIR ]] ; then
39 echo "Did not install new kernel and loader entry." >&2
40 echo "Please create the directory 'loader/entries/' in your EFI system partition." >&2
44 if [[ -f ${KERNEL_IMAGE/vmlinuz/initrd} ]]; then
45 INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initrd}
46 elif [[ -f ${KERNEL_IMAGE/vmlinuz/initrd}.img ]]; then
47 INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initrd}.img
48 elif [[ -f ${KERNEL_IMAGE/vmlinuz/initramfs}.img ]]; then
49 INITRD_IMAGE=${KERNEL_IMAGE/vmlinuz/initramfs}.img
52 if [[ -f /etc/kernel/cmdline ]]; then
54 BOOT_OPTIONS+="$line "
55 done < /etc/kernel/cmdline
57 if ! [[ $BOOT_OPTIONS ]]; then
59 BOOT_OPTIONS+="$line "
62 if ! [[ $BOOT_OPTIONS ]]; then
63 echo "Can't determine the kernel command line parameters." >&2
64 echo "Please specify the kernel command line in /etc/kernel/cmdline!" >&2
68 [[ -f /etc/os-release ]] && . /etc/os-release
70 echo "Can't determine the name of your distribution. Please create /etc/os-release." >&2
71 echo "See http://www.freedesktop.org/software/systemd/man/os-release.html" >&2
75 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
76 if ! [[ $MACHINE_ID ]]; then
77 echo "Can't determine your machine id. Please create /etc/machine-id!" >&2
78 echo "See http://www.freedesktop.org/software/systemd/man/machine-id.html" >&2
82 mkdir -p "${EFI_DIR}/${ID}/${MACHINE_ID}"
84 cp --preserve "$KERNEL_IMAGE" "${EFI_DIR}/${ID}/${MACHINE_ID}/"
85 [[ $INITRD_IMAGE ]] && cp --preserve "$INITRD_IMAGE" "${EFI_DIR}/${ID}/${MACHINE_ID}/"
88 echo "title $PRETTY_NAME"
89 echo "version $KERNEL_VERSION"
90 echo "machine-id $MACHINE_ID"
91 echo "options $BOOT_OPTIONS"
92 echo "linux /$ID/$MACHINE_ID/${KERNEL_IMAGE##*/}"
93 [[ $INITRD_IMAGE ]] && echo "initrd /${ID}/${MACHINE_ID}/${INITRD_IMAGE##*/}"
94 } > "${EFI_DIR}/loader/entries/${ID}-${KERNEL_VERSION}-${MACHINE_ID}.conf"
96 # now cleanup the old entries and files, for which no /lib/modules/$KERNEL_VERSION exists
98 cd ${EFI_DIR}/loader/entries
99 for conf in ${ID}-*-${MACHINE_ID}.conf; do
100 KERNEL_VERSION=${conf##$ID-}
101 KERNEL_VERSION=${KERNEL_VERSION%%-$MACHINE_ID.conf}
102 [[ $KERNEL_VERSION ]] || continue
103 [[ -d /lib/modules/${KERNEL_VERSION}/kernel ]] && continue
105 rm -f "${EFI_DIR}/${ID}/${MACHINE_ID}/*${KERNEL_VERSION}*"