9

The "Windows Server Installation Guide" links to "Manually download Windows Subsystem for Linux distro packages", which mentions several distributions that are officially provided: Debian, Kali, Ubuntu, OpenSUSE, Fedora, and SLES

Since we have Debian and Slackware based distros at hand:

  • Is it possible to use any distributions/tree other than those, such as Arch?
  • Are there any downsides to not using the official distributions?

I am particularly interested in a way that avoids using the Windows Store, as it can be blocked by Group Policies.

1

1 Answer 1

12

This is tested in Windows 10 v1709 and the procedure may change in future Windows 10 builds

  1. Compile Installer:
    We have to compile an executable to call the WslRegisterDistribution() function:
    (not expected for this documented function to change)
    #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);
    }
    
    Compile this with any C compiler (e.g. gcc), letting the executable name Wslnstall.exe (needed for step #3), and I have a compiled version of this in my GitHub repository

  2. 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.) and from my personal experience, there are some conditions that to be present in that .tar.gz file, such as the .tar.gz file should be compressed with gzip only, contain a valid /bin/bash or /bin/sh binary, and /etc/passwd file (as usual).
    • These are just guidelines users may skip, and here I omit these steps with a direct link to a pre-built .tar.gz for Alpine (only download the .tar.gz)

  3. Install:
    Place the compiled executable (step #1) and .tar.gz (step #2) within the same folder you want to install, running from within that folder:
    # WslInstall.exe <distro_name> <file_name.tar.gz>
      WslInstall.exe Alpine alpine-minirootfs-xxx.tar.gz
    

The Alpine distribution should now be installed.

3
  • 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, 2018 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, 2018 at 15:20
  • 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, 2018 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .