windows:wsl

Windows Subsystem for Linux 2 (WSL 2)

ソースコード: GitHub - microsoft/WSL2-Linux-Kernel: The source for the Linux kernel used in Windows Subsystem for Linux 2 (WSL2)
WSL 2 Terminal
 Windows Subsystem for Linux 2 (以下 WSL 2) は、2019/05/06 にブログ WSL2の発表|Windows コマンドラインで発表され、2019年6月末までに Windows Insider Program を通じて Microsoft が Windows で Linux カーネルを出荷する試みである。Windows 10 Insider Previews も参照のこと。
 Linux カーネルが Windows に同梱されるのは、今回が初である。(Microsoft は過去にも 2018 年に Microsoft Azure Sphere で Linux カーネル自体は出荷した事がある)

 WSL 2 は Microsoft がパッチを当てた Linux カーネル (初期ビルドでは Linux Kernel Version 4.19 ベース) を lightweight utility virtual machine (軽量ユーティリティ仮想マシン) (以下 VM) 内で実行する。この Linux カーネルは WSL 2 専用に構築された小型で軽量な WSL 2 Linux カーネルである。

 VM で実行する技術は KVMVMwareVirtualBoxXenHyper-VDocker… など今までもたくさんあったが、どれも起動が遅く、非常に隔離された環境に存在し、多くのコンピューターリソースを消費し、それを管理する時間が必要なものであった。それに比べて WSL 2 が他の VM と異なる点は以下の通りである。

  • Windows と Linux 間の高レベルの統合
  • 非常に高速な起動時間 (2 秒以内に機能する bash シェルにアクセスできる)
  • 小さなリソースフットプリント
  • そして何よりも VM の構成や管理が不要

 WSL は、Linux の ELF フォーマット形式のバイナリ実行ファイルを Windows でネイティブ実行できるようにするための互換レイヤーであるが、WSL 1 では一部で互換性の問題があったが、WSL 2 では Linux カーネルを Windows に内臓したことで完全なシステムコールの互換性を提供すると伴に、ファイルシステムのパフォーマンスが劇的に向上している。


WSL 2 で Fedora を利用するためのおすすめの方法は、LxRunOffline を利用してインストールする方法です。

Windows Subsystem for Linux (WSL) Version 2 のインストール
LxRunOffline - システムドライブ外に WSL 環境を構築する方法 (こちらの手順は最新化されています)
※WSL 2 + LxRunOffline で利用するなら、Fedora Remix を購入する必要はない。

Windows Subsystem for Linux (WSL) Version 1 のインストール(WSL 2 ではなく WSL 1 を導入する場合)

標準のインストールだと日本語が に文字化けする。
これはターミナルのフォントが日本語フォントになっていない為である。

$ 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'

ターミナルのフォントをMSゴシックなどの日本語フォントに変更する。

$ 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'

日本語ランゲージパックをインストールする。
sudo dnf install langpacks-ja を実行する。

$ 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!

WSL 2 の systemd 問題

システムロケール設定を ja_JP.UTF-8 に変更する。

$ 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
システムは、initd システム (PID 1) なので systemd として起動されていません。操作できません。
バスへの接続に失敗しました: ホストがダウンしています


本物の Fedora の PID 1 は /usr/lib/systemd/systemd であるが…

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.5 171732  5500 ?        Ss    9月05   2:13 /usr/lib/systemd/systemd --switched-root --system --deserialize 33
root         2  0.0  0.0      0     0 ?        S     9月05   0:00 [kthreadd]
...

現状の WSL 2 では PID 1 は Windows との相互運用に必要な処理を行う Microsoft 製のスタブであるカスタム /init であり、Linux の systemd ではない。

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0    888   560 ?        Sl   10:55   0:00 /init
root         6  0.0  0.0    896    80 ?        Ss   10:55   0:00 /init
...

現時点 (2019/09/16 現在) の WSL 2 では、systemd はサポートされていない。
https://github.com/microsoft/WSL/issues/1579
Systemd support for Windows Subsystem for Linux (WSL) · Issue #8036 · systemd/systemd · GitHub
今後 Microsoft によって systemd が有効化される可能性はあると思う。
Blockers for systemd? · Issue #994 · microsoft/WSLここで議論中。
しかし、Fedora は systemd を早くに採用した歴史があるので、systemd が使えないのはかなり致命的である。

nmcli も使えない… orz

$ nmcli con
Error: Could not create NMClient object: Could not connect: No such file or directory.

