「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-[[戻る>Linuxサブシステム]]

* 目次 [#rdb7338f]
#contents

*概要 [#ua00ab1b]
-Windows Subsystem for Linux (以下、WSLと略す。)
-旧称:[[Bash]] on Ubuntu on Windows / [[Bash]] on Windows

-仮想環境、エミュレーション環境(POSIX互換レイヤ)なので、~
[[Hyper-V]]の機能は使用せず、新しいサブシステムとしてLinuxを動作させることができる。

-これは、Linux系の開発環境をサポートすることが主目的と予想されている。

**方式 [#ma09b3b5]
-Linux互換環境を提供するPicoプロバイダードライバー~
(lxss.sysとlxcore.sysという2つのカーネルドライバー)で実装されている。

-[[リダイレクタ的なアーキテクチャによって>NetBIOS#e614ed6a]]、~
WindowsクライアントとLinuxサーバをPico経由で接続して動作する。
 Microsoft Bash Launcher(bash.exe) ---> LX Session manager service ---> Pico <---> Linux

-これにより、ほぼネイティブに(?)Linuxの機能(バイナリ)がWindowsから呼び出せる。

**ディストリビューション [#xd8a2083]
厳密には以下のLinuxディストリビューションの上で動作可能なツール
-Ubuntu
-OpenSUSE
-SUSE Linux Enterprise Server

*詳細 [#k849312c]

**インストール/アンインストール [#o393cbb1]

***Fall Creators Update(V.1709)以降 [#r34eea59]

-参考
--Windows 10でLinuxプログラムを利用可能にする~
WSL(Windows Subsystem for Linux)をインストールする:Tech TIPS - @IT~
http://www.atmarkit.co.jp/ait/articles/1608/08/news039.html

***Creators Update(V.1703)以前 [#t31e67b4]

-参考
--Windows Subsystem for Linuxをインストールしてみよう! - Qiita~
https://qiita.com/Aruneko/items/c79810b0b015bebf30bb

**自動的にSSHサーバが起動する [#nbdef969]
-WSLを入れると、自動的にSSHサーバが起動する。

-必要に応じて、
--Windowsファイアーウォールで当該ポートを塞ぐか、
--SSHサーバのサービスそのものを無効化する。

**ディストリビューション変更 [#h9713feb]
-WSL-Distribution-Switcherというツールが使用できる。
-V.1703互換操作で初期ディストリビューションセットアップすれば、V.1709のWSLでも、利用可能。

-参考
--Windows 10で始めるBash(41) WSL上のLinuxディストリビューションを変更する | マイナビニュース~
https://news.mynavi.jp/article/bashonwindows-41/

**[[Docker>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker]]との関係 [#ye854812]
WSL上で[[Docker>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker]]を動かすことはできない。~
[[Dockerのクライアント(Dockerコマンド)>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker#jbff7b71]]のみ利用するケースが多い。

*[[.NET Core]], [[ASP.NET Core]]開発 [#w85d0688]
Windows Subsystem for Linux (WSL)を使用した、[[.NET Core]], [[ASP.NET Core]]開発。

**[[.NET Coreの開発]] [#d6efbd4a]
-WSLをインストールし、
-[[Windows上で開発して>.NET Coreの開発]]
-[[検証手順>.NET Coreのデプロイ#fbabb769]]と同様に、WSL上にデプロイする。
--準備と確認
 Installing, this may take a few minutes...
 Installation successful!
 Please create a default UNIX user account. The username does not need to match your Windows username.
 For more information visit: https://aka.ms/wslusers
 Enter new UNIX username: seigi
 Enter new UNIX password:
 Retype new UNIX password:
 passwd: password updated successfully
 Default UNIX user set to: seigi
 To run a command as administrator (user "root"), use "sudo <command>".
 See "man sudo_root" for details.
 
 seigi@nishino:~$ curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100   983  100   983    0     0    319      0  0:00:03  0:00:03 --:--:--   319
 seigi@nishino:~$ sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
 [sudo] password for seigi:
 seigi@nishino:~$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
 seigi@nishino:~$ sudo apt-get update
 Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
 Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
 Get:3 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial InRelease [2,845 B]
 Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
 Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
 Get:6 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [7,532 kB]
 Get:7 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 Packages [38.1 kB]
 Get:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [484 kB]
 Get:9 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [209 kB]
 Get:10 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [7,224 B]
 Get:11 http://security.ubuntu.com/ubuntu xenial-security/restricted Translation-en [2,152 B]
 Get:12 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [344 kB]
 Get:13 http://archive.ubuntu.com/ubuntu xenial/universe Translation-en [4,354 kB]
 Get:14 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [129 kB]
 Get:15 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3,464 B]
 Get:16 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [1,744 B]
 Get:17 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [144 kB]
 Get:18 http://archive.ubuntu.com/ubuntu xenial/multiverse Translation-en [106 kB]
 Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [769 kB]
 Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [319 kB]
 Get:21 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [7,560 B]
 Get:22 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Translation-en [2,272 B]
 Get:23 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [624 kB]
 Get:24 http://archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [252 kB]
 Get:25 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.4 kB]
 Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [8,344 B]
 Get:27 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [4,844 B]
 Get:28 http://archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [3,220 B]
 Get:29 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7,400 B]
 Get:30 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3,996 B]
 Fetched 15.7 MB in 16s (944 kB/s)
 Reading package lists... Done
 seigi@nishino:~$ sudo apt-get install dotnet-sdk-2.0.0
 Reading package lists... Done
 Building dependency tree
 Reading state information... Done
 The following package was automatically installed and is no longer required:
   libfreetype6
 Use 'sudo apt autoremove' to remove it.
 The following additional packages will be installed:
   aspnetcore-store-2.0.0 dotnet-host dotnet-hostfxr-2.0.0 dotnet-runtime-2.0.0 dotnet-runtime-deps-2.1.0-rc1 libcurl3
   liblttng-ust-ctl2 liblttng-ust0 libunwind8 liburcu4
 The following NEW packages will be installed:
   aspnetcore-store-2.0.0 dotnet-host dotnet-hostfxr-2.0.0 dotnet-runtime-2.0.0 dotnet-runtime-deps-2.1.0-rc1
   dotnet-sdk-2.0.0 libcurl3 liblttng-ust-ctl2 liblttng-ust0 libunwind8 liburcu4
 0 upgraded, 11 newly installed, 0 to remove and 135 not upgraded.
 Need to get 108 MB of archives.
 After this operation, 309 MB of additional disk space will be used.
 Do you want to continue? [Y/n] Y
 Get:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 liburcu4 amd64 0.9.1-3 [47.3 kB]
 Get:2 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 aspnetcore-store-2.0.0 amd64 2.0.0-1 [18.1 MB]
 Get:3 http://archive.ubuntu.com/ubuntu xenial/universe amd64 liblttng-ust-ctl2 amd64 2.7.1-1 [72.2 kB]
 Get:4 http://archive.ubuntu.com/ubuntu xenial/universe amd64 liblttng-ust0 amd64 2.7.1-1 [127 kB]
 Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libcurl3 amd64 7.47.0-1ubuntu2.7 [187 kB]
 Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 libunwind8 amd64 1.1-4.1 [46.5 kB]
 Get:7 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-runtime-deps-2.1.0-rc1 amd64 2.1.0-rc1-1 [2,622 B]
 Get:8 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-host amd64 2.1.0-rc1-1 [34.4 kB]
 Get:9 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-hostfxr-2.0.0 amd64 2.0.0-1 [135 kB]
 Get:10 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-runtime-2.0.0 amd64 2.0.0-1 [18.6 MB]
 Get:11 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-sdk-2.0.0 amd64 2.0.0-1 [70.3 MB]
 Fetched 108 MB in 1min 39s (1,078 kB/s)
 Selecting previously unselected package aspnetcore-store-2.0.0.
 (Reading database ... 25532 files and directories currently installed.)
 Preparing to unpack .../aspnetcore-store-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking aspnetcore-store-2.0.0 (2.0.0-1) ...
 Selecting previously unselected package liburcu4:amd64.
 Preparing to unpack .../liburcu4_0.9.1-3_amd64.deb ...
 Unpacking liburcu4:amd64 (0.9.1-3) ...
 Selecting previously unselected package liblttng-ust-ctl2:amd64.
 Preparing to unpack .../liblttng-ust-ctl2_2.7.1-1_amd64.deb ...
 Unpacking liblttng-ust-ctl2:amd64 (2.7.1-1) ...
 Selecting previously unselected package liblttng-ust0:amd64.
 Preparing to unpack .../liblttng-ust0_2.7.1-1_amd64.deb ...
 Unpacking liblttng-ust0:amd64 (2.7.1-1) ...
 Selecting previously unselected package dotnet-runtime-deps-2.1.0-rc1.
 Preparing to unpack .../dotnet-runtime-deps-2.1.0-rc1_2.1.0-rc1-1_amd64.deb ...
 Unpacking dotnet-runtime-deps-2.1.0-rc1 (2.1.0-rc1-1) ...
 Selecting previously unselected package dotnet-host.
 Preparing to unpack .../dotnet-host_2.1.0-rc1-1_amd64.deb ...
 Unpacking dotnet-host (2.1.0-rc1-1) ...
 Selecting previously unselected package dotnet-hostfxr-2.0.0.
 Preparing to unpack .../dotnet-hostfxr-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking dotnet-hostfxr-2.0.0 (2.0.0-1) ...
 Selecting previously unselected package libcurl3:amd64.
 Preparing to unpack .../libcurl3_7.47.0-1ubuntu2.7_amd64.deb ...
 Unpacking libcurl3:amd64 (7.47.0-1ubuntu2.7) ...
 Selecting previously unselected package libunwind8.
 Preparing to unpack .../libunwind8_1.1-4.1_amd64.deb ...
 Unpacking libunwind8 (1.1-4.1) ...
 Selecting previously unselected package dotnet-runtime-2.0.0.
 Preparing to unpack .../dotnet-runtime-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking dotnet-runtime-2.0.0 (2.0.0-1) ...
 Selecting previously unselected package dotnet-sdk-2.0.0.
 Preparing to unpack .../dotnet-sdk-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking dotnet-sdk-2.0.0 (2.0.0-1) ...
 Processing triggers for libc-bin (2.23-0ubuntu9) ...
 Processing triggers for man-db (2.7.5-1) ...
 Setting up aspnetcore-store-2.0.0 (2.0.0-1) ...
 Setting up liburcu4:amd64 (0.9.1-3) ...
 Setting up liblttng-ust-ctl2:amd64 (2.7.1-1) ...
 Setting up liblttng-ust0:amd64 (2.7.1-1) ...
 Setting up dotnet-runtime-deps-2.1.0-rc1 (2.1.0-rc1-1) ...
 Setting up dotnet-host (2.1.0-rc1-1) ...
 Setting up dotnet-hostfxr-2.0.0 (2.0.0-1) ...
 Setting up libcurl3:amd64 (7.47.0-1ubuntu2.7) ...
 Setting up libunwind8 (1.1-4.1) ...
 Setting up dotnet-runtime-2.0.0 (2.0.0-1) ...
 Setting up dotnet-sdk-2.0.0 (2.0.0-1) ...
 This software may collect information about you and your use of the software, and send that to Microsoft.
 Please visit http://aka.ms/dotnet-cli-eula for more information.
 Welcome to .NET Core!
 ---------------------
 Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
 
 .NET Core Tools Telemetry
 --------------
 The .NET Core Tools include a telemetry feature that collects usage information. It is important that the .NET Team understands how the tools are being used so that we can improve them.
 
 The data collected is anonymous and will be published in an aggregated form for use by both Microsoft and community engineers under the Creative Commons Attribution License.
 
 The .NET Core Tools telemetry feature is enabled by default. You can opt-out of the telemetry feature by setting an environment variable DOTNET_CLI_TELEMETRY_OPTOUT (for example, 'export' on macOS/Linux, 'set' on Windows) to true (for example, 'true', 1). You can read more about .NET Core tools telemetry at https://aka.ms/dotnet-cli-telemetry.
 
 Installation Note
 --------------
 A command will be run during the install process that will improve project restore speed and enable offline access. It will take up to a minute to complete.
 Processing triggers for libc-bin (2.23-0ubuntu9) ...
 seigi@nishino:~$ dotnet --version
 2.0.0
 seigi@nishino:~$ which dotnet
 /usr/bin/dotnet
 seigi@nishino:~$ dotnet new console
 
 Welcome to .NET Core!
 ---------------------
 Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
 
 Telemetry
 --------------
 The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include command-line arguments. The data is collected by Microsoft and shared with the community.
 You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
 You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
 Getting ready...
 The template "Console Application" was created successfully.
 
 Processing post-creation actions...
 Running 'dotnet restore' on /home/seigi/seigi.csproj...
   Restoring packages for /home/seigi/seigi.csproj...
   Generating MSBuild file /home/seigi/obj/seigi.csproj.nuget.g.props.
   Generating MSBuild file /home/seigi/obj/seigi.csproj.nuget.g.targets.
   Restore completed in 236.36 ms for /home/seigi/seigi.csproj.
 
 
 Restore succeeded.
 
 seigi@nishino:~$ dotnet publish -f netcoreapp2.0
 Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
 Copyright (C) Microsoft Corporation. All rights reserved.
 
   seigi -> /home/seigi/bin/Debug/netcoreapp2.0/seigi.dll
   seigi -> /home/seigi/bin/Debug/netcoreapp2.0/publish/
 seigi@nishino:~$ dotnet /home/seigi/bin/Debug/netcoreapp2.0/seigi.dll
 Hello World!
 seigi@nishino:~$

--ビルドしたものを「/mnt/c」※ 1 を経由して実行~
※ 1 DrvFsのVFSファイルシステムプラグイン。
 seigi@nishino:~$ dotnet 
 /mnt/c/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp2.0/ConsoleApp1.dll
 Hello World!
 seigi@nishino:~$

**[[ASP.NET Coreの開発]] [#r6a90b09]
-WSLをインストールし、
-[[Windows上で開発して>ASP.NET Coreの開発]]
-[[検証手順>ASP.NET Coreのデプロイ#ac95e514]]と同様に、WSL上にデプロイする。

--準備と確認
 seigi@nishino:~$ dotnet new mvc
 Creating this template will make changes to existing files:
   Overwrite   seigi.csproj
   Overwrite   Program.cs
 
 Rerun the command and pass --force to accept and create.
 seigi@nishino:~$
 seigi@nishino:~$ dotnet new mvc --force
 The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
 This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details.
 
 Processing post-creation actions...
 Running 'dotnet restore' on /home/seigi/seigi.csproj...
   Restoring packages for /home/seigi/seigi.csproj...
   Restoring packages for /home/seigi/seigi.csproj...
   Restore completed in 2.09 sec for /home/seigi/seigi.csproj.
   Generating MSBuild file /home/seigi/obj/seigi.csproj.nuget.g.targets.
   Restore completed in 3.83 sec for /home/seigi/seigi.csproj.
 
 
 Restore succeeded.
 
 seigi@nishino:~$ dotnet run
 warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
       No XML encryptor configured. Key {89022286-2fdf-47e0-85d2-0047907c89b1} may be persisted to storage in unencrypted form.
 
 Hosting environment: Production
 Content root path: /home/seigi
 Now listening on: http://localhost:5000
 Application started. Press Ctrl+C to shut down.
 ^CApplication is shutting down...
 
 seigi@nishino:~$
#ref(mvc1.png,left,nowrap,mvcの実行1,60%)

--ビルドしたものを「/mnt/c」※ 1 を経由して実行~
#ref(mvc2.png,left,nowrap,mvcの実行2)


**参考 [#i96ee883]
-Windows Subsystem for Linuxを使って「開発」をしてみよう - Build Insider~
http://www.buildinsider.net/enterprise/wsl/02

*参考 [#ida97117]

**Build Insider [#n82f3c3e]
-Windows Subsystem for Linuxとは? そのインストールと使い方~
http://www.buildinsider.net/enterprise/wsl/01
-Windows Subsystem for Linuxを使って「開発」をしてみよう~
http://www.buildinsider.net/enterprise/wsl/02
-Bash on Ubuntu on Windowsの、Creators Updateでの強化点&新機能~
http://www.buildinsider.net/enterprise/wsl/creatorsupdate

**@IT [#zc4bbedd]
-Windows 10 The Latest:Windows 10でUbuntuのシェル「Bash」が動き始める! だが日本語はどうなる? (1/2)~
http://www.atmarkit.co.jp/ait/articles/1604/11/news031.html
-Tech TIPS:Windows 10のLinux/Ubuntu互換環境でbashを使う~
http://www.atmarkit.co.jp/ait/articles/1608/08/news039.html

**Qiita [#aae60597]
-Bash on Ubuntu on Windowsの動作要件~
https://qiita.com/tsukamoto/items/47717f8872325734b4e6
-Bash on Ubuntu on Windowsをインストールしてみよう!~
https://qiita.com/Aruneko/items/c79810b0b015bebf30bb

-WSLでDockerを使う~
https://qiita.com/tkyonezu/items/f89fe109ee764912bc8f
-Windows Subsystem for LinuxからDockerを使う~
https://qiita.com/koduki/items/37b97ef3310186ff73b8

**kledgeb [#tbdfa959]
-kledgeb: WSL~
https://kledgeb.blogspot.jp/search/label/WSL?max-results=10

***仕組み [#c8c36ba1]
-WSL その1 - Ubuntu on Windowsの概要とアーキテクチャー・Ubuntu on WindowsのFAQ~
https://kledgeb.blogspot.jp/2016/04/wsl-1-ubuntu-on-windowsubuntu-on.html
-その17 - WSLの仕組みとWSLを構成するコンポーネント~
https://kledgeb.blogspot.jp/2016/05/wsl-17-wslwsl.html

***ファイルシステム [#ve679160]
-WSLがサポートするファイルシステム
--その26 -(前編)LinuxのファイルシステムとWindowsのファイルシステム~
https://kledgeb.blogspot.jp/2016/06/wsl-26-wsllinuxwindows.html
--その27 -(後編)WSLのファイルシステム~
https://kledgeb.blogspot.jp/2016/06/wsl-27-wslwsl.html

-その60 - WindowsアプリからUbuntu環境内のファイルを決していじってはならない~
https://kledgeb.blogspot.jp/2016/11/wsl-60-windowsubuntu.html

-その109 - LinuxからWindowsのファイルにアクセスできない不具合~
https://kledgeb.blogspot.jp/2017/08/wsl-109-linuxwindows.html

***相互運用 [#a516035a]
-その52 - BashからWindowsバイナリーを起動する機能の有効・無効を切り替えるには~
https://kledgeb.blogspot.jp/2016/10/wsl-52-bashwindows.html
-その53 - WindowsとBashの相互運用~
https://kledgeb.blogspot.jp/2016/11/wsl-53-windowsbash.html

-WindowsとUbuntuの相互運用の仕組み
--その54 -(前編)~
https://kledgeb.blogspot.jp/2016/11/wsl-54-windowsubuntu.html
--その55 -(後編)~
https://kledgeb.blogspot.jp/2016/11/wsl-55-windowsubuntu.html

----
Tags: [[:Windows]], [[:Linuxサブシステム]], [[:仮想化]]

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS