Windows11のWSL設定続き(主にWSLgとFcitx5・Mozcによる日本語入力)

Posted by 雅楽斎 on Saturday, March 4, 2023

TOC

前の記事の続きです。

まっさらなWindows11でWSLをセットアップ

現状確認

>wsl --version
WSL バージョン: 1.0.3.0
カーネル バージョン: 5.15.79.1
WSLg バージョン: 1.0.47
MSRDC バージョン: 1.2.3575
Direct3D バージョン: 1.606.4
DXCore バージョン: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windowsバージョン: 10.0.22621.1265
>wsl --status
既定のディストリビューション: Ubuntu-22.04
既定のバージョン: 2
WSL1 は、現在のマシン構成ではサポートされていません。
WSL1 を使用するには、"Linux 用 Windows サブシステム" オプション コンポーネントを有効にしてください。

Systemdを有効にする

状況確認。

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

/etc/wsl.confを作成します。

[boot]
systemd = true

ログインしているWSL2ディストロから抜けて、コマンドプロンプトからWSLを終了します。

>wsl --shutdown

WSLにログインしてSystemdが動いていることを確認します。

$ systemctl status cron.service
● cron.service - Regular background program processing daemon
     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: >
     Active: active (running) since Thu 2023-03-03 17:40:40 JST; 26s ago
       Docs: man:cron(8)
   Main PID: 125 (cron)
      Tasks: 1 (limit: 11829)
     Memory: 424.0K
     CGroup: /system.slice/cron.service
             └─125 /usr/sbin/cron -f -P

Mar 03 17:40:40 DESKTOP-HKJE9NK systemd[1]: Started Regular background program >
Mar 03 17:40:40 DESKTOP-HKJE9NK cron[125]: (CRON) INFO (pidfile fd = 3)
Mar 03 17:40:40 DESKTOP-HKJE9NK cron[125]: (CRON) INFO (Running @reboot jobs)

SSHdのインストール

# apt-get install ssh

パスワード認証を有効にします(公開鍵/秘密鍵の管理が面倒なので…)

# diff -u /etc/ssh/sshd_config{.org,}
@@ -54,7 +54,7 @@
 #IgnoreRhosts yes

 # To disable tunneled clear text passwords, change to no here!
-#PasswordAuthentication yes
+PasswordAuthentication yes
 #PermitEmptyPasswords no

 # Change to yes to enable challenge-response passwords (beware issues with

sshdを再起動して、接続確認します。1

# systemctl restart sshd.service
$ ssh 0
The authenticity of host '0.0.0.0 (0.0.0.0)' can't be established.
ED25519 key fingerprint is SHA256:OLNu8Fw+99sqKVsc9LzguUytUCyfDV4pfRkgQGTRK+k.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '0.0.0.0' (ED25519) to the list of known hosts.
hogehoge@0.0.0.0's password:

便利ユーティリティの詰め合わせメタパッケージをインストール

# apt-get install wslu

ロケールを設定

現状確認。

$ localectl
   System Locale: LANG=C.UTF-8
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105
# apt-get install language-pack-ja
# localectl set-locale LANG=ja_JP.UTF-8
$ localectl
   System Locale: LANG=ja_JP.UTF-8
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105

VLゴシック他をインストール

このタイミングでやらないと後の設定でイライラするので。なお、大半のスクリーンショットはこの設定の前にやったのでデフォルトフォントでお送りします。

# apt-get install fonts-vlgothic fonts-motoya-l-cedar fonts-motoya-l-maruberi

/etc/fonts/local.confを作成します。

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="pattern">
    <test name="lang" compare="contains">
      <string>ja</string>
    </test>
    <test qual="any" name="family">
      <string>sans-serif</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>VL Pゴシック</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang" compare="contains">
      <string>ja</string>
    </test>
    <test qual="any" name="family">
      <string>monospace</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>VL ゴシック</string>
    </edit>
  </match>
</fontconfig>

ログインしているWSL2ディストロから抜けて、コマンドプロンプトからWSLを終了します。次にターミナルを開いたタイミングで反映されます。

>wsl --shutdown

GUIアプリをインストール

GUIアプリをインストールしてWSLgの動作確認をします。

# apt-get install x11-apps nautilus

xeyesを実行してGUIアプリが起動することを確認。

日本語入力関連

ひとまずWSLgのGUIアプリで日本語を入力できるようにはなりましたが、変換候補ウィンドウが表示できないという状況です。

im-configパッケージをインストール

# apt-get install im-config
$ im-config -l
 xim

一旦無印Fcitx4をインストール

# apt-get install fcitx fcitx-mozc fcitx-frontend-all
$ im-config -l
 fcitx xim

この状態でfcitx-config-gtk3を実行しても入力メソッドが表示されません。

daemonizeをインストール

