Skip to content

How to buld the kernel deb images

guojinhui-liam edited this page Jun 6, 2025 · 6 revisions
  • You can use build.sh as follows to build the deb image for debian OS.
  • Create the build.sh and then copy it to the linux kernel directory.
#!/bin/bash
set -x
set -e

declare -A archs=(
        ["x86_64"]="amd64"
        ["aarch64"]="arm64"
)

arch=${archs[$(uname -m)]}
if [ -z "$arch" ]; then
        echo "Unknown arch: $(uname -m)"
        exit 1
fi

if test -z "$CI_KERNEL_VERSION"; then
        pattern_bsk="v[0-9].[0-9]*.[0-9]*.bsk.[0-9]*"
        pattern_vk="v[0-9].[0-9]*.[0-9]*.vk.*"
        pattern_ve="v[0-9].[0-9]*.[0-9]*.ve.*"
        if git describe --dirty --tags | grep -q bsk; then
                version=$(git describe --dirty --tags --match "$pattern_bsk" | cut -c 2-)
        elif git describe --dirty --tags | grep -q vk; then
                version=$(git describe --dirty --tags --match "$pattern_vk" | cut -c 2-)
        else
                version=$(git describe --dirty --tags --match "$pattern_ve" | cut -c 2-)
        fi
        if [ -z "$version" ]; then
                echo "Don't have bsk release tag in git log, use hash as temp version."
                majorversion=$(grep -E "^VERSION = " Makefile | cut -d' ' -f3)
                patchlevel=$(grep -E "^PATCHLEVEL = " Makefile | cut -d' ' -f3)
                sublevel=$(grep -E "^SUBLEVEL = " Makefile | cut -d' ' -f3)
                hash=$(git rev-parse --short HEAD)
                version="$majorversion.$patchlevel.$sublevel-$hash"
        fi
else
        version=$CI_KERNEL_VERSION
fi

if test -n "$BASE_PAGE"; then
        version_suffix="-$BASE_PAGE"
fi

# build veLinux2 kernel with veLinux timestamp
if lsb_release -c | grep -q bookworm ; then
        timestamp="veLinux $version $(date)"
else
        timestamp="Debian $version $(date)"
fi

cp config."$(uname -m)$version_suffix" .config
version="$version$version_suffix"

if test -n "$SIGN_KERNEL"; then
        sed -i "/^# *CONFIG_MODULE_SIG_FORCE */c\CONFIG_MODULE_SIG_FORCE=y" .config
        sed -i "/^# *CONFIG_MODULE_SIG_ALL */c\CONFIG_MODULE_SIG_ALL=y" .config
        sed -i "/^ *CONFIG_MODULE_SIG_KEY=/c\CONFIG_MODULE_SIG_KEY=\"kernel_key.pem\"" .config
        version="$version-sign"
fi

make olddefconfig

BUILD_CFLAGS="-Werror"

localversion="$(echo $version | sed 's/^[0-9]\+\.[0-9]\+\.[0-9]\+//')"
krelease="$version-$arch"
make deb-pkg                                    \
     BUILD_TOOLS=y                              \
     KDEB_PKGVERSION="$version"                 \
     KERNELRELEASE="$krelease"                  \
     LOCALVERSION="$localversion"               \
     KBUILD_BUILD_TIMESTAMP="$timestamp"        \
     KBUILD_BUILD_USER="STE-Kernel"             \
     KBUILD_BUILD_HOST="ByteDance"              \
     DPKG_FLAGS="-sn"                           \
     CFLAGS_KERNEL="$BUILD_CFLAGS"              \
     CFLAGS_MODULE="$BUILD_CFLAGS"              \
     KDEB_SOURCENAME="linux"                    \
     "$@"
  • Go to linux kernel source directory and then checkout to the target branch. Build the 64k deb images for aarch64:
chmod +x build.sh
BASE_PAGE="64k" ./build.sh "-j$(nproc)"
  • Go to linux kernel source directory and then checkout to the target branch. Build the 4k deb images for aarch64 or amd64:
chmod +x build.sh
./build.sh "-j$(nproc)"

Clone this wiki locally