Skip to content

Instantly share code, notes, and snippets.

@r0b0
Last active June 3, 2026 07:25
Show Gist options
  • Select an option

  • Save r0b0/92d4418091dd787bc135d8d346d4be08 to your computer and use it in GitHub Desktop.

Select an option

Save r0b0/92d4418091dd787bc135d8d346d4be08 to your computer and use it in GitHub Desktop.

Building kernel packages as debian packages, including meta-packages

Prerequisite packages

sudo apt install reprepro debsigs equivs

Clone a linux kernel tree into linux-git folder. Add a build script in that folder: vim linux-git/OPTIONS

#!/bin/bash

set -e

TODAY=$(date --iso-8601)
MAKEOPTS="LOCALVERSION=-r0b0-$TODAY -j $(nproc)"

make olddefconfig $MAKEOPTS
make vmlinux $MAKEOPTS
make modules $MAKEOPTS

# external modules (if any)
make M=../soft_3rdpart/wave511/code/vdi/linux/driver $MAKEOPTS
make M=../soft_3rdpart/codaj12/jdi/linux/driver $MAKEOPTS
make M=../soft_3rdpart/wave420l/code/vdi/linux/driver $MAKEOPTS

make bindeb-pkg $MAKEOPTS

echo cd ..
echo ./publish_deb.sh *.deb
echo cd deb-repo

Create a folder for repo: mkdir deb-repo

Generate a GPG key for signing the packages, set a nice name and email address gpg --generate-key

Export the public key gpg --output pubkey.gpg --armor --export trebula@gmail.com > deb-repo/pubkey.gpg

Document sources file for your repo vim deb-repo/r0b0-visionfive2-linux.sources

Types: deb
URIs: https://r0b0.github.io/visionfive2-linux
Suites: trixie
Components: main
Signed-By: /etc/apt/trusted.gpg.d/r0b0-visionfive2-linux.pgp
Architectures: riscv64

Document apt-pinning file for your repo vim deb-repo/r0b0-visionfive2-linux.pref

Package: *
Pin: origin r0b0.github.io
Pin-Priority: 600

A nice landing page vim deb-repo/index.html

<!DOCTYPE html>
<html lang="en">
        <head>
                <meta charset="UTF-8">
        </head>
        <body>
                <main class="container">
                        <h1>Unofficial linux kernel debian repository</h1>
                        <p>This is an unofficial fork </p>

                        <h1>Usage</h1>
                        <h2>Import the signing key</h2>
                        <pre>
curl https://r0b0.github.io/visionfive2-linux/pubkey.gpg | sudo gpg -o /etc/apt/trusted.gpg.d/r0b0-visionfive2-linux.pgp --dearmor
                        </pre>
                        <h2>Setup the repository</h2>
                        <pre>
sudo curl https://r0b0.github.io/visionfive2-linux/r0b0-visionfive2-linux.sources -o /etc/apt/sources.list.d/r0b0-visionfive2-linux.sources
                        </pre>
                        <h2>Pin the repository</h2>
                        <pre>
sudo curl https://r0b0.github.io/visionfive2-linux/r0b0-visionfive2-linux.pref -o /etc/apt/preferences.d/r0b0-visionfive2-linux.pref
                        </pre>
                        <h2>Update and use</h2>
                        <pre>
sudo apt update
sudo apt install linux-headers-riscv64 linux-image-riscv64 linux-libc-dev
                        </pre>
                </main>
        </body>
</html>

Script for signing and publishing the packages: vim publish_deb.sh

#!/bin/bash

SIGNING_KEY=8970D270917B7A0808F6AE2A1EBC6F94C6DA493E
REPO_DIR="/home/user/deb-repo"

if [ ! -f "${REPO_DIR}/index.html" ]; then
	echo "You need to switch to gh-pages branch first!"
	exit 1
fi

sign_and_repre() {
 local file=$1
 debsigs -v \
   --gpgopts="--batch --no-tty --pinentry-mode=loopback" \
   --sign=origin \
   --default-key="$SIGNING_KEY" \
   "$file"
 reprepro -Vb "${REPO_DIR}" includedeb trixie "$file"
}

create_meta_package() {
 local orig_deb=$1
 local control_template=$2
 local log="equivs_build_${orig_deb}.log"
 echo building a meta package from $orig_deb
 export package=$(dpkg-deb -I $orig_deb |grep Package | sed 's/.*: //')
 echo dependent package $package
 export version=$(dpkg-deb -I $orig_deb |grep Version | sed 's/.*: //')
 echo version $version
 envsubst < $control_template > control
 equivs-build control | tee "$log"
 rm control
 local generated_deb=$(grep "dpkg-deb: building package" "${log}" | sed -n 's/.* '\''\(..\)\/\(.*\.deb\)'\''.*/\2/p')
 rm "${log}"
 echo generated deb: ${generated_deb}
 sign_and_repre "$generated_deb"
}


for file in "$@"
do
 sign_and_repre "$file"
 if [[ $file =~ "linux-image-6" ]]; then
  create_meta_package "$file" linux-meta-package-control.template
 fi
 if [[ $file =~ "linux-headers-6" ]]; then
  create_meta_package "$file" linux-headers-meta-package-control.template
 fi
done

echo "done, you can add, commit and push now"

echo cd $REPO_DIR
echo git add db dists pool
echo git commit
echo git push

Template file for the kernel meta package: vim linux-meta-package-control.template

Package: linux-image-riscv64
Version: ${version}
Priority: optional
Section: kernel
Maintainer: Robert T <trebula@gmail.com>
Provides: linux-image-generic, linux-latest-modules-${version}, wireguard-modules (= 1.0.0)
Depends: ${package} (= ${version})
Homepage: https://github.com/r0b0/visionfive2-linux
Architecture: riscv64
Description: Linux for 64-bit RISC-V platforms (meta-package)
 This package depends on the latest Linux kernel and modules for use on
 64-bit RISC-V platforms.

Template file for the header meta package: vim linux-headers-meta-package-control.template

Package: linux-headers-riscv64
Version: ${version}
Priority: optional
Section: kernel
Source: linux
Maintainer: Robert T <trebula@gmail.com>
Provides: linux-headers-generic
Depends: ${package} (= ${version})
Homepage: https://github.com/r0b0/visionfive2-linux
Description: Header files for Linux riscv64 configuration (meta-package)
 This package depends on the architecture-specific header files for the
 latest Linux kernel riscv64 configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment