WSL“分发”涉及什么?

Ben*_*arp 10 windows distribution-choice windows-subsystem-for-linux

WSL 允许用户使用他们选择的任何发行版,并且默认安装 Ubuntu。

我不太明白 WSL 上下文中分布的相关性。我的理解是Linux发行版是指操作系统的皮肤。操作系统核心之上的 UI 层。但是,当使用 WSL 时,您只需使用命令行,或者运行一个独立的单一 GUI 应用程序。那么,在这种情况下,分布的相关性是什么?它对您选择的分布有何影响?

Not*_*1ds 20

这里的其他一些答案集中在“Linux 发行版”的“正常”含义上,这对于理解您的问题的背景当然很有用。但您是在 WSL 的背景下专门询问这个问题的。

您选择哪种发行版有什么区别?

在我们讨论有关 WSL 发行版的“差异”之前,让我先回答您问题的这一部分。Linux 发行版的主要区别是(这里主要关注 WSL/开发人员需求):

  • 默认存储库中可用的应用程序版本。您通常会发现(过度概括)两种类型的分布:

    • "Stable" distributions, which tend to update very infrequently (other than security updates) but focus on making sure (to the best of their ability) that all packages work together well and don't break the system. Ubuntu, Debian, and Red Hat are good examples of these.

      Ubuntu, for example, has one release every 6 months. But only every two years (in April of even numbered years) is it updated with a long-term support (LTS) version (e.g. 22.04 LTS), which is supported for 5 years.

    • "Rolling-release" distributions, which focus on getting new releases of software into their repositories as soon as they are considered stable and tested. Arch and Kali are common examples of these.

    openSUSE, as another example, has distribution releases for each model, and both are available as Microsoft Store installs for WSL. If you search the Store for openSUSE, you'll find both "Leap" releases (stable) and "Tumbleweed" (rolling).

    Whether you choose a Stable or Rolling release is really up to you. I keep both around, personally. There's no reason at all on WSL to limit yourself to just one distribution (other than disk space). I've used Tumbleweed as my rolling release for a while, with the latest LTS of Ubuntu as my stable. However, I've been impressed with Artix as a rolling release (based on Arch) and am probably going to be trying it as my daily-rolling-driver for a while.

    Also note that, as a developer (from the fact that you posted this first on Stack Overflow, as well as your profile there), it may not matter quite as much for you based on the languages and tools you use. You appear to do a lot of Node-based/React/web/framework development from your SO tags. Under WSL (or any Linux distribution), you're unlikely to use the pre-packaged, repository version of Node.js anyway. You're going to install via nvm or n. Then, of course, you'll install packages/modules via npm, yarn (or other).

    And even for languages which are critical to the system and shouldn't be changed (e.g. it's a bad idea to change the Python version in a Linux distribution), you can use Docker or other virtualization/container technologies to use different language versions on WSL, regardless of the distribution. (More reading on that topic - See my recent answer regarding Docker Python on the Ask Ubuntu question How do I install a different Python version using apt-get?).

    So, as a developer, if you don't have any non-developer reasons to go with a rolling release, a stable-style distribution might make your life easier in the long run.

  • Availability of documentation and support is another good reason to choose a distribution. It's on this basis that I simply have to recommend Ubuntu to most new WSL users (and it is, as you mention, now the default WSL distribution). Most blogs, videos, or other instructional documentation that you find are going to focus on how to do things in Ubuntu. This may be shifting somewhat to Arch, but for now I think the advantage in this camp still goes to Ubuntu.

    That's not to say that you can blindly follow any Ubuntu (or any distribution) documentation and have it work on WSL. There are a number of differences in WSL that mean you often need to tweak the instructions somewhat. Some of those differences are covered below, but I try to maintain a more complete list in this Ask Ubuntu answer.

    On the flip side, note that Kali is an advanced distribution, even when not in WSL. See the excellent meta post here, If you need to ask, then Kali Linux is not the right distribution for you.

So what is the relevance of distribution in this [the WSL] context

