update kernel-builder

Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
Jess Frazelle 2018-05-28 22:21:15 -04:00
parent d4ce312cc2
commit 73175a0c6a
No known key found for this signature in database
GPG Key ID: 18F3685C0022BFF3
2 changed files with 100 additions and 70 deletions

View File

@ -1,28 +1,21 @@
FROM debian:buster FROM r.j3ss.co/wireguard:install
LABEL maintainer "Jessie Frazelle <jess@linux.com>" LABEL maintainer "Jessie Frazelle <jess@linux.com>"
RUN dpkg --add-architecture arm64 \ RUN apk add --no-cache \
&& dpkg --add-architecture ppc64el \ bash \
&& apt-get update && apt-get install -y \ bc \
bison \ bison \
ca-certificates \ ca-certificates \
cpio \
curl \ curl \
fakeroot \ fakeroot \
flex \ flex \
gnupg \
crossbuild-essential-arm64 \
crossbuild-essential-ppc64el \
gcc \
gcc-7-plugin-dev \
git \ git \
kernel-package \ gmp-dev \
libelf-dev \ libressl-dev \
make \ mpc1-dev \
libncurses5-dev \ mpfr-dev \
libssl-dev \ ncurses-dev \
--no-install-recommends \ tar
&& rm -rf /var/lib/apt/lists/*
ENV HOME /root ENV HOME /root
WORKDIR $HOME WORKDIR $HOME
@ -31,4 +24,4 @@ ENV JOBS 4
COPY build_kernel /usr/local/bin/build_kernel COPY build_kernel /usr/local/bin/build_kernel
CMD [ "bash" ] ENTRYPOINT [ "bash" ]

View File

@ -3,98 +3,135 @@ set -e
set -o pipefail set -o pipefail
linux_next(){ linux_next(){
( local dir="/usr/src/linux-next"
cd /usr/src
# check if we already have the source checked out # Check if we already have the source for linux-next checked out.
if [[ -d linux ]]; then if [[ -d "$dir" ]]; then
cd linux echo "Updating linux-next tree git remotes..."
(
cd "$dir"
git checkout master git checkout master
git remote update git remote update
)
else else
# clone the source files echo "Cloning the git source for linux..."
git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git "$dir"
echo "Adding the linux-next git remote..."
(
cd "$dir"
# add the linux-next remote
cd linux
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
)
fi
echo "Fetching the linux-next remote and updating tags..."
(
cd "$dir"
# fetch linux-next and tags
git fetch linux-next git fetch linux-next
git fetch --tags linux-next git fetch --tags linux-next
fi )
git checkout -b next-$(date +%Y%m%d) next-$(date +%Y%m%d) local branch="next-$(date +%Y%m%d)"
echo "Checking out the correct branch ${branch}..."
(
cd "$dir"
if [[ ! -f .config ]] && [[ -f ../config ]]; then git checkout -b "$branch" "$branch"
cp ../config .config
fi
nice -19 make -j$JOBS KDEB_PKGVERSION=$PKGVERSION INSTALL_MOD_STRIP=1 deb-pkg
) )
} }
install_kernel(){ install_kernel(){
local VERSION=$1 local VERSION=$1
local OPT=$2 local OPT=$2
local DIR="/usr/src/linux-${VERSION}"
if [[ -z $VERSION ]]; then if [[ -z $VERSION ]]; then
echo "Please specify a kernel version." echo "Please specify a kernel version."
exit 1 exit 1
elif [[ "$VERSION" == "next" ]]; then elif [[ "$VERSION" == "next" ]]; then
DIR="/usr/src/linux-next"
linux_next linux_next
exit 0
fi fi
if [[ "$VERSION" != "next" ]]; then
local MAJOR_VERSION=${VERSION:0:1} local MAJOR_VERSION=${VERSION:0:1}
local V=( ${VERSION//./ } ) local V=( ${VERSION//./ } )
local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}" local MAJOR_MINOR_VERSION="${V[0]}.${V[1]}"
# get the kernel source # Get the kernel source.
echo "Getting the kernel source for linux-${VERSION}..."
echo "This might take a bit to download. Hang tight!"
if [[ "$VERSION" == *-rc* ]]; then if [[ "$VERSION" == *-rc* ]]; then
[ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://git.kernel.org/torvalds/t/linux-${VERSION}.tar.gz" | tar -v -C /usr/src -xz [ -d "$DIR" ] || curl -sSL "https://git.kernel.org/torvalds/t/linux-${VERSION}.tar.gz" | tar -C /usr/src -xz
MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN" MAJOR_MINOR_VERSION="${MAJOR_VERSION}.x-rcN"
else else
[ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${VERSION}.tar.xz" | tar -v -C /usr/src -xJ [ -d /usr/src/linux-${VERSION} ] || curl -sSL "https://cdn.kernel.org/pub/linux/kernel/v${MAJOR_VERSION}.x/linux-${VERSION}.tar.xz" | tar -C /usr/src -xJ
fi fi
# Git clone and apply the patches for the aufs filesystem.
if [[ "$OPT" == "aufs" ]]; then if [[ "$OPT" == "aufs" ]]; then
# get the aufs standalone source aufsdir=/aufs4-standalone
aufsdir=/tmp/aufs4-standalone
if [[ -d $aufsdir ]]; then echo "Cloning the git patches for the aufs filesystem..."
rm -rf $aufsdir
fi
git clone --depth 1 --branch aufs${MAJOR_MINOR_VERSION} --single-branch https://github.com/sfjro/aufs4-standalone.git $aufsdir git clone --depth 1 --branch aufs${MAJOR_MINOR_VERSION} --single-branch https://github.com/sfjro/aufs4-standalone.git $aufsdir
fi
# apply the patches and compile the kernel (
cd /usr/src/linux-${VERSION} cd "$DIR"
# apply the patches echo "Applying patch for the aufs filesystem..."
if [[ "$OPT" == "aufs" ]]; then
git apply $aufsdir/aufs4-kbuild.patch git apply $aufsdir/aufs4-kbuild.patch
git apply $aufsdir/aufs4-base.patch git apply $aufsdir/aufs4-base.patch
git apply $aufsdir/aufs4-mmap.patch git apply $aufsdir/aufs4-mmap.patch
cp -r $aufsdir/{Documentation,fs} . cp -r $aufsdir/{Documentation,fs} .
cp $aufsdir/include/uapi/linux/aufs_type.h include/uapi/linux/ cp $aufsdir/include/uapi/linux/aufs_type.h include/uapi/linux/
)
fi
fi fi
if [[ "$OPT" == "aufs" ]]; then
# remove aufs source # Install Wireguard VPN into the kernel.
rm -rf $aufsdir if [[ ! -f "${DIR}/net/wireguard/allowedips.c" ]]; then
echo "Applying patch for Wireguard VPN..."
(
cd "$DIR"
/wireguard/contrib/kernel-tree/create-patch.sh | patch -p1
)
echo "Patch for Wireguard VPN successfully applied!"
else
echo "Patch for Wireguard VPN has already been applied!"
fi fi
if [[ ! -f .config ]] && [[ -f ../config ]]; then # Copy the config from /usr/src/config if it does not already exist.
if [[ ! -f "${DIR}/.config" ]] && [[ -f "/usr/src/config" ]]; then
(
cd "$DIR"
cp ../config .config cp ../config .config
# Add the config options for the aufs filesystem.
if [[ "$OPT" == "aufs" ]]; then if [[ "$OPT" == "aufs" ]]; then
echo "CONFIG_AUFS_FS=y" >> .config echo "CONFIG_AUFS_FS=y" >> .config
fi fi
# Add the config options for Wireguard VPN.
echo "CONFIG_WIREGUARD=y" >> .config
)
fi fi
nice -19 make -j$JOBS KDEB_PKGVERSION=$PKGVERSION DISABLE_PAX_PLUGINS=y INSTALL_MOD_STRIP=1 deb-pkg (
cd "$DIR"
echo "Building the kernel..."
make -j$JOBS
echo "Installing the modules..."
make modules_install
echo "Installing the kernel..."
make install
)
} }
install_kernel $@ install_kernel $@