Skip to content

Instantly share code, notes, and snippets.

@alinefr
Created December 22, 2016 06:53
Show Gist options
  • Save alinefr/0a2fc89b742f2fb6b8f71c1fcd7782f5 to your computer and use it in GitHub Desktop.
Save alinefr/0a2fc89b742f2fb6b8f71c1fcd7782f5 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Copyright (C) 1995 - 1998, Ian A. Murdock <[email protected]>
# 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
# Copyright (C) 2016 Aline Freitas
#
# This script is called from /usr/src/linux/arch/i386/boot/install.sh.
# If you install it as /root/bin/installkernel, you can do a "make install"
# from a generic kernel source tree, and the image will be installed to
# the proper place for EFI system.
set -e
efi_dest=/boot/EFI/Boot
# EFI stub kernel without extension ".efi"!!
efi_file=bootx64
kernel_src=/usr/src/linux
kernversion () {
echo $(file $1 | grep -Po '(?<=version)\W*\K[^ ]*')
}
# 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 () {
builtkernver=$(kernversion $kernel_src/$img)
currentkernver=$(kernversion $efi_dest/${efi_file}.efi)
if [[ $builtkernver != $currentkernver ]]; then
echo "Moving current kernel to bootx64.old.efi..."
mv $efi_dest/${efi_file}{,.old}.efi
fi
cat "$kernel_src/$img" > "$efi_dest/${efi_file}.efi"
}
updatever
if [ $? -eq 0 ]; then
echo "Kernel installed as ${efi_dest}/${efi_file}.efi"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment