Skip to content

Instantly share code, notes, and snippets.

@rgov
Last active June 24, 2023 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgov/68e4a82a61beac26987ce8a674f099d0 to your computer and use it in GitHub Desktop.
Save rgov/68e4a82a61beac26987ce8a674f099d0 to your computer and use it in GitHub Desktop.
Building a patched Ubuntu kernel
#!/bin/bash -eu
LINUX_META_PKG='linux-meta'
LINUX_PKG='linux-image-unsigned-"$KERNEL_ABI_VERSION"-generic'
# Enable apt source repositories
sed -i '/^deb /{n; s/^# deb-src/deb-src/;}' /etc/apt/sources.list
apt update
apt install -y dpkg-dev
# Download the linux-meta sources
apt source "$LINUX_META_PKG"
mv "$LINUX_META_PKG"-[0123456789]* linux-meta
# Determine the kernel ABI version referenced by the package
pushd linux-meta
KERNEL_ABI_VERSION=$(\
dpkg-parsechangelog -SVersion | awk -F. '{print $1"."$2"."$3"-"$4}')
popd
# Perform environment variable expansion on LINUX_PKG
LINUX_PKG=$(eval "echo ${LINUX_PKG}")
# Download the corresponding unsigned kernel sources
apt source "$LINUX_PKG"
mv "$LINUX_PKG"-[0123456789]* linux
# Install dependencies for these two packages
apt build-dep -y "$LINUX_META_PKG" "$LINUX_PKG"
# Build the packages
for PKG in linux linux-meta; do
pushd "$PKG"
dpkg-buildpackage -rfakeroot -uc -b
popd
done
@rgov
Copy link
Author

rgov commented Jun 16, 2023

For the Raspberry Pi kernel it should be:

LINUX_META_PKG='linux-meta-raspi'
LINUX_PKG='linux-image-"$KERNEL_ABI_VERSION"-raspi'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment