windows:wsl

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
次のリビジョン両方とも次のリビジョン
windows:wsl [2019/09/13 23:09] ともやんwindows:wsl [2019/09/20 02:04] – [Cloud9 SDK] ともやん
行 10: 行 10:
 ====== Windows Subsystem for Linux 2 (WSL 2) ====== ====== Windows Subsystem for Linux 2 (WSL 2) ======
 ソースコード: [[https://github.com/microsoft/WSL2-Linux-Kernel|GitHub - microsoft/WSL2-Linux-Kernel: The source for the Linux kernel used in Windows Subsystem for Linux 2 (WSL2)]]\\ ソースコード: [[https://github.com/microsoft/WSL2-Linux-Kernel|GitHub - microsoft/WSL2-Linux-Kernel: The source for the Linux kernel used in Windows Subsystem for Linux 2 (WSL2)]]\\
 +{{:windows:wsl_tmux.png?640|WSL 2 Terminal}}\\
 \\ \\
  Windows Subsystem for Linux 2 (以下 WSL 2) は、2019/05/06 に[[https://devblogs.microsoft.com/commandline/announcing-wsl-2/|ブログ]]で発表され、2019年6月末までに [[https://insider.windows.com/ja-jp/|Windows Insider Program]] を通じて Microsoft が Windows で Linux カーネルを出荷する試みである。[[windows:windows_10_insider_previews|Windows 10 Insider Previews]] も参照のこと。\\  Windows Subsystem for Linux 2 (以下 WSL 2) は、2019/05/06 に[[https://devblogs.microsoft.com/commandline/announcing-wsl-2/|ブログ]]で発表され、2019年6月末までに [[https://insider.windows.com/ja-jp/|Windows Insider Program]] を通じて Microsoft が Windows で Linux カーネルを出荷する試みである。[[windows:windows_10_insider_previews|Windows 10 Insider Previews]] も参照のこと。\\
行 25: 行 26:
  
 ===== インストール ===== ===== インストール =====
-コマドプロンプより Windows 10 ビド 18917 以降を実行していることを確認する。\\ +[[.:wsl:install|WSL 2 のイ]]\\
-<code batch> +
-> ver+
  
-Microsoft Windows [Version 10.0.18362.356]+===== 日本語環境に設定 ===== 
 +標準のインストールだと日本語が **□** に文字化けする。\\ 
 +これはターミナルのフォントが日本語フォントになっていない為である。\\ 
 +<WRAP prewrap 100%> 
 +<code> 
 +$ ll 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Nov 17  2015  Tracing 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Jan 23  2016  usb_driver 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Sep 13 23:24  Videos 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Nov 26  2015 'VirtualBox VMs' 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Jul 29 23:22  webrtc_event_logs 
 +lrwxrwxrwx 1 tomoyan tomoyan       65 Sep 13 22:40 '□□□□ □□□□' -> '/mnt/c/Users/tomoyan/AppData/Roaming/Microsoft/Windows/Start Menu' 
 +</code> 
 +</WRAP> 
 + 
 +ターミナルのフォントを**MSゴシック**などの日本語フォントに変更する。\\ 
 +{{:windows:wsl_set_terminal_font.png?400|}}\\ 
 +<WRAP prewrap 100%> 
 +<code> 
 +$ ll 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Nov 17  2015  Tracing 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Jan 23  2016  usb_driver 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Sep 13 23:24  Videos 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Nov 26  2015 'VirtualBox VMs' 
 +drwxr-xr-x 1 tomoyan tomoyan      512 Jul 29 23:22  webrtc_event_logs 
 +lrwxrwxrwx 1 tomoyan tomoyan       65 Sep 13 22:40 'スタート メニュー' -> '/mnt/c/Users/tomoyan/AppData/Roaming/Microsoft/Windows/Start Menu' 
 +</code> 
 +</WRAP> 
 + 
 +日本語ランゲージパックをインストールする。\\ 
 +**sudo dnf install langpacks-ja** を実行する。\\ 
 +<WRAP prewrap 100% #result> 
 +<code> 
 +$ sudo dnf install langpacks-ja 
 +Fedora Modular 30 - x86_64                               363 kB/s | 1.9 MB     00:05 
 +Fedora Modular 30 - x86_64 - Updates                     318 kB/s | 2.9 MB     00:09 
 +Fedora 30 - x86_64 - Updates                             249 kB/s |  24 MB     01:37 
 +Fedora 30 - x86_64                                       237 kB/s |  61 MB     04:22 
 +whitewaterfoundry_wslu                                   184  B/s | 833  B     00:04 
 +Dependencies resolved. 
 +==================================================================================== 
 + Package                            Arch      Version              Repository  Size 
 +==================================================================================== 
 +Installing: 
 + langpacks-ja                       noarch    1.0-17.fc30          fedora     8.4 k 
 +Installing dependencies: 
 + google-noto-cjk-fonts-common       noarch    20190416-2.fc30      updates     19 k 
 +Installing weak dependencies: 
 + glibc-langpack-ja                  x86_64    2.29-22.fc30         updates    323 k 
 + google-noto-sans-cjk-ttc-fonts     noarch    20190416-2.fc30      updates     85 M 
 + google-noto-serif-cjk-ttc-fonts    noarch    20190416-2.fc30      updates    109 M 
 + 
 +Transaction Summary 
 +==================================================================================== 
 +Install  5 Packages 
 + 
 +Total download size: 194 M 
 +Installed size: 297 M 
 +Is this ok [y/N]: y 
 +Downloading Packages: 
 +(1/5): google-noto-cjk-fonts-common-20190416-2.fc30  27 kB/s |  19 kB     00:00 
 +(2/5): glibc-langpack-ja-2.29-22.fc30.x86_64.rpm     83 kB/s | 323 kB     00:03 
 +(3/5): langpacks-ja-1.0-17.fc30.noarch.rpm           73 kB/s | 8.4 kB     00:00 
 +(4/5): google-noto-sans-cjk-ttc-fonts-20190416-2.fc  97 kB/s |  85 MB     15:03 
 +(5/5): google-noto-serif-cjk-ttc-fonts-20190416-2.f 105 kB/s | 109 MB     17:36 
 +------------------------------------------------------------------------------------ 
 +Total                                               188 kB/s | 194 MB     17:39 
 +Running transaction check 
 +Transaction check succeeded. 
 +Running transaction test 
 +Transaction test succeeded. 
 +Running transaction 
 +  Preparing        :                                                            1/1 
 +  Installing       : google-noto-cjk-fonts-common-20190416-2.fc30.noarch        1/5 
 +  Installing       : google-noto-sans-cjk-ttc-fonts-20190416-2.fc30.noarch      2/5 
 +  Installing       : google-noto-serif-cjk-ttc-fonts-20190416-2.fc30.noarch     3/5 
 +  Installing       : glibc-langpack-ja-2.29-22.fc30.x86_64                      4/5 
 +  Installing       : langpacks-ja-1.0-17.fc30.noarch                            5/5 
 +  Running scriptlet: langpacks-ja-1.0-17.fc30.noarch                            5/5 
 +  Verifying        : glibc-langpack-ja-2.29-22.fc30.x86_64                      1/5 
 +  Verifying        : google-noto-cjk-fonts-common-20190416-2.fc30.noarch        2/5 
 +  Verifying        : google-noto-sans-cjk-ttc-fonts-20190416-2.fc30.noarch      3/5 
 +  Verifying        : google-noto-serif-cjk-ttc-fonts-20190416-2.fc30.noarch     4/5 
 +  Verifying        : langpacks-ja-1.0-17.fc30.noarch                            5/5 
 + 
 +Installed: 
 +  langpacks-ja-1.0-17.fc30.noarch 
 +  glibc-langpack-ja-2.29-22.fc30.x86_64 
 +  google-noto-sans-cjk-ttc-fonts-20190416-2.fc30.noarch 
 +  google-noto-serif-cjk-ttc-fonts-20190416-2.fc30.noarch 
 +  google-noto-cjk-fonts-common-20190416-2.fc30.noarch 
 + 
 +Complete! 
 +</code> 
 +</WRAP> 
 + 
 +==== WSL 2 の systemd 問題 ==== 
 +システムロケール設定を **ja_JP.UTF-8** に変更する。\\ 
 +<code> 
 +$ sudo localectl set-locale LANG=ja_JP.UTF-8 
 +System has not been booted with systemd as init system (PID 1). Can't operate. 
 +Failed to create bus connection: Host is down 
 +</code> 
 +<code> 
 +システムは、initd システム (PID 1) なので systemd として起動されていません。操作できません。 
 +バスへの接続に失敗しました: ホストがダウンしています
 </code> </code>
-[スタート] - [設定] - [更新とセキュリティ] - [Windows Update] の順に選択し、[更新プログラムのチェック] を実行する。\\ 
 \\ \\
-※ 2019/09/13 現在 Build 18917 以降は **[[windows:windows_10_insider_previews|Windows 10 Insider Previews]]** としてのみ公開されてい\\+本物の Fedora の PID 1 は **/usr/lib/systemd/systemd** であが...\\ 
 +<WRAP prewrap 100%> 
 +<code> 
 +$ ps aux 
 +USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 
 +root          0.0  0.5 171732  5500 ?        Ss    9月05   2:13 /usr/lib/systemd/systemd --switched-root --system --deserialize 33 
 +root          0.0  0.0      0     0 ?        S     9月05   0:00 [kthreadd] 
 +... 
 +</code> 
 +</WRAP>
  
-PowerShell を管理者実行する。\\ +現状の WSL 2 では PID 1 は **/init** である。\\ 
-<code batch+<WRAP prewrap 100%
-powershell start-process powershell -verb runas+<code> 
 +$ ps aux 
 +USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 
 +root          0.0  0.0    888   560 ?        Sl   10:55   0:00 /init 
 +root          0.0  0.0    896    80 ?        Ss   10:55   0:00 /init 
 +...
 </code> </code>
 +</WRAP>
  
-管理者実行した PowerShell で Hyper-V が有効になってとを確認する。\\ +現時点 (2019/09/16 現在) の WSL 2 は、**systemd** はサポートされていい。\\ 
-<code powershell+[[https://github.com/systemd/systemd/issues/8036|Systemd support for Windows Subsystem for Linux (WSL) · Issue #8036 · systemd/systemd · GitHub]]\\ 
-PS > bcdedit /enum | find `"hypervisorlaunchtype`" +今後 Microsoft によって systemd が有効化される可能性はあると思う。\\ 
-hypervisorlaunchtype    Auto+[[https://github.com/microsoft/WSL/issues/994|Blockers for systemd? · Issue #994 · microsoft/WSL]]ここで議論中。\\ 
 +しかし、Fedora は **systemd** 早くに採用した歴史があるので、**systemd** が使えないのはかなり致命的である。\\ 
 +\\ 
 +**nmcli** も使えない... orz\\  
 +<code> 
 +$ nmcli con 
 +Error: Could not create NMClient object: Could not connect: No such file or directory.
 </code> </code>
  
-Hyper-V が Off の場合は On にする。\\ +**systemctl** も使えない... orz\\  
-<code powershell+<code> 
-PS > bcdedit /enum | find `"hypervisorlaunchtype`" +$ systemctl 
-hypervisorlaunchtype    Off+System has not been booted with systemd as init system (PID 1). Can't operate. 
 +Failed to connect to bus: Host is down
 </code> </code>
-<code powershell+ 
-PS > bcdedit /set hypervisorlaunchtype auto +**localectl** も使えない(日本語化できない)... orz\\ 
-この操作を正しく終了しました。+<code> 
 +$ sudo localectl set-locale LANG=ja_JP.UTF-8 
 +System has not been booted with systemd as init system (PID 1). Can't operate. 
 +Failed to create bus connection: Host is down
 </code> </code>
  
-Hyper-有効化した場合は PC 一旦再起動する。\\ +==== genie-systemd の fork ==== 
-<code powershell+本家: [[https://github.com/arkane-systems/genie|arkane-systems/genie]]\\ 
-PS shutdown //t 0+元ネタ: [[https://gist.github.com/therealkenc/f5109716abd885b2334f6bdaf8848b29|wsltub leftovers]]\\ 
 +ブログ: [[https://randomactsofcoding.wordpress.com/2019/06/13/systemd-on-wsl2/|systemd on WSL2 | public class Random : Coding {]]\\ 
 +\\ 
 +この fork は本家に取り込まれたので手順修正した。\\ 
 +[[https://github.com/arkane-systems/genie/commit/a71ec0603fc07ceea0d2e4fd307c1f9acd0cc9cf|Merge pull request #25 from tomoyan596/master]]\\ 
 +<del>Fedora Remix for WSL 用に [[https://github.com/arkane-systems/genie|arkane-systems/genie]] を fork して ./fedora-build を追加してみた。</del>\\ 
 +<del>[[https://github.com/tomoyan596/genie|tomoyan596/genie: A quick way into a systemd "bottle" for WSL]]</del>\\ 
 +\\ 
 +使い方は以下のようになる。\\ 
 +<code> 
 +$ sudo dnf install git 
 +$ cd ~ 
 +$ git clone https://github.com/arkane-systems/genie.git 
 +$ cd genie 
 +$ ./fedora-build 
 +</code> 
 +※<html><span style="color: red;"><b>注意!!: </b></span></html>**cd ~** は **dotnet core アプリ** のビルドは 9p ファイルシステム上で行うと失敗するので必ず **$HOME** などの **ext4 ファイルシステム** 上で行う必要がある。\\ 
 +これで依存パッケージも genie もすべてインストールされる。\\ 
 +\\ 
 +**genie -s** を実行して **systemd** を有効化する。\\ 
 +<code> 
 +$ genie -s
 </code> </code>
  
-再起動した場合は再び PowerShell を管理者として実行する。\\ +状態でステムロケル設定が可能る。\\ 
-**"仮想マシン プラットフォーム"** オプョン コンポネントを有効る。\\ +<code> 
-<code powershell+$ sudo localectl set-locale LANG=ja_JP.UTF-
-PS > Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform+$ source /etc/locale.conf 
 +$ locale 
 +LANG=ja_JP.UTF-
 +LC_CTYPE="ja_JP.UTF-8" 
 +LC_NUMERIC="ja_JP.UTF-8" 
 +LC_TIME="ja_JP.UTF-8" 
 +LC_COLLATE="ja_JP.UTF-8" 
 +LC_MONETARY="ja_JP.UTF-8" 
 +LC_MESSAGES="ja_JP.UTF-8" 
 +LC_PAPER="ja_JP.UTF-8" 
 +LC_NAME="ja_JP.UTF-8" 
 +LC_ADDRESS="ja_JP.UTF-8" 
 +LC_TELEPHONE="ja_JP.UTF-8" 
 +LC_MEASUREMENT="ja_JP.UTF-8" 
 +LC_IDENTIFICATION="ja_JP.UTF-8" 
 +LC_ALL= 
 +$ sudo -s 
 +[sudo] tomoyan のパスワード: 
 +</code> 
 +<html><span style="color: blue; font-size: 48px;"><b>genie 素晴らしい!!</b></span></html>\\
  
-Path          : +=== getty@tty1.service の無効化 === 
-Online        True +本家のドキュメント [[https://github.com/arkane-systems/genie|arkane-systems/genie]] にあるように、**getty@tty1.service** を無効にする。\\ 
-RestartNeeded : False+<WRAP prewrap 100%> 
 +<code> 
 +RECOMMENDATIONS 
 +Once you have this up and running, I suggest disabling via systemctl the getty@tty1 service (since logging on and using WSL is done via ptsen, not ttys).
 </code> </code>
 +<code>
 +これを実行したら、systemctl を介して getty@tty1 サービスを無効にすることをお勧めします (WSL へのログオンと使用は tty ではなく ptsen で行われるため)。
 +</code>
 +</WRAP>
 +
 +**getty@tty1.service** を停止し無効化する。\\
 +<WRAP prewrap 100%>
 +<code>
 +$ sudo systemctl stop getty@tty1.service
 +$ sudo systemctl disable getty@tty1.service
 +Removed /etc/systemd/system/getty.target.wants/getty@tty1.service.
 +$ sudo systemctl status getty@tty1.service
 +● getty@tty1.service - Getty on tty1
 +   Loaded: loaded (/usr/lib/systemd/system/getty@.service; disabled; vendor preset:>
 +   Active: inactive (dead)
 +     Docs: man:agetty(8)
 +           man:systemd-getty-generator(8)
 +           http://0pointer.de/blog/projects/serial-console.html
  
-**"仮想マシン プラットフォーム"** を有効化したら再び PC を再起動する。\\ + 9月 16 08:11:54 Cmon-wsl systemd[1]: Started Getty on tty1. 
-<code powershell> + 9月 16 08:45:09 Cmon-wsl systemd[1]: Stopping Getty on tty1... 
-PS > shutdown /r /t 0+ 9月 16 08:45:09 Cmon-wsl systemd[1]: getty@tty1.service: Succeeded. 
 + 9月 16 08:45:09 Cmon-wsl systemd[1]: Stopped Getty on tty1.
 </code> </code>
 +</WRAP>
  
-再起動した場合は再び PowerShell 管理者として実行する。\\ +=== 毎回 genie -s 実行なくも良い方法 === 
-Windows Subsystem for Linux インストールする。\\ +WSL 2 を起動する度に systemd 有効化るのは手間である。\\ 
-<code powershell> +で以下ように bash 起動時に自動で有効化ることが出来る。(お好みで...)\\ 
-PS > Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux +<code> 
-この操作を完了するため、今すぐコンピューターを再起動しまか? +$ sudo vi /etc/profile.d/genie.sh
-[Y] Yes  [N] No  [?] ヘルプ (既定値は "Y")<- Enter キーを入力+
 </code> </code>
 +**systemd** が **PID 1** で起動していない場合は **genie -s** を実行する。\\
 +<WRAP prewrap 100%>
 +<code bash /etc/profile.d/genie.sh>
 +if [ "`ps -eo pid,lstart,cmd | grep systemd | grep -v -e grep -e systemd- | sort -n -k2 | awk 'NR==1 { print $1 }'`" != "1" ]; then
 +  genie -s
 +fi
 +</code>
 +</WRAP>
  
-[[https://aka.ms/wslstore|https://aka.ms/wslstore Microsoft Store]] を開いて、自分の好きな Linux ディストリビュションを選択する。\\ +===== 基本的なコマンドのインストール ===== 
-{{:windows:wslstore.png?733|wslstore}}\\+[[https://www.tomoyan.net/linux/fedora_minimal_install#%E5%9F%BA%E6%9C%AC%E7%9A%84%E3%81%AA%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB|Fedora minimal インストール 基本的なコマンドのインストール]] を参考に基本的コマンドをインストーする。\\
  
-ここでは、230 円だったので Fedora Remix 購入しみた。\\ +==== キャッシュキープ ==== 
-{{:windows:wslstore_fedora_remix.png?704|Fedora Remix}}\\+お好み以下の設定行っおくと RPM パッケージがキャッシュされるようになる。\\ 
 +<code> 
 +$ sudo vi /etc/dnf/dnf.conf 
 +</code> 
 +<code autoconf /etc/dnf/dnf.conf> 
 +[main] 
 +gpgcheck=1 
 +installonly_limit=3 
 +clean_requirements_on_remove=true 
 +keepcache=1 <- 追記する。 
 +</code>
  
-ダウンロードが完了したら [スタート- [Fedora Rimix for WSL] を起動してみる。\\+ダウンロード済の場合は **[SKIPPED]** になる。\\
 <code> <code>
-Unpacking Linux filesystem image, this may take a few minutes... +$ sudo dnf install usbutils -y 
-WslRegisterDistribution failed with error0x80070057 +... 
-Error0x80070057 ???????????????+パッケージのダウンロード
 +[SKIPPED] hwdata-0.327-1.fc30.noarch.rpmAlready downloaded 
 +[SKIPPED] usbutils-012-2.fc30.x86_64.rpm: Already downloaded 
 +... 
 +完了しました! 
 +</code>
  
-Press any key to continue...+==== パッケージのインストール ==== 
 +**tmux - 端末多重化ソフトウェア と htop - 高機能タスクマネージャー**\\ 
 +\\ 
 +WSL で端末の複数接続に悩む前に tmux を入れておくといいだろう。\\ 
 +**tmux** は端末画面を複数分割してレイアウトできる。\\ 
 +**Ctrl + B** を入力後に様々な機能を呼び出せる。(簡単に書くと以下の通り)\\ 
 +  * Ctrl + B を入力後 ? でキーバインド一覧 
 +  * Ctrl + B を入力後 Shift + 5 で左右に分割 
 +  * Ctrl + B を入力後 Shift + 2 で上下に分割 
 +  * Ctrl + B を入力後 ↑ or ↓ or ← or → でペイン移動 
 +  * Ctrl + B を入力後 Space を繰り返すとお好みのレイアウトに 
 +**htop** は F1 キーを押すと使用方法が表示される。\\ 
 +{{:windows:wsl_tmux.png?600|tmux on wsl}}\\ 
 +<code> 
 +$ sudo dnf install tmux htop
 </code> </code>
-化けているが... 本当はこういうエラーらしい。\\+\\ 
 +**netstat arp ifconfig route** … など\\
 <code> <code>
-Unpacking Linux filesystem image, this may take a few minutes... +$ sudo dnf install net-tools -y
-WslRegisterDistribution failed with error: 0x80070057 +
-Error: 0x80070057 The parameter is incorrect. +
-Press any key to continue...+
 </code> </code>
  
-Windows Subsystem for Linux を一旦無効化する。\\ +**dig host nslookup nsupdate**\\ 
-<code powershell+<code> 
-PS > Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux +$ sudo dnf install bind-utils -y
-この操作を完了するために、今すぐコンピューターを再起動しますか? +
-[Y] Yes  [N] No  [?] ヘルプ (既定値は "Y"): <Enter キーを入力+
 </code> </code>
  
-再起動したら再び PowerShell を管理者として実行する。\\ +**whois**\\ 
-Windows Subsystem for Linux を再度有効化して再起動する。\\ +<code> 
-<code powershell+$ sudo dnf install jwhois -y
-PS > Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux +
-この操作を完了するために、今すぐコンピューターを再起動しますか? +
-[Y] Yes  [N] No  [?] ヘルプ (既定値は "Y"): <Enter キーを入力+
 </code> </code>
  
-再起動が完了したら [スタート] [Fedora Rimix for WSL] を起動する。\\ +**lspci これは以下の理由にり入れても使え**\\
-すると今度きちんと以下のような状態に。\\+
 <code> <code>
-Unpacking Linux filesystem image, this may take a few minutes... +$ cat /proc/bus/pci 
-Welcome to Fedora Remix for WSL. Powered by Pengwin Enterprise. +cat: /proc/bus/pciそのようなファイルやディレクトリはありません
-Please create a default Linux user account. The username does not need to match your Windows username. +
-Enter new UNIX username:+
 </code> </code>
  
-最初にデフォルト Linux ユーザーの作成を行う。\\+**lsusb**\\
 <code> <code>
-Welcome to Fedora Remix for WSL. Powered by Pengwin Enterprise. +$ sudo dnf install usbutils -y
-Please create a default Linux user account. The username does not need to match your Windows username. +
-Enter new UNIX username: tomoyan <ユーザーを入力する(Windows ユーザーと一致している必要はない) +
-Changing password for user tomoyan. +
-New password: <- UNIX ユーザーのパスワードを入力 +
-Retype new password: <- UNIX ユーザーの確認用パスワードを入力 +
-passwd: all authentication tokens updated successfully. +
-Installation successful! +
-[tomoyan@Cmon ~]$ exit+
 </code> </code>
  
-再び PowerShell を管理者として実行する。\\ +**lsmod depmod insmod rmmod modinfo modprobe**\\ 
-**wsl -l** を実行して **Fedora Remix** が初期化済みることを確認する。\\ +<code> 
-<code powershell>+$ sudo dnf install kmod -y 
 +</code> 
 + 
 +**mkpasswd** … など\\ 
 +<code> 
 +$ sudo dnf install expect -
 +</code> 
 + 
 +**rsync**\\ 
 +<code> 
 +$ sudo dnf install rsync -y 
 +</code> 
 + 
 +**man**\\ 
 +<code> 
 +$ sudo dnf install man -y 
 +</code> 
 + 
 +===== WSL 2 ファイルシステムへのアクセス ===== 
 +WSL 2 のファイルシステムへのアクセスは PowerShell で **\\wsl$\<distro>** の形式で行うことがで。\\ 
 +れは Plan 9 Network Provider (9p 省略) 利用して提供されるネットワーク共有である。\\ 
 +※ 9p はもともと [[https://ja.wikipedia.org/wiki/Plan_9_from_Bell_Labs|Plan 9 from Bell Labs]](研究用分散OS) 用に開発されたファイル共有プロトコルである。\\  
 +<code>
 PS > wsl -l PS > wsl -l
 Windows Subsystem for Linux ディストリビューション: Windows Subsystem for Linux ディストリビューション:
 fedoraremix (既定) fedoraremix (既定)
 +PS > cd \\wsl$\fedoraremix
 +PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\fedoraremix> explorer.exe .
 </code> </code>
 +PowerShell で **explorer.exe .** コマンドを実行するとエクスプローラーが開く。\\
 +{{:windows:wsl_linux_fs_access.png?640|WSL Linux FS Access}}\\
  
-念のため再度確認!! **wsl** コマンドに **--set-version** オプションが無い場合は Windows 10 ビルド 18917 以降実行していないので Windows を更新する。\\ +コマンドプロンプトからは一旦ネットワークドライブの割り当てを行う必要がある。\\ 
-<WRAP prewrap 100% #result> +<code> 
-<code powershell+> pushd \\wsl$\fedoraremix 
-PS > wsl --help +Z:\> explorer.exe . 
-Copyright (c) Microsoft CorporationAll rights reserved.+</code> 
 +**pushd** は Z: X: Y: と空いているライブ自動割り当てしてくれる。\\ 
 +\\ 
 +または **net use** コマンドドライブ割り当てする。\\ 
 +<code> 
 +net use x: \\wsl$\fedoraremix /persistent:yes 
 +コマンドは正常に終了しました。 
 +> x: 
 +X:¥> explorer.exe . 
 +</code> 
 +割り当て解除は **net use x: /delete** で行う。\\
  
-使用: wsl.exe [Argument] [Options...] [CommandLine]+===== .NET Core ===== 
 +.NET Core を Fedora にインストールする方は、以下を参照のこと。\\ 
 +[[linux:fedora_copr#net_core|Fedora Copr リポジトリ - .NET Core]]\\
  
-Linux バイナリ実行すための引数:+===== Cloud9 SDK ===== 
 +[[javascript:cloud9_sdk|Cloud9 SDK]] 元にインストールしてみ。\\ 
 +[[.:wsl:c9sdk|Cloud9 SDK on WSL2]]\\
  
-    コマンド を指定しないと、wsl.exe は既定のシェルを起動します。+===== トブルシューティグ =====
  
-    --exec, -e <コマンド ライン+==== System has not been booted with systemd as init system (PID 1). が発生する ==== 
-        指定したコマンドを既定の Linux ェルを使用しないで実行します。+<code
 +System has not been booted with systemd as init system (PID 1). Can't operate. 
 +Failed to create bus connection: Host is down 
 +</code> 
 +<code> 
 +システムはinitd ステム (PID 1) ので systemd として起動されてません。操作きません。 
 +バスへの接続に失敗ました: ホストがダウンしています 
 +</code> 
 +\\ 
 +現時点の WSL 2 では、**systemd** はサポートされていない\\ 
 +[[https://github.com/systemd/systemd/issues/8036|Systemd support for Windows Subsystem for Linux (WSL) · Issue #8036 · systemd/systemd · GitHub]]\\ 
 +\\ 
 +本物の Fedora の PID 1 は **/usr/lib/systemd/systemd** であるが...\\ 
 +<WRAP prewrap 100%> 
 +<code> 
 +$ ps aux 
 +USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 
 +root          0.0  0.5 171732  5500 ?        Ss    9月05   2:13 /usr/lib/systemd/systemd --switched-root --system --deserialize 33 
 +root          0.0  0.0      0     0 ?        S     9月05   0:00 [kthreadd] 
 +... 
 +</code> 
 +</WRAP>
  
-    -- +現状の WSL 2 では PID 1 は **/init** である\\ 
-        残りコマンド ラインをそのまま渡します+<WRAP prewrap 100%> 
 +<code> 
 +$ ps aux 
 +USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 
 +root          0.0  0.0    888   560 ?        Sl   10:55   0:00 /init 
 +root          0.0  0.0    896    80 ?        Ss   10:55   0:00 /init 
 +... 
 +</code> 
 +</WRAP>
  
-ション: +=== Process Monitor で WSL 2 の起動ロセを追ってみた === 
-    --distribution, -d <ディストリビュション名+コマンドプロンプより bash を起動すると以下のような流れで WSL 2 環境がロドされている。\\ 
-        指定したディストリビューションを実行します。+<WRAP prewrap 100%
 +<code> 
 +> bash <- cmd.exe より bash.exe (Microsoft Bash ラチャー) 起動
  
-    --user, -u <ユ+C:\WINDOWS\system32\conhost.exe 0x4 (コンソール ウィンドウ ホスト) 
-        指定したユとして実行します+C:\Windows\System32\bash.exe (Microsoft Bash ランチャー) 形式: PE32+ executable 
 +  +C:\WINDOWS\system32\wsl.exe /bin/bash --login (Microsoft Windows Subsystem for Linux ランチャ) をロド 
 +       +- C:\Windows\System32\lxss\LxssManagerProxyStub.dll (Lxss Manager ProxyStub DLL) 
 +        C:\WINDOWS\system32\vmcompute.exe (Hyper-V ホスト コンピューティング サービス) が起動される 
 +          +- C:\Windows\System32\lxss\tools\kernel 形式: ELF 64-bit LSB executable 
 +          +- C:\Windows\System32\lxss\tools\initrd.img 形式: ASCII cpio archive 
 +          +- C:\Windows\System32\vmwp.exe (仮想マシン ワーカー プロセス) をロード 
 +               +- %USERPROFILE%\AppData\Local\Packages\<distro>\LocalState\ext4.vhdx (distro の ext4) 
 +       |         +- C:\Windows\System32\lxss\tools\init 形式: ELF 64-bit LSB executable 
 +       +- C:\Windows\System32\lxss\wslhost.exe (Microsoft Windows Subsystem for Linux Background Host) 
 +            +- C:\Windows\System32\conhost.exe 0xffffffff -ForceV1 (コンソル ウィンドウ ホスト) 
 +C:\WINDOWS\system32\vmms.exe (仮想マシン管理サビス) 
 +</code> 
 +</WRAP> 
 +おおよそこのような流れのようである\\
  
-Windows Subsystem for Linux 管理するため引数:+==== genie-systemd の fork ==== 
 +[[#genie-systemd_の_fork|genie-systemd の fork]] 参照。\\ 
 +\\ 
 +コマンドプロンプトより起動方法は WSL2 に入って genie -s を実行すると以下ように systemd が PID 1 なる。\\ 
 +この状態で systemd に依存するものはすべて正常に使用できる。\\ 
 +<WRAP prewrap 100%> 
 +<code> 
 +> bash 
 +$ genie -s
  
-    --export <ディストリビューション名> <ファイル名> +$ ps aux 
-        ディストリビューションを tar ファイルにエクスポートします。 +USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND 
-        標準出力の場合は、ファイル名を にできます。+root          0.0  0.0 170712 11084 ?        Ss    9月15   0:00 /lib/systemd/systemd 
 +root        21  0.0  0.1  52848 16452 ?        Ss    9月15   0:00 /usr/lib/systemd/systemd-journald 
 +root        56  0.0  0.1 324844 19564 ?        Ssl   9月15   0:00 /usr/sbin/NetworkManager --no-daemon 
 +dbus        74  0.0  0.0 268584  3808 ?        Ss    9月15   0:00 /usr/bin/dbus-broker-launch --scope system --audit 
 +dbus        75  0.0  0.0   5332  2788 ?        S     9月15   0:00 dbus-broker --log 4 --controller 9 --machine-id 771a4 
 +root        80  0.0  0.0   2812  1864 tty1     Ss+   9月15   0:00 /sbin/agetty -o -p -- \u --noclear tty1 linux 
 +root        89  0.0  0.0  11996  6960 ?        Ss    9月15   0:00 /usr/sbin/sshd -D -oCiphers=aes256-gcm@openssh.com,ch 
 +root       556  0.0  0.0  18216  7952 ?        Ss   01:05   0:00 /usr/lib/systemd/systemd-logind 
 +root       621  0.0  0.0  12976  5864 pts/0    S    01:10   0:00 /sbin/runuser -l tomoyan -w INSIDE_GENIE,WSL_DISTRO_NAM 
 +tomoyan    623  0.0  0.0  19692  9548 ?        Ss   01:10   0:00 /usr/lib/systemd/systemd --user 
 +tomoyan    624  0.0  0.0 173932  2220 ?        S    01:10   0:00 (sd-pam) 
 +tomoyan    629  0.0  0.0   5260  3860 pts/0    S    01:10   0:00 -bash 
 +tomoyan    654  0.0  0.0   6916  3220 pts/0    R+   01:19   0:00 ps aux
  
-    --import <ディストリビューション名<インストール場所> <ファイル名+$ systemctl 
-        指定した tar ファイルを新しいディストリビューションとしてインポートします。 +  UNIT                        LOAD   ACTIVE     SUB       DESCRIPTION 
-        標準入力の場合は、ファイル名を にできます。+  proc-sys-fs-binfmt_misc.automount loaded active     running   Arbitrary Executabl> 
 +  dev-sdb.device              loaded activating tentative /dev/sdb 
 +  -.mount                     loaded active     mounted   / 
 +  dev-hugepages.mount         loaded active     mounted   Huge Pages File System 
 +  dev-mqueue.mount            loaded active     mounted   POSIX Message Queue File 
 +  etc-hostname.mount          loaded active     mounted   /etc/hostname 
 +  init.mount                  loaded active     mounted   /init 
 +  mnt-c.mount                 loaded active     mounted   /mnt/
 +  proc-sys-fs-binfmt_misc.mount loaded active     mounted   Arbitrary Executable Fi
 +  run-lock.mount              loaded active     mounted   /run/lock 
 +  run-shm.mount               loaded active     mounted   /run/shm 
 +  run-user-1000.mount         loaded active     mounted   /run/user/1000 
 +  run-user.mount              loaded active     mounted   /run/user 
 +  sys-fs-fuse-connections.mount loaded active     mounted   FUSE Control File Syste> 
 +  sys-kernel-debug.mount      loaded active     mounted   Kernel Debug File System 
 +  tmp.mount                   loaded active     mounted   Temporary Directory (/tmp 
 +</code> 
 +</WRAP>
  
-    --list, -l [Options] +==== genie-systemd (最初に試した時の資料です) ==== 
-        ディストリビューション一覧表示ます+[[https://github.com/arkane-systems/genie|arkane-systems/genie: A quick way into a systemd "bottle" for WSL]] を使用てみたいと思う\\ 
 +<WRAP prewrap 100%> 
 +<code> 
 +$ sudo dnf install git
  
-        オプション: +$ sudo dnf copr enable @dotnet-sig/dotnet
-            --all +
-                現在インストール中またはアンインストール中のものを含めて +
-                すべてのディストリビューションを一覧表示します。+
  
-            --running +You are about to enable a Copr repository. Please note that this 
-                現在実行中のディストリビューションのみを一覧表示します。+repository is not part of the main distribution, and quality may vary.
  
-    -setdefault, -s <ディストリビューション名+The Fedora Project does not exercise any power over the contents of 
-        ディストリビューションを既定として設定します。+this repository beyond the rules outlined in the Copr FAQ at 
 +<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>, 
 +and packages are not held to any quality or security level.
  
-    --terminate, -t <ディストリビューション名> +Please do not file bug reports about these packages in Fedora 
-        ディストリビューションを終了します。+Bugzilla. In case of problems, contact the owner of this repository.
  
-    --unregister <ディストリビューション名> +Do you really want to enable copr.fedorainfracloud.org/@dotnet-sig/dotnet? [y/N]: y 
-        ディストリビューションの登録を解除します。+Repository successfully enabled.
  
-    --upgrade <ディストリビューション名> +$ sudo curl -o /usr/bin/hostess -LO https://github.com/cbednarski/hostess/releases/download/ 
-        ディストリビューションを WslFs ファイル システム形式にアップグレードします。+v0.3.0/hostess_linux_amd64 
 +$ sudo chmod 755 /usr/bin/hostess
  
-    --help +$ sudo dnf install daemonize dotnet-runtime-2.2 dotnet-host-fxr-2.2 dotnet-sdk-2.2 
-        使用法を表示します。+ 
 +$ git clone https://github.com/arkane-systems/genie.git 
 +$ cd genie/genie 
 +$ dotnet publish -r linux-x64 --self-contained false 
 +Program.cs(75,50): error CS0121: The call is ambiguous between the following methods or properties: 'CommandHandler.Create<T>(Func<T, int>)' and 'CommandHandler.Create<T>(Func<T, Task<int>>)' [/mnt/c/Users/tomoyan/genie/genie/genie.csproj] 
 +Program.cs(80,52): error CS0121: The call is ambiguous between the following methods or properties: 'CommandHandler.Create<T>(Func<T, int>)' and 'CommandHandler.Create<T>(Func<T, Task<int>>)' [/mnt/c/Users/tomoyan/genie/genie/genie.csproj] 
 +Program.cs(87,47): error CS0121: The call is ambiguous between the following methods or properties: 'CommandHandler.Create<T>(Func<T, int>)' and 'CommandHandler.Create<T>(Func<T, Task<int>>)' [/mnt/c/Users/tomoyan/genie/genie/genie.csproj] 
 +Program.cs(99,46): error CS0121: The call is ambiguous between the following methods or properties: 'CommandHandler.Create<T1, T2>(Func<T1, T2, int>)' and 'CommandHandler.Create<T1, T2>(Func<T1, T2, Task<int>>)' [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 </code> </code>
 </WRAP> </WRAP>
  
 +.NET Core アプリのビルドを 9p ファイルシステム上でビルドすると破損した実行ファイルができるようだ。\\
 +1 回目のビルドは失敗する。(これは genie の不具合ではない)\\
 +<WRAP prewrap 100% #result>
 +<code>
 +$ pwd
 +/mnt/c/Users/tomoyan/genie
 +
 +$ cd genie
 +$ dotnet publish -r linux-x64 --self-contained false
 +Microsoft (R) Build Engine version 15.9.20.63311 for .NET Core
 +Copyright (C) Microsoft Corporation. All rights reserved.
 +
 +  Restoring packages for /mnt/c/Users/tomoyan/genie/genie/genie.csproj...
 +  Generating MSBuild file /mnt/c/Users/tomoyan/genie/genie/obj/genie.csproj.nuget.g.props.
 +  Generating MSBuild file /mnt/c/Users/tomoyan/genie/genie/obj/genie.csproj.nuget.g.targets.
 +  Restore completed in 306.02 ms for /mnt/c/Users/tomoyan/genie/genie/genie.csproj.
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018: The "EmbedAppNameInHost" task failed unexpectedly. [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018: System.IO.IOException: Invalid argument [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedView.CreateView(SafeMemoryMappedFileHandle memMappedFileHandle, MemoryMappedFileAccess access, Int64 requestedOffset, Int64 requestedSize) [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor(Int64 offset, Int64 size, MemoryMappedFileAccess access) [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor() [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at Microsoft.NET.Build.Tasks.AppHost.Create(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean overwriteExisting) [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at Microsoft.NET.Build.Tasks.EmbedAppNameInHost.ExecuteCore() [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +/usr/lib64/dotnet/sdk/2.2.109/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(308,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/mnt/c/Users/tomoyan/genie/genie/genie.csproj]
 +</code>
 +</WRAP>
 +
 +2 回目のビルドは成功する。\\
 +しかし、壊れた実行ファイルが出来上がっている。\\
 +<WRAP prewrap 100%>
 +<code>
 +$ dotnet publish -r linux-x64 --self-contained false
 +Microsoft (R) Build Engine version 15.9.20.63311 for .NET Core
 +Copyright (C) Microsoft Corporation. All rights reserved.
 +
 +  Restore completed in 75.31 ms for /mnt/c/Users/tomoyan/genie/genie/genie.csproj.
 +  genie -> /mnt/c/Users/tomoyan/genie/genie/bin/Debug/netcoreapp2.2/linux-x64/genie.dll
 +  genie -> /mnt/c/Users/tomoyan/genie/genie/bin/Debug/netcoreapp2.2/linux-x64/publish/
 +</code>
 +</WRAP>
 +
 +ビルドされた実行ファイルを起動すると以下のエラーが発生する。\\
 +<WRAP prewrap 100%>
 +<code>
 +$ genie/bin/Debug/netcoreapp2.2/linux-x64/publish/genie
 +This executable is not bound to a managed DLL to execute. The binding value is: 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'
 +A fatal error was encountered. This executable was not bound to load a managed DLL.
 +</code>
 +<code>
 +この実行可能ファイルは、実行するマネージDLLにバインドされていません。バインディング値は:
 +'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'
 +致命的なエラーが発生しました。この実行可能ファイルは、マネージDLLを読み込むようにバインドされていません。
 +</code>
 +</WRAP>
 +
 +これは 9p が共有メモリマップ I/O (MSBuild はそのような I/O をするようだ) をサポートできないファイルシステムだからのようである。\\
 +9p ファイルシステムは /mnt/c つまり Windows 10 の C:\ をマウントしている部分のことである。\\
 +<WRAP prewrap 100%>
 +<code>
 +$ pwd
 +/mnt/c/Users/tomoyan/genie
 +$ mount
 +...
 +C:\ on /mnt/c type 9p (rw,noatime,sync,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;metadata;uid=1000;gid=1000;umask=22;fmask=11;case=off;symlinkroot=/mnt/,access=client,msize=65536,trans=fd,rfd=8,wfd=8)
 +</code>
 +</WRAP>
 +※この問題は dotnet-sdk の問題に上がっているようだ。\\
 +[[https://github.com/dotnet/sdk/issues/2989|Error running self-contained Linux EXE: "This executable is not bound to a managed DLL to execute. The binding value is: 'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'" · Issue #2989 · dotnet/sdk]]\\
  
 ===== 参考文献 ===== ===== 参考文献 =====
  • windows/wsl.txt
  • 最終更新: 2024/02/04 13:41
  • by 非ログインユーザー