Add kernel build and install scripts

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2024-08-23 15:05:08 +02:00
parent 3c32052382
commit 852c2e4699
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57
2 changed files with 117 additions and 0 deletions

87
linux/build-and-push.sh Executable file
View File

@ -0,0 +1,87 @@
#!/bin/ksh
# Sloppy tool to assist with Linux kernel bisection
#
# 1. Resets upstream kernel sources
# 2. Applies SUSE patches on upstream Linux sources
# 3. Builds Linux
# 4. Copies result to a target over SSH
# 5. Installs result on target, including initrd (Dracut) and boot entry (GRUB)
#
# Copyright 2024 Georg Pfuetzenreuter <mail+opensuse@georg-pfuetzenreuter.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -Ceux
GIT_LINUX=~/Work/git/linux
GIT_LINUX_PATCHES=~/Work/git/kernel-source
LINUX_BUILD=~/Work/kernel-build
LINUX_CONFIG=default
LINUX_VERSION=6.4.0-"$LINUX_CONFIG"-dirty
TARGET_USER=root
TARGET_HOST=192.168.5.92
TARGET_HOST_IP="$TARGET_HOST"/24
TARGET_PIPE=/run/user/"$(id -u)"/bisect
TARGET_BUILD=/tmp/build
SSH_KEY=~/.ssh/bisect.pub
SSH="ssh -i $SSH_KEY -q -l $TARGET_USER $TARGET_HOST"
if ! $SSH -- true
then
echo "Host $TARGET_HOST is not ready."
exit 1
fi
GIT_COMMIT="$(git -C "$GIT_LINUX_PATCHES" rev-parse --short HEAD)"
LINUX_BUILD="$LINUX_BUILD"/"$GIT_COMMIT"
if [ -d "$LINUX_BUILD" ]
then
echo "Commit $GIT_COMMIT has already been built!"
exit 1
fi
install -dv "$LINUX_BUILD"
pushd "$GIT_LINUX"
git clean -df
git restore .
"$GIT_LINUX_PATCHES"/rpm/apply-patches "$GIT_LINUX_PATCHES"/series.conf "$GIT_LINUX_PATCHES"
popd
install -vm0644 "$GIT_LINUX_PATCHES"/config/x86_64/"$LINUX_CONFIG" "$LINUX_BUILD"/.config
make -C"$GIT_LINUX" -j"$(nproc)" O="$LINUX_BUILD"
$SSH -- rm -fr "$TARGET_BUILD"
rsync --exclude='.tmp*' --info=progress2 -lr "$LINUX_BUILD"/ "$TARGET_USER"@"$TARGET_HOST":"$TARGET_BUILD"
$SSH -- make -C/usr/src/linux O="$TARGET_BUILD" modules_install
$SSH -- make -C/usr/src/linux O="$TARGET_BUILD" install
VMLINUZ=/boot/vmlinuz-"$GIT_COMMIT"
INITRD=/boot/initrd-"$GIT_COMMIT"
$SSH -- install -vm0644 "$TARGET_BUILD"/arch/x86/boot/bzImage "$VMLINUZ"
$SSH -- dracut --kernel-image "$VMLINUZ" "$INITRD" "$LINUX_VERSION"
$SSH -- grub2-mkconfig -o /boot/grub2/grub.cfg
ROOT="$($SSH -- blkid -o value -s UUID -t LABEL=ROOT)"
echo "Root partition UUID: $ROOT"
echo 'Now reboot, test, and update the bisection.'

30
linux/install.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh -Cefu
# Copies a newly built Linux, creates an initrd image and a GRUB boot entry
#
# Copyright 2024 Georg Pfuetzenreuter <mail+opensuse@georg-pfuetzenreuter.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
builddir=/tmp/build
commit="${1?Specify commit hash}"
make -C/usr/src/linux -j6 O="$builddir" modules_install
make -C/usr/src/linux O="$builddir" install
VMLINUZ=/boot/vmlinuz-"$commit"
INITRD=/boot/initrd-"$commit"
LINUX_VERSION=6.4.0-default-dirty
install -vm0644 "$builddir"/arch/x86/boot/bzImage "$VMLINUZ"
dracut --kernel-image "$VMLINUZ" "$INITRD" "$LINUX_VERSION"
grub2-mkconfig -o /boot/grub2/grub.cfg