2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSLのシステムディストリビューションに入ってみる

2
Posted at

What's?

WSLについて見ていると、システムディストリビューションというものがあることに気づいたので少し見てみました。

環境

今回の環境はこちら。

PS > wsl --version
WSL バージョン: 3.0.1.0
カーネル バージョン: 6.18.40.1-1
WSLg バージョン: 1.0.79
MSRDC バージョン: 1.2.7214
Direct3D バージョン: 1.611.1-81528511
DXCore バージョン: 10.0.26100.1-240331-1435.ge-release
Windows バージョン: 10.0.26200.9457

WSLのシステムディストリビューション

WSLのシステムディストリビューションは、ドキュメントなどには見当たらないのですがヘルプに出てきます。

PS > wsl --help

こちらですね。

    --system
        システム ディストリビューションのシェルを起動します。

WSLディストリビューションがない状態では起動できません。

PS > wsl --system
Linux 用 Windows サブシステムにインストールされているディストリビューションはありません。
この問題を解決するには、以下の手順に従ってディストリビューションをインストールしてください:

'wsl.exe --list --online' を使用して利用可能な配布を一覧表示する
および 'wsl.exe --install <Distro>' を使用してインストールしてください。

システムディストリビューションが使えるようになるまで

というわけで、WSLディストリビューションを作成します。今回は2つほど。

PS > wsl --install Ubuntu-26.04

PS > wsl --install Ubuntu-24.04

できました。

PS > wsl --list
Linux 用 Windows サブシステム ディストリビューション:
Ubuntu-26.04 (既定値)
Ubuntu-24.04

この状態であれば、システムディストリビューションには入れるようです。

PS > wsl --system
wslg [ /mnt/c/Users/user ]$

ちなみに、この時はすべてのWSLディストリビューションが停止している時に実行したのですが、デフォルトになっているディストリビューションは起動するようです。

PS > wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-26.04    Running         2
  Ubuntu-24.04    Stopped         2

OSを再起動したりWSLを停止ししたりして試してみたのですが、wsl --systemを実行するとデフォルトのWSLディストリビューションは少なくとも起動するみたいですね。

PS > wsl --shutdown

システムディストリビューションの中身

システムディストリビューションの中身を見てみましょう。

Microsoft Azure Linuxのようです。

wslg [ ~ ]$ cat /etc/os-release
NAME="Microsoft Azure Linux"
VERSION="3.0.20260616"
ID=azurelinux
VERSION_ID="3.0"
PRETTY_NAME="Microsoft Azure Linux 3.0"
ANSI_COLOR="1;34"
HOME_URL="https://aka.ms/azurelinux"
BUG_REPORT_URL="https://aka.ms/azurelinux"
SUPPORT_URL="https://aka.ms/azurelinux"
wslg [ ~ ]$ cat /etc/azurelinux-release
Azure Linux 3.0
AZURELINUX_BUILD_NUMBER=3.0.20260616

カーネルはもちろんWSLのものと同じですね。

wslg [ ~ ]$ uname -srvmpio
Linux 6.18.40.1-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Fri Jul 31 22:12:15 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

起動しているプロセス。

wslg [ ~ ]$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   3760  2700 hvc0     Sl+  13:07   0:00 /init
root           2  0.1  0.0   3612  2564 hvc0     S+   13:07   0:00 /init
root           3  0.0  0.0   3760  1876 hvc0     Sl+  13:07   0:00 /init
root           4  0.0  0.0   3612  2096 hvc0     S+   13:07   0:00 init-watcher
root           9  0.0  0.1 123508  8520 hvc0     Sl+  13:07   0:00 /usr/bin/WSLGd
wslg          13  0.4  0.5 744060 33012 hvc0     Sl+  13:07   0:00 /usr/bin/weston --backend=rdp-backend.so --modules=wslgd-notify.so --xwayland --socket=wayland-0 --shell=rdprail
wslg          18  0.0  0.0   3628  2500 hvc0     S+   13:07   0:00 /init /mnt/c/Program Files/WSL/msrdc.exe msrdc.exe /wslg /silent /v:E2D568E1-EF82-4803-BE49-1E53D7A0AC1C /hvsock
wslg          19  0.0  0.0   8940  4108 hvc0     S+   13:07   0:00 /usr/bin/dbus-daemon --syslog --nofork --nopidfile --system
wslg          20  0.0  0.1 232940  8004 hvc0     Sl+  13:07   0:00 /usr/bin/pulseaudio --log-time=true --disallow-exit=true --exit-idle-time=-1 --load=module-rdp-sink sink_name=RD
wslg          24  0.0  0.0   8896  2340 ?        Ss   13:07   0:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 8 --print-address 10 --session
root          27  0.0  0.0   3760  2104 hvc0     Sl+  13:07   0:00 plan9 --control-socket 7 --log-level 4 --server-fd 8 --pipe-fd 10 --log-truncate
root          30  0.0  0.0   3768  1300 ?        Ss   13:07   0:00 /init
wslg          31  0.1  0.3  43852 19216 ?        Ss   13:07   0:00 /usr/bin/Xwayland :0 -rootless -core -listen 37 -wm 38 -terminate -nolisten local -ac
root          32  0.0  0.0   3836  1224 ?        S    13:07   0:00 /init
wslg          33  0.0  0.0   8692  5356 pts/0    Ss   13:07   0:00 -bash
wslg          76  0.0  0.0   4576  3244 pts/0    R+   13:10   0:00 ps aux

