Disclaimer: The following procedure is tested in Windows 10 Version 1709 (Fall Creators Update). The procedure may change in future Windows 10 builds. Warning, programming language ahead.
- Compile Installer: We've to compile an executable to call the
WslRegisterDistribution()
function. This documented function may not change (as expected). Here is the code:
#include <Windows.h>
#include <stdio.h>
typedef HRESULT (WINAPI* RegisterDistro)(PCWSTR distroName, PCWSTR tarGzFilename);
int main() {
int wargc;
wchar_t** wargv;
wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
HMODULE dll = LoadLibraryExW(L"wslapi.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
RegisterDistro func = (RegisterDistro)GetProcAddress(dll, "WslRegisterDistribution");
HRESULT result = func(wargv[1], wargv[2]);
(result == S_OK) ? printf("%ls installed\n", wargv[1]) : printf("Error: 0x%x\n", result);
}
Now, compile that code with any C compiler (e.g. gcc). Let the executable name Wslnstall.exe (need for step #3). I've got a compiled version of this at my GitHub repository here WslInstall.
- Download .tar.gz RootFS: There are many ways to get the RootFS of a distro e.g. from ISO file, from docker image, using
debootstrap
command etc. From my personal experience, there are some conditions that to be present in that .tar.gz
file. The .tar.gz file should be compressed with gzip only and should contain a valid /bin/bash
or /bin/sh
binary and /etc/passwd
file (as usual).
These are just guidelines users may skip it. Here I omit those steps and put a direct link to download a pre-build .tar.gz
file. e.g. For Alpine, go to this link: http://dl-4.alpinelinux.org/alpine/v3.7/releases/x86_64/ and download only the tar.gz
file.
Install: Put the compiled executable (step #1) and the .tar.gz file (step #2) in same folder where you want to install. Run this command in that folder: WslInstall.exe <distro_name> <file_name.tar.gz>
. For example the command will be:
WslInstall.exe Alpine alpine-minirootfs-xxx.tar.gz
.
The Alpine distribution should be installed.
Comments are not for extended discussion; this conversation has been moved to chat.
– Journeyman Geek – 2018-04-14T15:24:33.650