systemctl も使えない… orz

$ systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

localectl も使えない(日本語化できない)… orz

$ 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

genie-systemd の fork

本家: arkane-systems/genie
元ネタ: wsltub leftovers
ブログ: systemd on WSL2 | public class Random : Coding {

この fork は本家に取り込まれたので手順を修正した。
Merge pull request #25 from tomoyan596/master
Fedora Remix for WSL 用に arkane-systems/genie を fork して ./fedora-build を追加してみた。
tomoyan596/genie: A quick way into a systemd "bottle" for WSL

使い方は以下のようになる。

$ sudo dnf install git
$ cd ~
$ git clone https://github.com/arkane-systems/genie.git
$ cd genie
$ ./fedora-build

注意!!: cd ~dotnet core アプリ のビルドは 9p ファイルシステム上で行うと失敗するので必ず $HOME などの ext4 ファイルシステム 上で行う必要がある。
これで依存パッケージも genie もすべてインストールされる。

genie -s を実行して systemd を有効化する。

$ genie -s

この状態でシステムロケール設定が可能になる。

$ 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=

genie🧚‍♂️ 素晴らしい!!😍

getty@tty1.service の無効化

本家のドキュメント arkane-systems/genie にあるように、getty@tty1.service を無効にする。

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).
これを実行したら、systemctl を介して getty@tty1 サービスを無効にすることをお勧めします (WSL へのログオンと使用は tty ではなく ptsen で行われるため)。

getty@tty1.service を停止し無効化する。

$ 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.
毎回 genie -s を実行しなくても良い方法

WSL 2 を起動する度に systemd を有効化するのは手間である。
そこで以下のように bash 起動時に自動で有効化することが出来る。(お好みで…)

$ sudo vi /etc/profile.d/genie.sh

systemdPID 1 で起動していない場合は genie -s を実行する。

/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

Fedora minimal インストール - 基本的なコマンドのインストール を参考に基本的なコマンドをインストールする。

キャッシュのキープ

お好みで以下の設定を行っておくと RPM パッケージがキャッシュされるようになる。

$ sudo vi /etc/dnf/dnf.conf
/etc/dnf/dnf.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=true
keepcache=1 <- 追記する。

ダウンロード済の場合は [SKIPPED] になる。

$ 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
...
完了しました!

パッケージのインストール

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 キーを押すと使用方法が表示される。
tmux on wsl

$ sudo dnf install tmux htop


netstat arp ifconfig route … など

$ sudo dnf install net-tools -y

dig host nslookup nsupdate

$ sudo dnf install bind-utils -y

whois

$ sudo dnf install jwhois -y

lspci

$ sudo dnf install pciutils -y

2020/09/06 追記: 2020/05/19 に WSL が GPU コンピューティングをサポートすることを発表した。
The Windows Subsystem for Linux BUILD 2020 Summary | Windows Command Line
/proc/bus/pci が存在するようになった。

$ ll /proc/bus/pci
合計 0
dr-xr-xr-x 2 root root 0  9月  6 17:38 8285:00
dr-xr-xr-x 2 root root 0  9月  6 17:38 9fd9:00
dr-xr-xr-x 2 root root 0  9月  6 17:38 a1ef:00
dr-xr-xr-x 2 root root 0  9月  6 17:38 aa29:00
-r--r--r-- 1 root root 0  9月  6 17:38 devices

lspci - これは以下の理由により入れても使えない。
<code> $ cat /proc/bus/pci cat: /proc/bus/pci: そのようなファイルやディレクトリはありません </code>

lsusb

$ sudo dnf install usbutils -y

lsmod depmod insmod rmmod modinfo modprobe

$ sudo dnf install kmod -y

mkpasswd … など

$ sudo dnf install expect -y

rsync

$ sudo dnf install rsync -y

man

$ sudo dnf install man -y

WSL 2 のファイルシステムへのアクセスは PowerShell で \\wsl$\<distro> の形式で行うことができる。
これは Plan 9 Network Provider (9p と省略) を利用して提供されるネットワーク共有である。
※ 9p はもともと Plan 9 from Bell Labs(研究用分散OS) 用に開発されたファイル共有プロトコルである。

PS > wsl -l
Windows Subsystem for Linux ディストリビューション:
fedoraremix (既定)
PS > cd \\wsl$\fedoraremix
PS Microsoft.PowerShell.Core\FileSystem::\\wsl$\fedoraremix> explorer.exe .

