Skip to content

Commit

Permalink
add support for WSL2 kernels (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Schrock authored and Derek Smart committed Oct 16, 2019
1 parent 7d26656 commit 87ebe66
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ RUN apt-get install -y \
# Linuxkit binaries (such as fixdep) require musl
RUN apt-get install -y musl

# Linuxkit requires the ability to copy data from docker images
# Tar can fail sometimes on overlayfs, use bsdtar as a workaround
RUN apt-get install -y bsdtar

# Add required tools for those distros that require building the kernel from source
RUN apt-get install -y build-essential libncurses-dev bison flex libssl-dev \
libelf-dev

# Some distros require the ability to copy data from docker images
RUN apt-get -y install apt-transport-https \
ca-certificates \
curl \
Expand Down
3 changes: 3 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function get_kernel_type() {
linuxkit)
echo linuxkit
;;
microsoft-standard)
echo wsl
;;
*)
case $KERNEL_UNAME in
*Ubuntu*)
Expand Down
4 changes: 2 additions & 2 deletions src/vanilla.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function get_kernel_src() {
if [ ! -d /src/linux ]; then
curl --retry 5 -o /src/linux-$version.tar.xz -L https://www.kernel.org/pub/linux/kernel/v${version%%.*}.x/linux-$version.tar.xz
cd /src
tar xf linux-$version.tar.xz
mv $linux-version linux
bsdtar xf linux-$version.tar.xz
mv linux-$version linux
rm linux-$version.tar.xz
fi

Expand Down
62 changes: 62 additions & 0 deletions src/wsl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#
# Copyright The Titan Project Contributors.
#

#
# Build process for the WSL2 (Windows Service for Linux 2) kernel. The kernel is
# available at:
#
# https://github.com/microsoft/WSL2-Linux-Kernel
#
# However, there do not appear to be any pre-built binary packages, so we need
# to fetch the kernel source and build it ourselves. Like the vanilla kernel
# build process, we need a config.gz file to make sure we're building with the
# appropriate kernel parameters.
#

# Get vanilla kernel source
function get_kernel_src() {
local version=$KERNEL_VERSION

# Download Kernel source
if [ ! -d /src/linux ]; then
curl --retry 5 -o /src/$KERNEL_RELEASE.tar.gz -L https://github.com/microsoft/WSL2-Linux-Kernel/archive/$KERNEL_RELEASE.tar.gz
cd /src
bsdtar xf $KERNEL_RELEASE.tar.gz
mv WSL2-Linux-Kernel-$KERNEL_RELEASE linux
rm $KERNEL_RELEASE.tar.gz
fi

KERNEL_SRC=/src/linux
KERNEL_OBJ=/src/linux
}

#
# Build the kernel from source. We need to do a full build because in order to build the ZFS
# kernel modules, we not only depend on specific artifacts created in that process
# (such as utsrelease.h), but we have to link against objects and we don't have
# those objects available within the builder image.
#
function build_kernel() {
# Set kernel configuration
if [ ! -f /src/linux/.config ]; then
if [ -f /config/config.gz ]; then
zcat /config/config.gz > /src/linux/.config
else
zcat /proc/config.gz > /src/linux/.config
fi
fi

cd /src/linux && make -j8
}

# Vanilla entry point
function build() {
get_zfs_source
if [ "$ZFS_CONFIG" != "user" ]; then
get_kernel_src
build_kernel
fi
build_zfs
}

0 comments on commit 87ebe66

Please sign in to comment.