本当はsystemdでやった方がメンテナンス性が高いので、後々変更する可能性があります。

# apt-get install daemonize

~/.bash_profileに無印Fcitxを起動する行と環境変数を記述。

daemonize -e /tmp/dbus-${USER}.log -o /tmp/dbus-${USER}.log -p /tmp/dbus-${USER}.pid -l /tmp/dbus-${USER}.pid -a /usr/bin/dbus-daemon --address="unix:path=$XDG_RUNTIME_DIR/bus" --session --nofork  >>/dev/null 2>&1
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
daemonize -e /tmp/fcitx.log -o /tmp/fcitx.log -p /tmp/fcitx.pid -l /tmp/fcitx.pid -a /usr/bin/fcitx
export INPUT_METHOD=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

ログインしているWSL2ディストロから抜けて、コマンドプロンプトからWSLを終了します。

>wsl --shutdown

次にターミナルを開いたタイミングで反映されますが、ターミナルを開くと重複起動を示す行が出力されるので、2回は呼ばれてるのが無駄感ありますが先に進みます。

Can't lock the lock file "/tmp/fcitx.pid". Is another instance running?

Fcitx無印を設定

$ fcitx-config-gtk3

Fcitx5をインストールしてFcitx無印から移行

Ubuntuに入っているFcitx5は古いので、追加したPPAからfcitx5をインストールします。ここでfcitx無印は競合パッケージとして削除されます。

詳細は以下の記事で。

富士通LIFEBOOK S938/SにUbuntu MATE 22.04をインストールした後の諸設定)

# add-apt-repository ppa:ikuya-fruitsbasket/fcitx5
# apt-get install fcitx5=5.0.21-2ubuntu1~jammy1 fcitx5-mozc mozc-data mozc-server mozc-utils-gui
$ im-config -n fcitx5

Fcitx5を設定

Fcitx5の起動設定

無印用に設定した~/.bash_profileのfcitxをfcitx5に書き換えます。全体はこちら。

daemonize -e /tmp/dbus-${USER}.log -o /tmp/dbus-${USER}.log -p /tmp/dbus-${USER}.pid -l /tmp/dbus-${USER}.pid -a /usr/bin/dbus-daemon --address="unix:path=$XDG_RUNTIME_DIR/bus" --session --nofork  >>/dev/null 2>&1
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
daemonize -e /tmp/fcitx5.log -o /tmp/fcitx5.log -p /tmp/fcitx5.pid -l /tmp/fcitx5.pid -a /usr/bin/fcitx5 --disable=wayland
export INPUT_METHOD=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx

ログインしているWSL2ディストロから抜けて、コマンドプロンプトからWSLを終了します。

>wsl --shutdown

次にターミナルを開いたタイミングで、やっぱり2回実行されているようでターミナルに表示されますが先に進みます。

Can't lock the lock file "/tmp/fcitx5.pid". Is another instance running?

Fcitx5移行ウィザードを実行

Fcitx5移行ウィザードを実行します。

$ /usr/bin/fcitx5-migrator

Fcitx無印で設定したものが表示されるので、グローバル設定にチェックを入れて先に進みます。

Fcitx5の設定

Fcitx5の設定をします。

$ /usr/bin/fcitx5-configtool

現在の入力メソッドにMozcがない場合は有効な入力メソッドから追加します。

グローバルオプションタブで必要な設定をします。個人的には入力メソッドの切り替えからControl+スペースの削除と一時的に第1入力メソッドに切り替えるの左Shiftを削除しています。

Mozcの設定

変換対象の選択はシフトを押さずに矢印でやる主義なので、Mozcのキーバインドを変更します。

$ /usr/lib/mozc/mozc_tool --mode=config_dialog

キー設定の選択をMS-IMEからATOKに変更します。

この作業の途中でフォントをVLゴシックに変えたので、最後だけフォントが変わってしまっています。

設定はできたが、変換候補ウィンドウが表示されない

Fcitx5とMozcを使ってWSLg上で日本語入力ができるようにはなりましたが、結果として変換キーを押した時に変換候補ウィンドウが表示されません。残念。

デフォルトフォントとVLゴシックの違い

本稿ではかなり最初の方でUIをVLゴシックに変えるようにしていますが、実際には作業の途中で変更したので、どのくらい変わるのかスクショでおさらい。

daemonize使わずにsystemdでやりたい・・・

スポンサーリンク


  1. 「ssh 0」の0はIPv4アドレスの0.0.0.0の32ビット符号なし表現で、0.0.0.0→IN_ADDR_ANY→(一般的な場合)127.0.0.1と解釈されて、loインタフェースが生きていれば自端末に接続します。IPv6の場合は「::」や「::0」で同様のことができて、プロトコルが有効かどうかを確認可能です。 [return]

comments powered by Disqus