Skip to content

Instantly share code, notes, and snippets.

@patrickshan
Created August 18, 2018 12:16
Show Gist options
  • Save patrickshan/732a34129c7928200717dc0561535d2f to your computer and use it in GitHub Desktop.
Save patrickshan/732a34129c7928200717dc0561535d2f to your computer and use it in GitHub Desktop.
Use ramdisk to build latest kernel deb package for debian
#!/bin/bash
if [[ $EUID -ne 0 ]]
then
echo "This script must be run as root"
exit 1
fi
if [[ $# -ne 1 ]]
then
echo "need to specify kernel version"
exit 1
fi
version=$1
VersionSeries=$(echo ${version} | cut -d. -f1)
# Download
url=https://cdn.kernel.org/pub/linux/kernel/v${VersionSeries}.x/linux-${version}.tar.xz
wget -S --spider ${url} 2>&1 | grep -q 'HTTP/1.1 200 OK'
if [[ $? == "1" ]]
then
echo "Could not find kernel with url: ${url}"
exit 1
fi
mkdir -p /tmp/ramdisk
# use 5GB ram as ramdisk
# building 4.18 kernel uses around 3.2GB
sudo mount -t tmpfs -o size=5G tmpfs /tmp/ramdisk
wget -O /tmp/ramdisk/linux-${version}.tar.xz ${url}
pushd /tmp/ramdisk
tar xf linux-${version}.tar.xz
cd linux-${version}
cp /boot/config-$(uname -r) ./.config
time make deb-pkg -j7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment