適用於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 Window系統)。[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 Window系統來執行一些圖形(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). 

外部連結 編輯