适用于Linux的Windows子系统

在Windows上原生运行Linux二进制可执行文件的兼容层

适用于Linux的Windows子系统(英語:Windows Subsystem for Linux,简称WSL)是一个为在Windows 10Windows Server 2019以上能够原生运行Linux二进制可执行文件ELF格式)的兼容层

适用于Linux的Windows子系统
在Windows 10上运行的Bash
在Windows 10上运行的Bash
其他名称WSL
開發者微软
首次发布WSL 1: 2016年8月2日,​7年前​(2016-08-02
WSL 2: 2019年6月12日,​4年前​(2019-06-12[1]
当前版本
編輯維基數據鏈接
源代码库github.com/Microsoft/WSL(仅问题)
操作系统Windows 10, Windows Server 2019, Windows 11
取代Windows Services for UNIX
类型兼容层(WSL 1), 虚拟化(WSL 2)
许可协议子系统: 专有商业软件;
Linux内核: GNU GPLv2(仅), 具有在兼容GPL变体下或在宽松许可如BSD、MIT下的一些代码
网站docs.microsoft.com/windows/wsl

概览 编辑

WSL提供了一个由微软开发的Linux兼容的内核接口(不包含Linux内核代码)[4],然后可以在其上运行GNU用户空间,例如Ubuntu[5][6][7][8]openSUSE[9]SUSE Linux Enterprise Server[10][11][12]Debian[13]Kali Linux[14]这样的用户空间可能包含Bash shell和命令语言,使用本机GNU/Linux命令行工具(sedawk等),编程语言解释器(Ruby,Python等),甚至是图形应用程序(使用主机端的X窗口系统)。[15]

简介和可用性 编辑

在周年更新中引入时,只有Ubuntu镜像可用。秋季创意者更新将Linux发行版的安装过程移至Microsoft商店,并引入了FedoraSUSE镜像。[12]

WSL在版本1607之后的64位版本的Windows 10与Windows 11中可用。它也可在Windows Server 2019中使用。

发展 编辑

微软首次尝试在Windows上实现类似Unix的兼容性,首先是微软POSIX子系统,由Windows Services for UNIX通过MKS/Interix取代,后者最终因Windows 8.1的发布而被弃用。Windows Subsystem for Linux背后的技术起源于未发布的Astoria项目,它使一些Android应用程序能够在Windows 10 移动版上运行。[16]它首先在Windows 10 Insider Preview build 14316中提供。[17]

虽然微软以前的项目和第三方Cygwin专注于基于POSIX标准创建自己独特的类Unix环境,但WSL的目标是原生Linux兼容性。WSL不是将非原生功能包装到Win32系统调用中,而是利用NT内核执行程序将Linux程序作为特殊的、隔离的最小进程(称为“pico-processes”)作为专用系统连接到内核模式“pico-providers”。调用和异常处理程序不同于vanilla NT进程。[18]

微软将WSL视为“主要面向开发人员的工具 — 尤其是Web开发人员以及在开源项目上工作或使用开源项目的人员”。[15]WSL使用的资源少于完全虚拟化的机器,这是在Windows环境中运行Linux软件的最直接方式,同时还允许用户在同一组文件上使用Windows应用程序和Linux工具。[15]

2020年9月,WSL 2開始向Windows 10 Version 1903/1909和Windows 10 May 2020(20H1/Version 2004)的用戶推送。WSL 2支持GUI应用[19]

設計 编辑

WSL 1 编辑

LXSS Manager Service是负责与子系统交互的服务(通过驱动程序lxss.syslxcore.sys),以及Bash.exe(不要与Linux发行版提供的Shell混淆)的方式启动Linux进程,以及在执行期间处理Linux系统调用和二进制锁。[20]

特定用户调用的所有Linux进程都进入“Linux实例”(通常,第一个调用的进程是init)。关闭所有应用程序后,将关闭实例。

WSL 1的設計沒有硬體模擬/虛擬化(与coLinux等其他项目不同),WSL直接使用主机文件系统(通过VolFSDrvFS[21]和硬件的某些部分,例如网络(Web服务器,用于例如,可以通过主机上配置的相同接口和IP地址进行访问,并且对使用需要管理权限的端口或已经被其他应用程序占用的端口共享相同的限制),这保证了互操作性。[22]

即使从shell运行sudo,某些位置(例如系统文件夹)和配置的访问/修改也受到限制。必须启动具有提升权限的实例才能获得“真正的sudo”并允许此类访问。[15]

WSL 1 無法運行所有 Linux 軟體(如32位二进制文件)[23][24]或需要在WSL中未实现的特定Linux内核服务的软件。由于WSL中没有“真正的”Linux内核,因此无法运行内核模块(如设备驱动程序),但是,WSL 2 使用即時虛擬化的Linux內核實例。可以通过在Windows(主机)环境(例如VcXsrv或Xming[25]中安装X窗口系统来运行一些图形(GUI)应用程序(例如Mozilla Firefox),但是这种模式还存在一定的问题,例如缺乏音频支持或硬件加速(导致图形性能不佳)。尽管已经在计划中,但是目前还没有实现对OpenCLCUDA的支持。[26][27]

也就是说,微软明确指出WSL面向应用程序的开发者,而不是面向桌面环境或生产服务器。微软建议使用虚拟机Hyper-VKubernetes)和Azure来实现这些目的。[15]

在性能测试中,WSL 1通常接近原生Linux(如Ubuntu、Debian、Intel Clear Linux或其他Linux发行版)。在某些测试中I/O是WSL的瓶颈。[28] [29]

WSL 2 编辑

 
Synaptic package manager running on WSL

WSL 2 引入了體系結構中的更改。微軟選擇了通過高度優化的Hyper-V功能子集進行虛擬化,以便運行內核和發行版(基於內核),承諾性能相當於WSL 1,為了 向下相容,開發人員不需要更改其已發佈發行版中的任何內容。 WSL 2 設定可以通過 WSL 全域 設定配置進行調整,該配置位在使用者設定檔資料夾中名為.wslconfigINI檔案[30][31]

發行版本安裝在ext4格式的虛擬磁碟中,主機檔案系統可以通過9P 協定協議透明地訪問,[32] 類似於QEMU等其他虛擬機器技術。[33] 對於用戶,微軟承諾讀寫性能是WSL 1的20倍。[34] Windows提供一個IFS網路重新導向程式,使用UNC路徑首碼\\wsl$來訪問Linux客戶檔。

WSL 2 需要Windows 11,[35] 或Windows 10版本 2004 和更新版本(組建 19041 和更新版本)[36]

微軟聲稱重新設計的WSL 2後端在某些操作上的速度比WSL 1提高了20倍,[37]2020 年 6 月,使用 AMD Threadripper 3970x 進行了 173 次測試的基準測試顯示,WSL 2 (20H2) 性能良好,性能僅為本機 Ubuntu 20.04.0 LTS 的 87%。這是對WSL 1的改進,在此比較中,WSL 1的性能僅為本機Ubuntu的70%。[38],WSL 2改善了I/O性能,提供了接近原生的水準。 在2020年5月,用Intel i9 10900K進行的69項測試比較顯示了幾乎相同的相對性能。[39] 在2020年12月,用AMD Ryzen 5900X進行的43項測試的基準顯示了WSL 2(20H2)的良好性能,其性能為原生20.04.1 LTS的93%。這比WSL 1有進步,後者在這種比較中只有73%。[40]

截图 编辑

参见 编辑

参考资料 编辑

  1. ^ Craig Loewen. WSL 2 is now available in Windows Insiders. Windows Command Line. 2019-06-12 [2022-05-21]. (原始内容存档于2022-05-29). 
  2. ^ https://github.com/microsoft/WSL/releases?page=1.
  3. ^ Releases 0.58.3. [2022-05-21]. (原始内容存档于2022-05-25). 
  4. ^ Gerwitz, Mike. GNU/kWindows. mikegerwitz.com. [2018-04-08]. (原始内容存档于2020-12-21). 
  5. ^ Harsh, Mike. Run Bash on Ubuntu on Windows. Building Apps for Windows. Microsoft. 30 March 2016 [2016-06-14]. (原始内容存档于2019-05-16). 
  6. ^ Finley, Klint. Why Microsoft Making Linux Apps Run on Windows Isn't Crazy. Wired. Condé Nast. 30 March 2016 [2018-12-20]. (原始内容存档于2021-04-19). 
  7. ^ Kirkland, Dustin. Ubuntu on Windows – The Ubuntu Userspace for Windows Developers. Ubuntu Insights. Canonical. 30 March 2016. (原始内容存档于2017-12-21). 
  8. ^ Hammons, Jack. Bash on Ubuntu on Windows. MSDN. Microsoft. 9 April 2016 [2016-06-14]. (原始内容存档于2017-11-30). 
  9. ^ Get openSUSE Leap 42 - Microsoft Store
  10. ^ Get SUSE Linux Enterprise Server 12 - Microsoft Store
  11. ^ Yegulalp, Serdar. Windows Subsystem for Linux welcomes Suse and Fedora options. InfoWorld. 2017-05-12 [2017-09-16]. (原始内容存档于2018-06-14). 
  12. ^ 12.0 12.1 Ubuntu now available from the Windows Store!. Windows Command Line Tools For Developers Blog. July 10, 2017 [2017-08-11]. (原始内容存档于2019-02-12). 
  13. ^ Debian GNU/Linux for WSL now available in the Windows Store. Windows Command Line Tools For Developers. [2018-03-07]. (原始内容存档于2019-04-21) (美国英语). 
  14. ^ Kali Linux in the Windows App Store. [2018-03-09]. (原始内容存档于2021-01-23) (美国英语). 
  15. ^ 15.0 15.1 15.2 15.3 15.4 Frequently Asked Questions for WSL. Microsoft. [2016-11-13]. (原始内容存档于2016-10-07). 
  16. ^ Bright, Peter. Why Microsoft needed to make Windows run Linux software. Ars Technica. Condé Nast. 6 April 2016 [2018-12-20]. (原始内容存档于2021-05-07). 
  17. ^ Aul, Gabe. Announcing Windows 10 Insider Preview Build 14316. Windows Experience Blog. Microsoft. 6 April 2016 [2016-06-14]. (原始内容存档于2020-08-13). 
  18. ^ Windows Subsystem for Linux Overview. Windows Subsystem for Linux. [2018-04-22]. (原始内容存档于2020-01-04) (美国英语). 
  19. ^ [图]WSL 2迎来重大改进:支持GUI应用 向Windows 10 v1903/1909开放. [2020-09-25]. (原始内容存档于2021-07-16). 
  20. ^ Jack Hammons. Windows Subsystem for Linux Overview. Windows Subsystem for Linux blog on MSDN. April 22, 2016 [2018-12-20]. (原始内容存档于2020-01-04). 
  21. ^ Jack Hammons. WSL File System Support. Windows Subsystem for Linux blog on MSDN. June 15, 2016 [2018-12-20]. (原始内容存档于2020-01-04). 
  22. ^ Jack Hammons. WSL Networking. Windows Subsystem for Linux blog on MSDN. November 8, 2016 [2018-12-20]. (原始内容存档于2019-11-05). 
  23. ^ Please enable WSL to run 32 bit ELF binaries. Windows Developer feedback (Microsoft/UserVoice). [2018-12-20]. (原始内容存档于2019-08-23). 
  24. ^ Support for 32-bit i386 ELF binaries. GitHub. [2018-12-20]. (原始内容存档于2019-04-09). 
  25. ^ Windows 10's Bash shell can run graphical Linux applications with this trick. PC World. [September 10, 2018]. (原始内容存档于2019-02-21). 
  26. ^ GPU not accesssible for running tensorflow and installing CUDA · Issue #1788 · Microsoft/WSL. GitHub. [September 10, 2018]. (原始内容存档于2019-04-12). 
  27. ^ OpenCL & CUDA GPU support. Windows Developer feedback (Microsoft/UserVoice). September 15, 2016 [September 10, 2018]. (原始内容存档于2018-07-07). 
  28. ^ Windows Subsystem for Linux. Phoronix. [2018-12-20]. (原始内容存档于2020-10-01). 
  29. ^ Michael Larabel. A Look At The Windows 10 October 2018 Update Performance With WSL. Phoronix. October 12, 2018 [2018-12-20]. (原始内容存档于2020-10-21). 
  30. ^ Loewen, Craig. What's new for WSL in Insiders Preview Build 18945. Microsoft devblog. 26 July 2019 [26 July 2019]. (原始内容存档于26 July 2019). In this new update we’ve added the ability to start using global config options for WSL. These options are targeted towards power users who want to further customize their WSL experience. 
  31. ^ Hillis, Ben. MicrosoftDocs/WSL | Build 18947. GitHub. 25 July 2019 [26 July 2019]. (原始内容存档于26 July 2019). 
  32. ^ A Deep Dive Into How WSL Allows Windows to Access Linux Files. Windows Command Line Tools For Developers. 2019-05-30 [2019-06-24]. (原始内容存档于2019-05-30) (美国英语). 
  33. ^ Jujjuri, Venkateswararao; Van Hensbergen, Eric; Liguori, Anthony; Pulavarty, Badari. VirtFS—A virtualization aware File System pass-through (PDF). Linux Symposium. July 13–16, 2010 [2022-11-17]. (原始内容存档 (PDF)于2022-11-17). 
  34. ^ Announcing WSL 2. [2022-11-17]. (原始内容存档于2019-05-06). 
  35. ^ Comparing WSL 1 and WSL 2. Microsoft Learn. 2022-10-04 [2022-10-18]. (原始内容存档于2022-09-19). 
  36. ^ Install Linux on Windows with WSL. [2022-11-17]. (原始内容存档于2022-12-20). 
  37. ^ About WSL 2. [2022-11-17]. (原始内容存档于2022-09-19). 
  38. ^ Larabel, Michael. Ubuntu 20.04 vs. Windows 10 WSL/WSL2 Performance In 170+ Benchmarks. Phoronix. 24 June 2020 [2022-11-17]. (原始内容存档于2007-11-17). 
  39. ^ Larabel, Michael. Windows 10 May 2020 Performance For WSL vs. WSL2. Phoronix. 17 June 2020 [2022-11-17]. (原始内容存档于2007-11-17). 
  40. ^ Larabel, Michael. Windows Subsystem For Linux / WSL2 Performance With The AMD Ryzen 9 5900X. Phoronix. 16 December 2020 [2022-11-17]. (原始内容存档于2007-11-17). 

外部链接 编辑