ここでWSLディストリビューションを起動してみます。

PS > wsl

システムディストリビューション側で、起動中のプロセスがとても増えました。

wslg [ ~ ]$ ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.0   3760  2700 hvc0     Sl+  13:07   0:00 /init
root           2  0.9  0.2  24224 15316 ?        Ss   13:07   0:02 /sbin/init
root           3  0.0  0.0   3760  2336 hvc0     Sl+  13:07   0:00 /init
root           4  0.0  0.0   3612  2096 hvc0     S+   13:07   0:00 init-watcher
root           9  0.0  0.1 123508  8520 hvc0     Sl+  13:07   0:00 /usr/bin/WSLGd
wslg          13  0.3  0.5 744060 33016 hvc0     Sl+  13:07   0:00 /usr/bin/weston --backend=rdp-backend.so --modules=wslgd-notify.so --xwayland --socket=wayland-0 --shell=rdprail
wslg          18  0.0  0.0   3628  2500 hvc0     S+   13:07   0:00 /init /mnt/c/Program Files/WSL/msrdc.exe msrdc.exe /wslg /silent /v:E2D568E1-EF82-4803-BE49-1E53D7A0AC1C /hvsock
wslg          19  0.0  0.0   8940  4108 hvc0     S+   13:07   0:00 /usr/bin/dbus-daemon --syslog --nofork --nopidfile --system
wslg          20  0.0  0.1 232940  8004 hvc0     Sl+  13:07   0:00 /usr/bin/pulseaudio --log-time=true --disallow-exit=true --exit-idle-time=-1 --load=module-rdp-sink sink_name=RD
wslg          24  0.0  0.0   8896  2340 ?        Ss   13:07   0:00 /usr/bin/dbus-daemon --syslog --fork --print-pid 8 --print-address 10 --session
root          27  0.0  0.0   3760  2104 hvc0     Sl+  13:07   0:00 plan9 --control-socket 7 --log-level 4 --server-fd 8 --pipe-fd 10 --log-truncate
root          30  0.0  0.0   3768  1300 ?        Ss   13:07   0:00 /init
wslg          31  0.0  0.3  43852 19216 ?        Ss   13:07   0:00 /usr/bin/Xwayland :0 -rootless -core -listen 37 -wm 38 -terminate -nolisten local -ac
root          32  0.0  0.0   3836  1224 ?        S    13:07   0:00 /init
wslg          33  0.0  0.0   8692  5356 pts/0    Ss   13:07   0:00 -bash
root         122  1.4  0.2  50412 18116 ?        S<s  13:11   0:00 /usr/lib/systemd/systemd-journald
989          160  0.2  0.2  22416 14464 ?        Ss   13:11   0:00 /usr/lib/systemd/systemd-resolved
root         165  1.2  0.1  34676 11912 ?        Ss   13:11   0:00 /usr/lib/systemd/systemd-udevd
root         216  0.0  0.0   2888  1952 ?        Ss   13:11   0:00 /bin/sh /usr/lib/systemd/scripts/chronyd-starter.sh -n -F 1
root         219  0.0  0.0   4472  3160 ?        Ss   13:11   0:00 /usr/sbin/cron -f -P
995          222  0.3  0.0   8820  5440 ?        Ss   13:11   0:00 @dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
root         229  0.9  0.4  44096 29784 ?        Ss   13:11   0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root         240  0.4  0.1  18436  9396 ?        Ss   13:11   0:00 /usr/lib/systemd/systemd-logind
root         254  0.4  0.2 1792300 15128 ?       Ssl  13:11   0:00 /usr/libexec/wsl-pro-service
100          256  0.3  0.0 220548  5928 ?        Ssl  13:11   0:00 /usr/sbin/rsyslogd -n -iNONE
root         269  0.0  0.0   5492  2736 tty1     Ss+  13:11   0:00 /usr/sbin/agetty --noreset --noclear --issue-file=/etc/issue:/etc/issue.d:/run/issue.d:/usr/lib/issue.d - linux
988          299  0.2  0.1  20424  6440 ?        S    13:11   0:00 /usr/sbin/chronyd -n -F 1 -x
root         300  1.6  0.5 123460 32724 ?        Ssl  13:11   0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
988          318  0.0  0.0  12096  2420 ?        S    13:11   0:00 /usr/sbin/chronyd -n -F 1 -x
root         396  0.0  0.0   3768  1304 ?        Ss   13:11   0:00 /init
root         397  0.0  0.0   3836  1228 ?        S    13:11   0:00 /init
wslg         398  0.0  0.0   6268  5544 pts/0    Ss+  13:11   0:00 -bash
root         399  0.0  0.0   8648  5604 ?        Ss   13:11   0:00 login -- user
wslg         430  0.3  0.2  22344 13552 ?        Ss   13:11   0:00 /usr/lib/systemd/systemd --user
wslg         432  0.0  0.0  22920  4088 ?        S    13:11   0:00 (sd-pam)
wslg         456  0.0  0.0   6136  5416 ?        Ss+  13:11   0:00 -bash
wslg         517  0.0  0.0   4576  3252 pts/0    R+   13:11   0:00 ps aux