In WSL, the word "Distribution" is actually a bit overloaded, with several meanings, as well as some important differences from the "normal" definition of Linux distribution:

  • First, a WSL distribution, at its core, is simply a packaged root filesystem. It can include something as simple as a single statically linked executable (like BusyBox) or a complex ecosystem of packages, scripts, and package management (like Ubuntu or Arch).

    That package can be a:

    • tar or tar.gz
    • A Hyper-V virtual disk image (vhd or vhdx) in the latest WSL Preview releases.

    But really, as long as you can package your files in one of those two forms, you can, at least wsl --import the package into a WSL distribution. There are some convenient (and presumably tested) distributions available to install from the Microsoft Store into WSL, but they ultimately package an install.tar.gz which then gets installed into WSL.

    WSL's packaging has the added advantage that it is really easy to convert any software for which there is a Docker image to a WSL "distribution". Just docker pull ..., docker run ..., and docker export ... to create a tarball. Want a Red Hat image that isn't in the Microsoft Store, just grab the appropriate Docker image. BusyBox? Same. Etc.

    To be a "bootable" distribution, however, you do need a minimum of:

    • An /etc/passwd with one or more users.
    • The shell defined for the primary user, which becomes the default entry point.
    • If the user is not root, then you either need a /etc/wsl.conf defining the default user (see here) or a registry entry.
  • A "normal" Linux distribution also typically provides a default:

    • Init system
    • Kernel with drivers
    • Bootloader (typically GRUB2)
    • X and/or Wayland server

    None of that is needed or utilized in WSL. WSL provides its own kernel. While (in WSL2 at least) you can build your own (from standard kernel sources) and replace it, a single kernel is shared among all distributions that you have installed on your Windows/WSL system. In WSL1, this is a pseudo-kernel that does syscall translations from Linux to Windows. In WSL2, it is a real Linux kernel running in a managed (as in, you can't typically see it, access it, or change it) Hyper-V virtual machine.

    WSL also provides its own init system, which handles the interoperability between WSL/Linux and the Windows layer (such as networking, the ability to execute Windows binaries through binfmt_misc, WSLg boot, and more).

    This can be problematic, since WSL does not run the standard init for most Linux distributions. For instance, even though Ubuntu/Debian/Arch (pretty much everyone other than some niche distros) runs Systemd, WSL does not enable it, even when running one of those "distributions". See my explanations here and here.

    And while Systemd is, of course, the dominant init system, it is more problematic than most other init systems under WSL since both WSL's init and Systemd vie to be PID1. Systemd will flat out refuse to run as anything but PID1 (and WSL2 won't let it, without using namespaces as a workaround). Some other inits / process managers can run as non-PID1, so are more (IMHO) suitable for use under WSL. I've had good success with Artix and Dinit, for instance. And as a plain-vanilla process manager, Supervisord works reasonably well under most any distribution.

  • A WSL "Distribution" can also mean the "instance" or "container" that is created from the imported package. Running wsl -l -v will list the installed distributions on your system.

    When you run one of these, at least under WSL2, what is running is essentially a container (isolated namespace) for the package you imported.

  • A Linux distribution also often comes with a default Desktop environment (e.g. Gnome, KDE Plasma, Xfce, others) as well as (as you mention) theming. While it's possible to run a desktop environment from your a distro in WSL, it's not a standard process. In Windows 11, WSL can run Linux GUI applications through the use of the WSLg feature, but that's for running individual Linux applications integrated into the Windows desktop.

    可以运行 Linux 桌面环境(通过第三方 X 服务器、WSLg 全屏 Weston/Xwayland 或 XRDP),但是(除了 XRDP)您需要确保Alt+之类的键绑定Tab是进行更改,以便它们不会被 Windows 内置功能拦截。


dr_*_*dr_ 19

我的理解是Linux发行版是指操作系统的皮肤。操作系统核心之上的 UI 层。

这是不正确的。Linux 发行版在许多基本方面都存在差异,这些差异超出了 GUI 的外观和感觉:

  • 内核版本,以及各种自定义(想要最新的内核和尖端软件?使用 Fedora。想要稳定性?使用 RHEL。)
  • 支持不同的硬件设备
  • 包管理器(RHEL 有rpmyum、 和dnf;Debian 有dpkgapt;ArchLinux 有pacman;等等)
  • 软件包和工具(例如,Debian 在其主要存储库中仅包含免费和开源软件)
  • 存储库,具有不同的更新和错误修复时间表

但是,如果您的主要用途只是编写一些 Bash 脚本,那么无论使用哪种发行版,您的体验都会或多或少相同。

  • “如果你的主要用途只是编写一些 bash 脚本,那么你的体验或多或少会是相同的”——这假设了一个相对主流的发行版,而不是像 NixOS 这样的发行版(其中 `/usr/bin` 除了`env` 和 `/bin` 除了 `sh` 之外没有其他文件)或 GUIX。 (5认同)

Whi*_*Owl 6

从广义上讲,分布的差异就是皮肤的差异。不同的图形界面只是它的一个特例。首先,任何两个分配函数之间有两个主要区别:

  1. 存储库中包含哪些内容以及不包含哪些内容;
  2. 基本工具的默认值是什么。

第一个示例可以是库或应用程序的版本。一旦开发人员制作了新版本 - 分发版的维护者应该下载它,编译并在存储库中发布。如果维护者(真实的人)预计应用程序的新版本中会出现很多错误 - 他可以跳过该版本。但另一个发行版的维护者将按原样发布它,并允许普通用户直接向开发人员抱怨错误。

对于第二个:在 Ubuntu 中,正在sudo检查组wheel中是否有允许使用sudo. 在 Fedora 中,该组名为sudosudo在将其作为基本工具之一放入存储库之前,这种差异已在编译过程中内置到工具中。

请不要忘记,终端也是一个 UI。只是不是图形化的。而且也可能存在差异。例如:在 Ubuntu 中,您用于apt从其存储库安装新应用程序,但在 Fedora 中您用于执行dnf相同的任务。这可以被视为不同的 UI 选择。他们具有相同的目的以及几乎相同的能力和局限性。只是不同的命令行键集,并且正在处理不同结构的包。

通过对操作系统结构的充分了解,可以忽略您安装的发行版并混合不同发行版的不同方法。您可以sudo自己重新编译并定义其特殊组,admins例如。或者您可以dnf在 Ubuntu(或aptFedora)上安装并从两个存储库下载应用程序,之后您可能需要调整下载的应用程序的一些设置,但这是可能的。当然,您始终可以下载一些应用程序/库作为源代码,然后自己编译它,并共享编译后的版本 - 这将成为您自己的发行版。

这适用于操作系统的正常设置和 WSL 操作系统。