6

In "Install the Linux Subsystem on Windows Server", Microsoft mentions three distributions that are officially provided: Debian, Kali, Ubuntu, OpenSUSE, and SLES.

Since we have Debian-based and Slackware-based distros at hand, I am wondering: Is it possible to use any other distributions from those - or other - distribution trees (such as Fedora, Arch), and are there any downsides to not using the "official" distributions? I am particularly interested in a way that avoids using Windows Store, such as that explained in the above link, as Windows Store could be blocked by Group Policies.

9

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.

  1. 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.

  1. 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.

  1. 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.

  • You could also P/Invoke that via PowerShell/C#. Would avoid the need for a separate executable, if that's desired or the environment makes it impractical. – Bob Apr 14 '18 at 15:17
  • @Bob I know that with C#. But using C one has many option like VS, cygwin, mingw etc. If you know that with Powershell the I've a question in SO, can you answer this question stackoverflow.com/q/47250994/8928481 and reply your answer in this link. – Biswapriyo Apr 14 '18 at 15:20
  • @Biswapriyo as I've already proven my incompetence my word has not that much value here, though I'd think that PowerShell is sufficient, as WSL is a Win10-thing, anyways, and PoSh is included in Win10. – flolilo Apr 14 '18 at 16:22
  • I'll have a look at it tomorrow (if I remember) - no particular reason it shouldn't work, so it's odd that it didn't seem to work for you. But I don't have WSL on this particular machine so it'll have to wait a bit. – Bob Apr 14 '18 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.