其他名称 | Windows Subsystem for Linux |
---|---|
开发者 | 微软 |
取代 | Windows Services for UNIX |
适用于Linux的Windows子系统(英语:Windows Subsystem for Linux,简称WSL)是一个为在Windows 10和Windows Server 2019上能够原生运行Linux二进制可执行文件(ELF格式)的兼容层。
概览
WSL提供了一个由微软开发的Linux兼容的内核接口(不包含Linux内核代码)[1],然后可以在其上运行GNU用户空间,例如Ubuntu,[2][3][4][5]openSUSE,[6]SUSE Linux Enterprise Server,[7][8][9]Debian[10]和Kali Linux。[11]这样的用户空间可能包含Bash shell和命令语言,使用本机GNU/Linux命令行工具(sed,awk等),编程语言解释器(Ruby,Python等),甚至是图形应用程序(使用主机端的X窗口系统)。[12]
简介和可用性
在周年更新中引入时,只有Ubuntu镜像可用。秋季创意者更新将Linux发行版的安装过程移至Microsoft商店,并引入了Fedora和SUSE镜像。[9]
WSL仅在版本1607之后的64位版本的Windows 10中可用。它也可在Windows Server 2019中使用。
发展
微软首次尝试在Windows上实现类似Unix的兼容性,首先是微软POSIX子系统,由Windows Services for UNIX通过MKS/Interix取代,后者最终因Windows 8.1的发布而被弃用。Windows Subsystem for Linux背后的技术起源于未发布的Astoria项目,它使一些Android应用程序能够在Windows 10 移动版上运行。[13]它首先在Windows 10 Insider Preview build 14316中提供。[14]
虽然微软以前的项目和第三方Cygwin专注于基于POSIX标准创建自己独特的类Unix环境,但WSL的目标是原生Linux兼容性。WSL不是将非原生功能包装到Win32系统调用中,而是利用NT内核执行程序将Linux程序作为特殊的、隔离的最小进程(称为“pico-processes”)作为专用系统连接到内核模式“pico-providers”。调用和异常处理程序不同于vanilla NT进程。[15]
微软将WSL视为“主要面向开发人员的工具 — 尤其是Web开发人员以及在开源项目上工作或使用开源项目的人员”。[12]WSL使用的资源少于完全虚拟化的机器,这是在Windows环境中运行Linux软件的最直接方式,同时还允许用户在同一组文件上使用Windows应用程序和Linux工具。[12]
2020年9月,WSL 2开始向Windows 10 Version 1903/1909和Windows 10 May 2020(20H1/Version 2004)的用户推送。WSL 2支持GUI应用[16]。
体系结构
LXSS Manager Service是负责与子系统交互的服务(通过驱动程序lxss.sys
和lxcore.sys
),以及Bash.exe(不要与Linux发行版提供的Shell混淆)的方式启动Linux进程,以及在执行期间处理Linux系统调用和二进制锁。[17]
特定用户调用的所有Linux进程都进入“Linux实例”(通常,第一个调用的进程是init)。关闭所有应用程序后,将关闭实例。
硬件和文件系统访问
由于没有硬件仿真/虚拟化(与coLinux等其他项目不同),WSL直接使用主机文件系统(通过VolFS
和DrvFS
)[18]和硬件的某些部分,例如网络(Web服务器,用于例如,可以通过主机上配置的相同接口和IP地址进行访问,并且对使用需要管理权限的端口或已经被其他应用程序占用的端口共享相同的限制),这保证了互操作性。[19]
即使从shell运行sudo,某些位置(例如系统文件夹)和配置的访问/修改也受到限制。必须启动具有提升权限的实例才能获得“真正的sudo”并允许此类访问。[12]
局限性
此子系统无法运行所有Linux软件(如32位二进制文件)[20][21]或需要在WSL中未实现的特定Linux内核服务的软件。由于WSL中没有“真正的”Linux内核,因此无法运行内核模块(如设备驱动程序)。
可以通过在Windows(主机)环境(例如VcXsrv或Xming)[22]中安装X窗口系统来运行一些图形(GUI)应用程序(例如Mozilla Firefox),但是这种模式还存在一定的问题,例如缺乏音频支持或硬件加速(导致图形性能不佳)。尽管已经在计划中,但是目前还没有实现对OpenCL和CUDA的支持。[23][24]
也就是说,微软明确指出WSL面向应用程序的开发者,而不是面向桌面环境或生产服务器。微软建议使用虚拟机(Hyper-V或Kubernetes)和Azure来实现这些目的。[12]
性能
在性能测试中,Windows Subsystem for Linux通常接近原生Linux(如Ubuntu、Debian、Intel Clear Linux或其他Linux发行版)。在某些测试中I/O是WSL的瓶颈。[25] [26]
截图
参见
参考资料
- ↑ Gerwitz, Mike. GNU/kWindows. mikegerwitz.com. [2018-04-08].
- ↑ Harsh, Mike. Run Bash on Ubuntu on Windows. Building Apps for Windows. Microsoft. 30 March 2016.
- ↑ Finley, Klint. Why Microsoft Making Linux Apps Run on Windows Isn't Crazy. Wired. Condé Nast. 30 March 2016.
- ↑ Kirkland, Dustin. Ubuntu on Windows – The Ubuntu Userspace for Windows Developers. Ubuntu Insights. Canonical. 30 March 2016.
- ↑ Hammons, Jack. Bash on Ubuntu on Windows. MSDN. Microsoft. 9 April 2016.
- ↑ Get openSUSE Leap 42 - Microsoft Store
- ↑ Get SUSE Linux Enterprise Server 12 - Microsoft Store
- ↑ Yegulalp, Serdar. Windows Subsystem for Linux welcomes Suse and Fedora options. InfoWorld. 2017-05-12 [2017-09-16].
- ↑ 9.0 9.1 Ubuntu now available from the Windows Store!. Windows Command Line Tools For Developers Blog. July 10, 2017 [2017-08-11].
- ↑ Debian GNU/Linux for WSL now available in the Windows Store. Windows Command Line Tools For Developers. [2018-03-07] (美国英语).
- ↑ Kali Linux in the Windows App Store. [2018-03-09] (美国英语).
- ↑ 12.0 12.1 12.2 12.3 12.4 Frequently Asked Questions for WSL. Microsoft. [2016-11-13].
- ↑ Bright, Peter. Why Microsoft needed to make Windows run Linux software. Ars Technica. Condé Nast. 6 April 2016.
- ↑ Aul, Gabe. Announcing Windows 10 Insider Preview Build 14316. Windows Experience Blog. Microsoft. 6 April 2016.
- ↑ Windows Subsystem for Linux Overview. Windows Subsystem for Linux. [2018-04-22] (美国英语).
- ↑ [图]WSL 2迎来重大改进:支持GUI应用 向Windows 10 v1903/1909开放.
- ↑ Jack Hammons. Windows Subsystem for Linux Overview. Windows Subsystem for Linux blog on MSDN. April 22, 2016.
- ↑ Jack Hammons. WSL File System Support. Windows Subsystem for Linux blog on MSDN. June 15, 2016.
- ↑ Jack Hammons. WSL Networking. Windows Subsystem for Linux blog on MSDN. November 8, 2016.
- ↑ Please enable WSL to run 32 bit ELF binaries. Windows Developer feedback (Microsoft/UserVoice). [2018-12-20].
- ↑ Support for 32-bit i386 ELF binaries. GitHub.
- ↑ Windows 10's Bash shell can run graphical Linux applications with this trick. PC World. [September 10, 2018].
- ↑ GPU not accesssible for running tensorflow and installing CUDA · Issue #1788 · Microsoft/WSL. GitHub. [September 10, 2018].
- ↑ OpenCL & CUDA GPU support. Windows Developer feedback (Microsoft/UserVoice). September 15, 2016 [September 10, 2018].
- ↑ Windows Subsystem for Linux. Phoronix.
- ↑ Michael Larabel. A Look At The Windows 10 October 2018 Update Performance With WSL. Phoronix. October 12, 2018.
外部链接
- 官方博客
- 微软文档上的WSL页面
- GitHub上的WSL页面
- Windows Command Line Tools For Developers blog
- Brown, Pete. Fun with the Windows Subsystem for Linux. Windows Developer Blog. Microsoft. 22 July 2016 [2018-12-20].