PowerShell で explorer.exe . コマンドを実行するとエクスプローラーが開く。
WSL Linux FS Access

コマンドプロンプトからは一旦ネットワークドライブの割り当てを行う必要がある。

> pushd \\wsl$\fedoraremix
Z:\> explorer.exe .

pushd は Z: X: Y: と空いているドライブを自動割り当てしてくれる。

または net use コマンドでドライブ割り当てする。

> net use x: \\wsl$\fedoraremix /persistent:yes
コマンドは正常に終了しました。
> x:
X:¥> explorer.exe .

割り当て解除は net use x: /delete で行う。

WSL 1 のディスクイメージの場所

wsl –set-version <distro> 1 で変換処理を行うと、rootfs フォルダーにディスクイメージが存在する。

%LOCALAPPDATA%\Packages\<distro identifier>\LocalState\rootfs\

WSL2 のディスクイメージの場所

wsl –set-version <distro> 2 で変換処理を行うと、ext4.vhdx にディスクイメージが存在する。

%LOCALAPPDATA%\Packages\<distro identifier>\LocalState\ext4.vhdx

ローカルファイルリンク有効化 - Chrome プラグイン

例:

{{ url }}

リンク編集:

その他参考文献

.NET Core を Fedora にインストールする方法は、以下を参照のこと。
Fedora Copr リポジトリ - .NET Core

Cloud9 SDK を元にインストールしてみる。
Cloud9 SDK on WSL2

Fedora 30 → 31

$ cat /etc/redhat-release
Generic release 30 (Generic)
$ sudo dnf upgrade --refresh
$ sudo dnf install dnf-plugin-system-upgrade
$ sudo dnf system-upgrade --allowerasing --skip-broken download --releasever=31
$ sudo dnf system-upgrade reboot

参考文献

WSL 2 に接続できない場合

System has not been booted with systemd as init system (PID 1). が発生する

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to create bus connection: Host is down
システムは、initd システム (PID 1) なので systemd として起動されていません。操作できません。
バスへの接続に失敗しました: ホストがダウンしています


現時点の WSL 2 では、systemd はサポートされていない。
Systemd support for Windows Subsystem for Linux (WSL) · Issue #8036 · systemd/systemd · GitHub

本物の Fedora の PID 1 は /usr/lib/systemd/systemd であるが…

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.5 171732  5500 ?        Ss    9月05   2:13 /usr/lib/systemd/systemd --switched-root --system --deserialize 33
root         2  0.0  0.0      0     0 ?        S     9月05   0:00 [kthreadd]
...

現状の WSL 2 では PID 1 は /init である。

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0    888   560 ?        Sl   10:55   0:00 /init
root         6  0.0  0.0    896    80 ?        Ss   10:55   0:00 /init
...
Process Monitor で WSL 2 の起動プロセスを追ってみた

コマンドプロンプトより bash を起動すると以下のような流れで WSL 2 環境がロードされている。

> bash <- cmd.exe より bash.exe (Microsoft Bash ランチャー) を起動

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 (仮想マシン管理サービス)

おおよそこのような流れのようである。

genie-systemd の fork

genie-systemd の fork を参照。

コマンドプロンプトより起動方法は WSL2 に入って genie -s を実行すると以下のように systemd が PID 1 なる。
この状態で systemd に依存するものはすべて正常に使用できる。

> bash
$ genie -s

$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  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

genie-systemd (最初に試した時の資料です)

arkane-systems/genie: A quick way into a systemd "bottle" for WSL を使用してみたいと思う。

$ 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]

.NET Core アプリのビルドを 9p ファイルシステム上でビルドすると破損した実行ファイルができるようだ。
1 回目のビルドは失敗する。(これは genie の不具合ではない)

$ 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]

2 回目のビルドは成功する。
しかし、壊れた実行ファイルが出来上がっている。

$ 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/

ビルドされた実行ファイルを起動すると以下のエラーが発生する。

$ 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.
この実行可能ファイルは、実行するマネージDLLにバインドされていません。バインディング値は:
'c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2'
致命的なエラーが発生しました。この実行可能ファイルは、マネージDLLを読み込むようにバインドされていません。

これは 9p が共有メモリマップ I/O (MSBuild はそのような I/O をするようだ) をサポートできないファイルシステムだからのようである。
9p ファイルシステムは /mnt/c つまり Windows 10 の C:\ をマウントしている部分のことである。

$ 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)

※この問題は dotnet-sdk の問題に上がっているようだ。
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 非ログインユーザー