add install_uefistub.sh
script to install uefi-stub kernels with efibootmngr
This commit is contained in:
parent
8ea9d9ccd1
commit
bab3e4a23b
1 changed files with 107 additions and 0 deletions
107
install_uefistub.sh
Executable file
107
install_uefistub.sh
Executable file
|
@ -0,0 +1,107 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 1995 - 1998, Ian A. Murdock <imurdock@debian.org>
|
||||
# Copyright (C) 1998, 1999, Guy Maor
|
||||
# Copyright (C) 2002, Matthew Wilcox
|
||||
# Copyright (C) 2002, 2004, 2005, 2007, 2009 Clint Adams
|
||||
# Copyright (C) 2009 Manoj Srivasta
|
||||
#
|
||||
# Install the kernel on a Debian Linux system.
|
||||
#
|
||||
# This script is called from /usr/src/linux/arch/i386/boot/install.sh.
|
||||
# If you install it as /sbin/installkernel, you can do a "make install"
|
||||
# from a generic kernel source tree, and the image will be installed to
|
||||
# the proper place for Debian GNU/Linux.
|
||||
|
||||
set -e
|
||||
set -x
|
||||
# Parse the command line options. Of course, powerpc has to be all
|
||||
# different, and passes in a fifth argument, just because it is
|
||||
# "special". We ignore the fifth argument, and do not flag is as an
|
||||
# error, which it would be for any arch apart from powerpc
|
||||
if [ $# -eq 3 ] || [ $# -eq 4 ] || [ $# -eq 5 ] ; then
|
||||
img="$2"
|
||||
map="$3"
|
||||
ver="$1"
|
||||
if [ $# -ge 4 ] && [ -n "$4" ] ; then
|
||||
dir="$4"
|
||||
else
|
||||
dir="/boot"
|
||||
fi
|
||||
else
|
||||
echo "Usage: installkernel <version> <image> <System.map> <directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create backups of older versions before installing
|
||||
updatever () {
|
||||
if [ -f "$dir/$1-$ver" ] ; then
|
||||
mv "$dir/$1-$ver" "$dir/$1-$ver.old"
|
||||
fi
|
||||
|
||||
cat "$2" > "$dir/$1-$ver"
|
||||
|
||||
# This section is for backwards compatibility only
|
||||
if test -f "$dir/$1" ; then
|
||||
# The presence of "$dir/$1" is unusual in modern intallations, and
|
||||
# the results are mostly unused. So only recreate them if they
|
||||
# already existed.
|
||||
if test -L "$dir/$1" ; then
|
||||
# If we were using links, continue to use links, updating if
|
||||
# we need to.
|
||||
if [ "$(readlink -f ${dir}/${1})" = "${dir}/${1}-${ver}" ]; then
|
||||
# Yup, we need to change
|
||||
ln -sf "$1-$ver.old" "$dir/$1.old"
|
||||
else
|
||||
mv "$dir/$1" "$dir/$1.old"
|
||||
fi
|
||||
ln -sf "$1-$ver" "$dir/$1"
|
||||
else # No links
|
||||
mv "$dir/$1" "$dir/$1.old"
|
||||
cat "$2" > "$dir/$1"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
updateefi () {
|
||||
targetName="${1}-${ver}.efi"
|
||||
commandline="root=UUID=981395d2-7045-4e5e-a20d-509e35a5b99b ro quiet initrd=\\initramfs"
|
||||
efidevice="/dev/nvme0n1"
|
||||
efiimage="$dir/EFI/GentooKernelstub/$targetName"
|
||||
if [ -f "$efiimage" ] ; then
|
||||
mv "$efiimage" "$efiimage".old
|
||||
fi
|
||||
|
||||
cat "$2" > "$efiimage"
|
||||
if ! efibootmgr | grep -q "$ver" ; then
|
||||
efibootmgr -d "${efidevice}" -p 1 --create --label "Gentoo Kernel $ver" --loader "EFI\\GentooKernelstub\\${targetName}" -u "$commandline"
|
||||
fi
|
||||
|
||||
echo Done installing efi
|
||||
}
|
||||
|
||||
if [ "$(basename $img)" = "vmlinux" ] ; then
|
||||
img_dest=vmlinux
|
||||
else
|
||||
img_dest=vmlinuz
|
||||
fi
|
||||
updatever $img_dest "$img"
|
||||
updateefi $img_dest "$img"
|
||||
updatever System.map "$map"
|
||||
|
||||
config=$(dirname "$map")
|
||||
config="${config}/.config"
|
||||
if [ -f "$config" ] ; then
|
||||
updatever config "$config"
|
||||
fi
|
||||
|
||||
# If installing in the usual directory, run the same scripts that hook
|
||||
# into kernel package installation. Also make sure the PATH includes
|
||||
# /usr/sbin and /sbin, just as dpkg would.
|
||||
if [ "$dir" = "/boot" ]; then
|
||||
PATH="$PATH:/usr/sbin:/sbin" \
|
||||
run-parts --verbose --exit-on-error --arg="$ver" --arg="$dir/$img_dest-$ver" \
|
||||
/etc/kernel/postinst.d
|
||||
fi
|
||||
|
||||
exit 0
|
Loading…
Add table
Reference in a new issue