Skip to content

Instantly share code, notes, and snippets.

@Yousha
Last active May 27, 2024 09:13
Show Gist options
  • Save Yousha/6ebb8901ee114f399bfcd113c708c0cd to your computer and use it in GitHub Desktop.
Save Yousha/6ebb8901ee114f399bfcd113c708c0cd to your computer and use it in GitHub Desktop.
Shell script to update Linux kernel. (Traditionally)
#!/bin/sh
# Prepare.
set -o nounset # Abort on unbound variable.
set -o pipefail # Non-POSIX - Don't hide errors within pipes.
LANG=C
LC_CTYPE=C
LC_ALL=C
[ $UID != 0 ] && {
echo -e "\nYou don't have permission to run this script."
exit 13
}
[ "$(uname -m)" != x86_64 ] && {
echo -e "\nSystem architecture is not supported.\n"
exit 1
}
# Initialize.
VERSION_LINUX=6.7.6
export KVER=$VERSION_LINUX
FILE_SOURCE_LINUX=linux-$VERSION_LINUX.tar.xz
DIRECTORY_SOURCE_LINUX=linux-$VERSION_LINUX
mkdir -p /usr/src/
cd /usr/src/
rm -f $FILE_SOURCE_LINUX
# Download & extract.
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/$FILE_SOURCE_LINUX
sleep 1
tar -xvf $FILE_SOURCE_LINUX
sleep 1
# Cleanup source directory.
chown -R "$USER":"$USER" $DIRECTORY_SOURCE_LINUX/
cd $DIRECTORY_SOURCE_LINUX/
make mrproper
sleep 1
# Prepare config.
zcat /proc/config.gz >.config
make ARCH=x86_64 olddefconfig
sleep 1
# Compile.
make ARCH=x86_64 -j$(($(nproc) / 2 + 2)) all
sleep 1
# Remove old Linux packages.
# Install modules. (/lib/modules/)
make modules_install
# Install new vmlinuz and System.map files and rename old ones. (/boot/)
# For debugging, kernel "oops" trace, `ps`command...
make install
# Replace/Install headers in /usr/include/ and update version in /usr/include/linux/version.h.
make headers_install INSTALL_HDR_PATH=/usr
mv /boot/.config /boot/.config.old
cp -v .config /boot/.config
cp /boot/vmlinuz /boot/efi/EFI/Slackware/vmlinuz
# Install kernel source.
cd /usr/src/
rm $FILE_SOURCE_LINUX
rm linux
ln -s /usr/src/$DIRECTORY_SOURCE_LINUX linux
# Only Slackware Linux: Regenerate InitialRAMDisk.
/usr/share/mkinitrd/mkinitrd_command_generator.sh -k $VERSION_LINUX 1>update_mkinit.sh
chmod +x ./update_mkinit.sh
source ./update_mkinit.sh
rm ./update_mkinit.sh
# Finalize.
rm -rf /boot/initrd-tree/
#eliloconfig or update-grub or lilo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment