This is a several-part problem, you see.
To start, this is what a WSL 2 kernel release string (what you see from uname -r
) looks like:
5.10.16.3-microsoft-standard-WSL2
If you take a look at the configuration file supplied with the WSL Linux kernel (available here), you’ll see that this is set right there in line 22:
CONFIG_LOCALVERSION=”-microsoft-standard-WSL2”
So what? I hear you cry.
So nothing, in itself. The trouble comes when you try to make packages for that kernel - because, you see, to be recognized as a WSL kernel by things that care about detecting WSL, you need that “WSL2” string to be in there, and to be capitalized. Consider, for example, this code from systemd and systemd-detect-virt, which as you can see, looks explicitly for the letters WSL in capitals1. As the systemd code mentions, this is the perhaps-not-official-but-at-least-unofficial technique recommended over here for detecting WSL.
Now here’s the thing. This is all fine if you are building a one-off kernel, but if you want a nice packaged kernel, with headers, and modules, and maybe even to install it on multiple WSL instances, you’re going to want something a mite more convenient than what you can get from make xconfig ; make ; make install ; make modules_install. Such as, for example, running a quick make deb-pkg to get the three .deb packages (kernel image and modules, headers, and libc) you need to install your shiny new custom kernel in such a way that the is are dotted, the ts are crossed, the DKMS rebuild process is triggered, and package management knows what’s going on.
So you try it. And it doesn’t work:
dpkg-source: error: source package name 'linux-5.10.16.3-20210504-1-microsoft-custom-WSL2+' is illegal: character 'W' not allowed
dpkg-buildpackage: error: dpkg-source -i.git --before-build . subprocess returned exit status 255
make[1]: *** [scripts/Makefile.package:77: deb-pkg] Error 255
make: *** [Makefile:1529: deb-pkg] Error 2
…because as you hadn’t considered, upper case is illegal in apt package names, and since the package name is derived from the kernel version string, you can’t have any capitals in it.
So you can have your packaged custom kernel, but anything that depends on recognizing WSL won’t recognize it.
What to do?
Well, first, bitch about it to Microsoft, as one does. See WSL issue number #6911.
But when you get done with that and realize that it won’t give you an immediate solution to the problem, consult your friendly local kernel developer, and then start hacking on the build scripts until they can be made to compile a package with a different - by virtue of being lower case - name than the kernel release name.
Fortunately for you, you don’t have to do that.
You can just grab the patch I made, here:
From 33890150b1898474d16d141fba7865068d1e2f7b Mon Sep 17 00:00:00 2001 | |
From: Alistair Young <avatar@arkane-systems.net> | |
Date: Thu, 6 May 2021 19:41:36 -0500 | |
Subject: [PATCH] Case hack for Debian build. | |
--- | |
scripts/Makefile.package | 6 ++++-- | |
scripts/package/builddeb | 7 ++++--- | |
scripts/package/mkdebian | 8 +++++--- | |
3 files changed, 13 insertions(+), 8 deletions(-) | |
diff --git a/scripts/Makefile.package b/scripts/Makefile.package | |
index f952fb64789d..201e6635597e 100644 | |
--- a/scripts/Makefile.package | |
+++ b/scripts/Makefile.package | |
@@ -24,8 +24,10 @@ include $(srctree)/scripts/Kbuild.include | |
# but the binrpm-pkg target can; for some reason O= gets ignored. | |
# Remove hyphens since they have special meaning in RPM filenames | |
-KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) | |
-KDEB_SOURCENAME ?= linux-$(KERNELRELEASE) | |
+KERNELRELEASELC = $(shell echo $(KERNELRELEASE) | tr '[:upper:]' '[:lower:]') | |
+ | |
+KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASELC)) | |
+KDEB_SOURCENAME ?= linux-$(KERNELRELEASELC) | |
KBUILD_PKG_ROOTCMD ?="fakeroot -u" | |
export KDEB_SOURCENAME | |
# Include only those top-level files that are needed by make, plus the GPL copy | |
diff --git a/scripts/package/builddeb b/scripts/package/builddeb | |
index 91a502bb97e8..9d7fc917d19c 100755 | |
--- a/scripts/package/builddeb | |
+++ b/scripts/package/builddeb | |
@@ -107,13 +107,14 @@ deploy_libc_headers () { | |
} | |
version=$KERNELRELEASE | |
+pkgversion=$(echo $KERNELRELEASE | tr '[:upper:]' '[:lower:]') | |
tmpdir=debian/linux-image | |
dbg_dir=debian/linux-image-dbg | |
-packagename=linux-image-$version | |
+packagename=linux-image-$pkgversion | |
dbg_packagename=$packagename-dbg | |
if [ "$ARCH" = "um" ] ; then | |
- packagename=user-mode-linux-$version | |
+ packagename=user-mode-linux-$pkgversion | |
fi | |
# Not all arches have the same installed path in debian | |
@@ -211,7 +212,7 @@ done | |
if [ "$ARCH" != "um" ]; then | |
if is_enabled CONFIG_MODULES; then | |
deploy_kernel_headers debian/linux-headers | |
- create_package linux-headers-$version debian/linux-headers | |
+ create_package linux-headers-$pkgversion debian/linux-headers | |
fi | |
deploy_libc_headers debian/linux-libc-dev | |
diff --git a/scripts/package/mkdebian b/scripts/package/mkdebian | |
index 60a2a63a5e90..985a72e90a13 100755 | |
--- a/scripts/package/mkdebian | |
+++ b/scripts/package/mkdebian | |
@@ -85,7 +85,9 @@ set_debarch() { | |
} | |
# Some variables and settings used throughout the script | |
-version=$KERNELRELEASE | |
+version=$(echo $KERNELRELEASE | tr '[:upper:]' '[:lower:]') | |
+mkversion=$KERNELRELEASE | |
+ | |
if [ -n "$KDEB_PKGVERSION" ]; then | |
packageversion=$KDEB_PKGVERSION | |
revision=${packageversion##*-} | |
@@ -225,14 +227,14 @@ srctree ?= . | |
build-indep: | |
build-arch: | |
- \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \ | |
+ \$(MAKE) KERNELRELEASE=${mkversion} ARCH=${ARCH} \ | |
KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile | |
build: build-arch | |
binary-indep: | |
binary-arch: build-arch | |
- \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \ | |
+ \$(MAKE) KERNELRELEASE=${mkversion} ARCH=${ARCH} \ | |
KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile intdeb-pkg | |
clean: | |
-- | |
2.31.1 | |
Or, alternatively a capitalized “Microsoft”, but since the problem is with all capital letters, that doesn’t help you much.