ここでデフォルトディストリビューション側でコマンドを実行してみます。

$ bash -c 'sleep 60; echo "Ubuntu 26.04"'

これ、システムディストリビューション側から見えるんですよね。

wslg [ ~ ]$ ps aux | grep sleep
wslg         528  0.0  0.0   4948  3628 pts/0    S+   13:13   0:00 bash -c sleep 60; echo "Ubuntu 26.04"
wslg         529  0.0  0.1  16112  7868 pts/0    S+   13:13   0:00 sleep 60
wslg         533  0.0  0.0   3688  1912 pts/0    S+   13:13   0:00 grep --color=auto sleep

もうひとつWSLディストリビューションを起動してみます。

PS > wsl -d Ubuntu-24.04

併せてコマンド実行。

$ bash -c 'sleep 60; echo "Ubuntu 24.04"'

2つのディストリビューションで、同時に実行しているのですがデフォルトディストリビューションのものしか見えません。

wslg [ ~ ]$ ps aux | grep sleep
wslg         891  0.0  0.0   4948  3644 pts/0    S+   22:18   0:00 bash -c sleep 60; echo "Ubuntu 26.04"
wslg         892  0.0  0.1  16112  7852 pts/0    S+   22:18   0:00 sleep 60
wslg         902  0.0  0.0   3688  1800 pts/0    S+   22:18   0:00 grep --color=auto sleep

これを確認するには、システムディストリビューション側にもディストリビューション名を指定します。

PS > wsl --system -d Ubuntu-24.04

こちらではひとつ目のディストリビューションの実行コマンドは見えません。

wslg [ ~ ]$ ps aux | grep sleep
wslg         535  0.1  0.0   4760  3348 pts/0    S+   22:31   0:00 bash -c sleep 60; echo "Ubuntu 24.04"
wslg         536  0.0  0.0   3132  1908 pts/0    S+   22:31   0:00 sleep 60
wslg         540  0.0  0.0   3688  1792 pts/0    S+   22:31   0:00 grep --color=auto sleep

というわけで、システムディストリビューションは通常のディストリビューションのペアになるもののようです。

WSLg

システムディストリビューションに入るとwslgという名前がちらほら見えるので、WSLgの情報を見てみます。

この図がここまで見た情報を物語っていそうですね。

image.png

つまりWSLgはWaylandとRDPを使い、Windows側にWSL上でのGUIの実行結果を見せる仕組みのようです。

そしてシステムディストリビューションの情報も書いてありますね。

WSLg Architecture Overview / WSLg System Distro

ここまで見てきた情報も書かれていそうです。

  • The system distro is based on the Microsoft Azure Linux 3.0. This is a minimal Linux environment, just enough to run the various pieces of WSLg.
  • Every WSL 2 user distro is paired with its own instance of the system distro.
  • The system distro runs partially isolated from the user distro to which it is paired, in its own NS/PID/UTS namespace but shares other namespaces such as IPC, to allow for shared memory optimization across the boundary.

また予想通りですが、システムディストリビューションをユーザーが操作することは想定されていないようです。

While a user can get a terminal into the system distro, the system distro is not meant to be used directly by users.

ちょっとWSLに対する理解が進んだ気がしますね。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?