diff --git a/linux/build-and-push.sh b/linux/build-and-push.sh new file mode 100755 index 0000000..6afa0b8 --- /dev/null +++ b/linux/build-and-push.sh @@ -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 +# +# 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.' diff --git a/linux/install.sh b/linux/install.sh new file mode 100755 index 0000000..65c4de6 --- /dev/null +++ b/linux/install.sh @@ -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 +# +# 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