windows:wsl

差分

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

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
次のリビジョン両方とも次のリビジョン
windows:wsl [2019/09/13 23:34] ともやんwindows:wsl [2019/09/17 08:18] – [パッケージのインストール] ともやん
行 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]] も参照のこと。\\
行 26: 行 27:
 ===== インストール ===== ===== インストール =====
 [[.:wsl:install|WSL 2 のインストール]]\\ [[.:wsl:install|WSL 2 のインストール]]\\
 +
 +===== 日本語環境に設定 =====
 +標準のインストールだと日本語が **□** に文字化けする。\\
 +これはターミナルのフォントが日本語フォントになっていない為である。\\
 +<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>
 +\\
 +本物の 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>
 +
 +現時点 (2019/09/16 現在) の WSL 2 では、**systemd** はサポートされていない。\\
 +[[https://github.com/systemd/systemd/issues/8036|Systemd support for Windows Subsystem for Linux (WSL) · Issue #8036 · systemd/systemd · GitHub]]\\
 +今後 Microsoft によって systemd が有効化される可能性はあると思う。\\
 +しかし、Fedora は **systemd** を早くに採用した歴史があるので、**systemd** が使えないのはかなり致命的である。\\
 +\\
 +**nmcli** も使えない... orz\\ 
 +<code>
 +$ nmcli con
 +Error: Could not create NMClient object: Could not connect: No such file or directory.
 +</code>
 +
 +**systemctl** も使えない... orz\\ 
 +<code>
 +$ systemctl
 +System has not been booted with systemd as init system (PID 1). Can't operate.
 +Failed to connect to bus: Host is down
 +</code>
 +
 +**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>
 +
 +==== genie-systemd の fork ====
 +本家: [[https://github.com/arkane-systems/genie|arkane-systems/genie]]\\
 +\\
 +この 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>
 +$ sudo localectl set-locale LANG=ja_JP.UTF-8
 +$ source /etc/locale.conf
 +$ locale
 +LANG=ja_JP.UTF-8
 +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>\\
 +
 +=== getty@tty1.service の無効化 ===
 +本家のドキュメント [[https://github.com/arkane-systems/genie|arkane-systems/genie]] にあるように、**getty@tty1.service** を無効にする。\\
 +<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>
 +これを実行したら、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
 +
 + 9月 16 08:11:54 Cmon-wsl systemd[1]: Started Getty on tty1.
 + 9月 16 08:45:09 Cmon-wsl systemd[1]: Stopping Getty on tty1...
 + 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>
 +</WRAP>
 +
 +=== 毎回 genie -s を実行しなくても良い方法 ===
 +WSL 2 を起動する度に systemd を有効化するのは手間である。\\
 +そこで以下のように bash 起動時に自動で有効化することが出来る。(お好みで...)\\
 +<code>
 +$ sudo vi /etc/profile.d/genie.sh
 +</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://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 インストール - 基本的なコマンドのインストール]] を参考に基本的なコマンドをインストールする。\\
 +
 +==== キャッシュのキープ ====
 +お好みで以下の設定を行っておくと 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>
 +
 +ダウンロード済の場合は **[SKIPPED]** になる。\\
 +<code>
 +$ sudo dnf install usbutils -y
 +...
 +パッケージのダウンロード:
 +[SKIPPED] hwdata-0.327-1.fc30.noarch.rpm: Already downloaded
 +[SKIPPED] usbutils-012-2.fc30.x86_64.rpm: Already downloaded
 +...
 +完了しました!
 +</code>
 +
 +==== パッケージのインストール ====
 +**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>
 +\\
 +**netstat arp ifconfig route** … など\\
 +<code>
 +$ sudo dnf install net-tools -y
 +</code>
 +
 +**dig host nslookup nsupdate**\\
 +<code>
 +$ sudo dnf install bind-utils -y
 +</code>
 +
 +**whois**\\
 +<code>
 +$ sudo dnf install jwhois -y
 +</code>
 +
 +**lspci - これは以下の理由により入れても使えない。**\\
 +<code>
 +$ cat /proc/bus/pci
 +cat: /proc/bus/pci: そのようなファイルやディレクトリはありません
 +</code>
 +
 +**lsusb**\\
 +<code>
 +$ sudo dnf install usbutils -y
 +</code>
 +
 +**lsmod depmod insmod rmmod modinfo modprobe**\\
 +<code>
 +$ sudo dnf install kmod -y
 +</code>
 +
 +**mkpasswd** … など\\
 +<code>
 +$ sudo dnf install expect -y
 +</code>
 +
 +**rsync**\\
 +<code>
 +$ sudo dnf install rsync -y
 +</code>
 +
 +===== WSL 2 ファイルシステムへのアクセス =====
 +WSL 2 のファイルシステムへのアクセスは PowerShell で **\\wsl$\<distro>** の形式で行うことができる。\\
 +これは 9p ファイルシステムを利用して提供されるネットワーク共有である。\\
 +<code>
 +PS > wsl -l
 +Windows Subsystem for Linux ディストリビューション:
 +fedoraremix (既定)
 +PS > cd \\wsl$\fedoraremix
 +PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\fedoraremix> explorer.exe .
 +</code>
 +PowerShell で **explorer.exe .** コマンドを実行するとエクスプローラーが開く。\\
 +{{:windows:wsl_linux_fs_access.png?640|WSL Linux FS Access}}\\
 +
 +===== Cloud9 SDK =====
 +[[javascript:cloud9_sdk|Cloud9 SDK]] を元にインストールしてみる。\\
 +
 +==== Node.js のインストール ====
 +nodebrew をインストールする。
 +<code>
 +$ curl -kL git.io/nodebrew | perl - setup
 +  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 +                                 Dload  Upload   Total   Spent    Left  Speed
 +  0        0        0          0      0 --:--:-- --:--:-- --:--:--     0
 +  0        0        0          0      0 --:--:--  0:00:02 --:--:--     0
 +  0        0        0          0      0 --:--:--  0:00:03 --:--:--     0
 +100 24634  100 24634    0       5131      0  0:00:04  0:00:04 --:--:-- 30041
 +Fetching nodebrew...
 +Installed nodebrew in $HOME/.nodebrew
 +
 +========================================
 +Export a path to nodebrew:
 +
 +export PATH=$HOME/.nodebrew/current/bin:$PATH
 +========================================
 +</code>
 +
 +指示にしたがってパスを設定する。
 +<code>
 +$ vi ~/.bashrc
 +</code>
 +<code>
 +# User specific aliases and functions
 +export PATH=$HOME/.nodebrew/current/bin:$PATH
 +</code>
 +<code>
 +$ source ~/.bashrc
 +</code>
 +
 +**node.js バイナリをインストール**\\
 +インストール可能なバージョンを調べる。
 +<code>
 +$ nodebrew ls-remote
 +〜省略〜
 +v12.7.0   v12.8.0   v12.8.1   v12.9.0   v12.9.1   v12.10.0    
 +〜省略〜
 +</code>
 +
 +バージョンを指定してバイナリをインストールする。
 +<WRAP prewrap 100%>
 +<code>
 +$ nodebrew install-binary v12.10.0
 +Fetching: https://nodejs.org/dist/v12.10.0/node-v12.10.0-linux-x64.tar.gz
 +######################################################################### 100.0%
 +Installed successfully
 +</code>
 +</WRAP>
 +
 +利用するバージョンを指定する。
 +<code>
 +$ nodebrew use v12.10.0
 +use v12.10.0
 +</code>
 +
 +動作確認を行う。
 +<code>
 +$ nodebrew use v12.10.0
 +use v12.10.0
 +$ node -v
 +v12.10.0
 +</code>
 +
 +==== その他依存パッケージのインストール ====
 +<code>
 +$ sudo dnf install python2 gcc
 +</code>
 +
 +==== Cloud9 SDK のインストール ====
 +github より Cloud9 SDK をダウンロードする。\\
 +<code>
 +$ git clone https://github.com/c9/core.git c9sdk
 +</code>
 +
 +Cloud9 SDK をビルドする。\\
 +<code>
 +$ cd c9sdk
 +$ ./scripts/install-sdk.sh
 +</code>
 +
 +Cloud9 SDK を実行する。\\
 +<code>
 +$ node server.js -p 8080 -a :
 +</code>
 +[[http://localhost:8080|]] にアクセスする。\\
 +WSL 2 では localhost 問題も解決しており http://localhost:8080 で Windows 10 から WSL 2 内の Cloud9 にアクセスできる。\\
 +{{:windows:wsl_c9sdk.png?640|Cloud9 SDK on WSL2}}\\
 +
 +===== トラブルシューティング =====
 +
 +==== System has not been booted with systemd as init system (PID 1). が発生する ====
 +<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 の起動プロセスを追ってみた ===
 +コマンドプロンプトより bash を起動すると以下のような流れで WSL 2 環境がロードされている。\\
 +<WRAP prewrap 100%>
 +<code>
 +> bash <- cmd.exe より bash.exe (Microsoft Bash ランチャー) を起動
 +
 +C:\WINDOWS\system32\conhost.exe 0x4 (コンソール ウィンドウ ホスト)
 +C:\Windows\System32\bash.exe (Microsoft Bash ランチャー)
 +  +- 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
 +          +- C:\Windows\System32\lxss\tools\initrd.img
 +          +- C:\Windows\System32\vmwp.exe (仮想マシン ワーカー プロセス) をロード
 +               +- %USERPROFILE%\AppData\Local\Packages\<distro>\LocalState\ext4.vhdx (distro の ext4)
 +               +- C:\Windows\System32\lxss\tools\init
 +       +- 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>
 +おおよそこのような流れのようである。\\
 +
 +==== genie-systemd の fork ====
 +[[#genie-systemd_の_fork|genie-systemd の fork]] を参照。\\
 +\\
 +コマンドプロンプトより起動方法は WSL2 に入って genie -s を実行すると以下のように systemd が PID 1 なる。\\
 +この状態で systemd に依存するものはすべて正常に使用できる。\\
 +<WRAP prewrap 100%>
 +<code>
 +> bash
 +$ genie -s
 +
 +$ ps aux
 +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
 +
 +$ systemctl
 +  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/c
 +  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>
 +
 +==== 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
 +
 +You are about to enable a Copr repository. Please note that this
 +repository is not part of the main distribution, and quality may vary.
 +
 +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.
 +
 +Please do not file bug reports about these packages in Fedora
 +Bugzilla. In case of problems, contact the owner of this repository.
 +
 +Do you really want to enable copr.fedorainfracloud.org/@dotnet-sig/dotnet? [y/N]: y
 +Repository successfully enabled.
 +
 +$ sudo curl -o /usr/bin/hostess -LO https://github.com/cbednarski/hostess/releases/download/
 +v0.3.0/hostess_linux_amd64
 +$ sudo chmod 755 /usr/bin/hostess
 +
 +$ 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>
 +</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 非ログインユーザー