トラブルシューティング(Ubuntu 24.04LTS on WSL2, 2025年度版)

はじめに_

WSL2上のUbuntu 24.04 LTSに関するトラブルシューティング

仮想化支援技術が有効になっているかわからない_

  1. タスクマネージャーを起動する(スタート→Windowsシステムツール→タスクマネージャー)
  2. タスクマネージャーの「パフォーマンス」アイコン(下画像の赤枠部分)をクリックし、CPUの項を開く
  3. CPUの項で「仮想化」という項目を見る。「有効」となっていれば仮想化支援技術は有効になっている。
  4. 仮想化支援技術が有効でないときには、BIOS/UEFIの設定から仮想化支援技術を有効にする。自分が使っている型番名を調べ、Googleで「型番名 BIOS 設定」と調べる。ノートパソコンの場合は型番は底面に書かれている場合が多い。

Ubuntuのインストールに成功しているかを確認する。_

PowerShell上で以下のコマンドを入力し、Ubuntuが表示されているならばインストールに成功している。以下の例では、Ubuntuが表示されているのでインストールに成功している。

NAMEがインストールしたUbuntuのディストリビューション名、STATEというのは現在の状態、Runnningが稼働中、Stoppedが停止中。VERSIONはWSLのバージョン1と2のどちらでインストールされているかという情報。バージョン2になっていれば問題ない。標準ではバージョン2でインストールされている。

PowerShell 7.5.1
PS C:\Windows\System32> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-24.04    Running         2

WSL上にインストールしたLinuxのパスワードを忘れた_

以下を参考に対応する。

概要は以下のとおり。Ubuntu 24.04 上のユーザ hogehogeのパスワードを忘れたので変更する。

  1. Windows Powershellを管理者権限で起動する
    • 「スタート」→「Windows Powershell」に進む
    • Windows Powershellのアイコンにカーソルを合わせ、右クリックする。
    • 管理者として起動を選択する。
  2. 現在インストールされているLinuxの一覧を確認する。たとえば、私の環境では以下のようになる。
    wsl -l -v
      NAME            STATE           VERSION
    * Ubuntu-24.04    Stopped         2
    
  3. 上記コマンドのNAME欄を確認する。上記の例ではUbuntu-24.04が目的のLinux名となる。Ubuntu 24.04 にルート権限(管理者権限)でログインする。Powershell上で以下のコマンドを実行する。私の環境では以下のようなメッセージがでた。
    PS C:\Windows\System32> wsl -u root -d Ubuntu-24.04
    Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/pro
    
     System information as of 2025年  6月 16日 月曜日 21:35:19 JST
    
      System load:  0.04                Processes:             66
      Usage of /:   0.9% of 1006.85GB   Users logged in:       1
      Memory usage: 8%                  IPv4 address for eth0: 172.24.246.153
      Swap usage:   0%
    
     * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
       just raised the bar for easy, resilient and secure K8s cluster deployment.
    
       https://ubuntu.com/engage/secure-kubernetes-at-the-edge
    
    This message is shown once a day. To disable it please create the
    /root/.hushlogin file.
    root@PI-WIN11:/mnt/c/Windows/System32#
    
  4. 該当するユーザ(今回の例ではhogehoge)のパスワードを変更する。なお、Powershell上に表示される日本語メッセージは文字化けするので注意(Windows 11の日本語文字コードはCP932、Ubuntuの日本語文字コードはUTF-8のため)。そこで、表示メッセージを一時的に英語にして、パスワードの変更を行う。以下の例はユーザ名をgotohにしている。
    % export LANG=C
    % passwd hogehoge
    New password:  (ここに新しいパスワードを入力する。入力結果は表示されないので注意)
    Retype new password: (もう一度、同じパスワードを入力する)
    passwd: password updated successfully (このようなメッセージがでたらパスワードの変更は成功している)
    
  5. Ubuntuからログアウトする
    % exit
    

これでパスワードが変更できている。Powershell上でログインできるか確かめてみる(今回の例ではhogehoge)。変更したパスワードでログインできていれば成功している。ログインできない場合は、上をやり直す。

PS C:\Windows\System32> wsl -u hogehoge -d Ubuntu-24.04

Ubuntuの起動時のユーザがrootユーザになっている場合_

Ubuntuインストール後のユーザ設定時にうまくユーザアカウントを作成できていない場合に、Ubuntuがrootで起動してしまうとのこと。

参考

まず、現在のユーザを確認する。PowershellからUbuntuをrootユーザで起動する。Powershell上で以下のコマンドを実行する。

% wsl -u root -d Ubuntu-24.04

Ubuntuを起動したら、ターミナルでコマンドwhoamiを実行する。whoamiの実行結果がrootと表示されている場合は現在のユーザはrootである。

% whoami
root

ログイン用ユーザ(一般ユーザ)が作成されているかを確認する。ユーザ名がgotohの場合、以下のコマンドで確認する。以下のようにユーザ名を含む行が表示されていたら、ログイン用ユーザは作成済みとなっている。何も表示されないならば、一般ユーザは作成されていない。

# grep gotoh /etc/passwd
gotoh:x:1002:1002:,,,:/home/gotoh:/bin/bash

一般ユーザは作成されていない場合、以下の手順で作成する。この例ではユーザ名はgotohとする。Ubuntuのターミナル上で「adduser ユーザ名」を実行する。ユーザ名は半角英数字にすること(スペースは入れない)。部屋番号、職場電話番号、自宅電話番号、その他は何も入力せずEnterキーを押す。

# adduser gotoh
ユーザー `gotoh' を追加しています...
新しいグループ `gotoh' (1001) を追加しています...
新しいユーザー `gotoh' (1001) をグループ `gotoh' に追加しています...
ホームディレクトリ `/home/gotoh' を作成しています...
`/etc/skel' からファイルをコピーしています...
新しい パスワード: (注:キー入力しても何も表示されない)
新しい パスワードを再入力してください: (注:キー入力しても何も表示されない)
passwd: パスワードは正しく更新されました
gotoh のユーザ情報を変更中
新しい値を入力してください。標準設定値を使うならリターンを押してください
        フルネーム []: Yuichi Goto
        部屋番号 []:
        職場電話番号 []:
        自宅電話番号 []:
        その他 []:
以上で正しいですか? [Y/n] Y

これで一般ユーザが作成できた。続いて作成したユーザでsudoが使えるように設定する。以下のコマンドのgotohの部分を自分のユーザに変更すること。

% gpasswd -a gotoh sudo
Adding user gotoh to group sudo

ユーザが作成されているかを確認する。以下のようにユーザ名を含む行が表示されていたら、ユーザは作成済みとなっている。

# grep gotoh /etc/passwd
gotoh:x:1002:1002:,,,:/home/gotoh:/bin/bash

作成したユーザでUbuntuが起動するように設定する。以下のコマンドを実行し、/etc/wsl.conf に設定を記述する。なお、以下の例ではユーザ名をgotohとしている。 /etc/wsl.confに追記する。以下のコマンドを実行する。

# echo '[user]' | tee -a /etc/wsl.conf
# echo 'default=gotoh' | tee -a /etc/wsl.conf

catコマンドで内容が追記されているか確認する(最後の2行)。

#  cat /etc/wsl.conf
[boot]
systemd=true
[user]
default=gotoh

Ubuntuからログアウトする。

# exit

wslを停止する。

> wsl -t Ubuntu-24.04

Ubuntuにログインし、作成したユーザで起動できるか確認する。

> wsl -d Ubuntu-24.04
% whoami
gotoh

あるパッケージがインストールされているかどうか調べたい_

% apt list "パッケージ名/キーワード"

たとえば、mozcがインストールされているか調べたい場合は以下のように入力する。

% apt list "*mozc*"
一覧表示... 完了
emacs-mozc-bin/noble,now 2.28.4715.102+dfsg-2.2build7 amd64 [インストール済み、自動]
emacs-mozc/noble,now 2.28.4715.102+dfsg-2.2build7 amd64 [インストール済み]
fcitx-mozc-data/noble,now 2.28.4715.102+dfsg-2.2build7 all [インストール済み、自動]
fcitx-mozc/noble 2.28.4715.102+dfsg-2.2build7 amd64
fcitx5-mozc/noble,now 2.28.4715.102+dfsg-2.2build7 amd64 [インストール済み]
ibus-mozc/noble 2.28.4715.102+dfsg-2.2build7 amd64
mozc-data/noble,now 2.28.4715.102+dfsg-2.2build7 all [インストール済み、自動]
mozc-server/noble,now 2.28.4715.102+dfsg-2.2build7 amd64 [インストール済み、自動]
mozc-utils-gui/noble,now 2.28.4715.102+dfsg-2.2build7 amd64 [インストール済み、自動]
uim-mozc/noble 2.28.4715.102+dfsg-2.2build7 amd64

以下のコマンドでも調べられる。

% dpkg -l | grep パッケージ名/キーワード

% dpkg -l | grep mozc
ii  emacs-mozc                                     2.28.4715.102+dfsg-2.2build7             amd64        Mozc for Emacs
ii  emacs-mozc-bin                                 2.28.4715.102+dfsg-2.2build7             amd64        Helper module for emacs-mozc
ii  fcitx-mozc-data                                2.28.4715.102+dfsg-2.2build7             all          Mozc input method - data files for fcitx
ii  fcitx5-mozc:amd64                              2.28.4715.102+dfsg-2.2build7             amd64        Mozc engine for fcitx5 - Client of the Mozc input method
ii  mozc-data                                      2.28.4715.102+dfsg-2.2build7             all          Mozc input method - data files
ii  mozc-server                                    2.28.4715.102+dfsg-2.2build7             amd64        Server of the Mozc input method
ii  mozc-utils-gui                                 2.28.4715.102+dfsg-2.2build7             amd64        GUI utilities of the Mozc input method

半角全角キーを押すとシングルクォートが表示される_

キーボードレイアウト(キーボード配列)が英語配列になっているのが原因。2025年6月現在、WSL2はWindows側のキーボード配列を引き継いでいる。

Ubuntu上で以下のコマンドを実行してみる。以下のように「layout=jp」となっていれば日本語配列になっている。

% grep convert_rdp_keyboard_to_xkb_rule_names /mnt/wslg/weston.log
[17:57:15.315] convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=jp variant=(null) options=(null)

以下のように「layout=us」となっていれば英語配列になっている。

% grep convert_rdp_keyboard_to_xkb_rule_names /mnt/wslg/weston.log
[19:55:05.700] convert_rdp_keyboard_to_xkb_rule_names: matching model=pc105 layout=us variant=(null) options=(null)

キーボード配列

Windows側からemacsにコピー&ペーストできない_

Windows側アプリからemacsへのコピー&ペースト実施方法に従い、 Windows側アプリからemacsへのコピー&ペーストできない場合は以下を確かめる。

Waylandの設定がうまくできているか?_

GUIアプリケーションインストールの準備(Wayland)の部分の設定がうまくできていない可能性がある。

まず、xwaylandがインストール済みになっていることを確認する。インストール済みになっていなければインストールする。

apt list xwayland
一覧表示... 完了
xwayland/noble-updates,now 2:23.2.6-1ubuntu0.5 amd64 [インストール済み]
N: 追加バージョンが 2 件あります。表示するには '-a' スイッチを付けてください。

Waylandの設定が~/.profileに適切に設定できているか確認する。以下の例ではユーザ名 gotoh、gotohのユーザIDが1000の場合で実行している。各自の場合に合わせてユーザ名やユーザIDを変えること。

(注:uidがユーザID)
% id
uid=1000(gotoh) gid=1000(gotoh) groups=1000(gotoh),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),100(users)

(注:-lは小文字のエル)
% ls -l /mnt/wslg/runtime-dir/
合計 0
drwx------ 2 gotoh gotoh 80  6月 16 20:48 pulse
srwxrwxrwx 1 gotoh gotoh  0  6月 16 20:48 wayland-0  (このファイルがあることを確認する)
-rw-rw---- 1 gotoh gotoh  0  6月 16 20:48 wayland-0.lock

(注:-lは小文字のエル)
% ls -l /run/user/XXXX (XXXXはidで調べたユーザID)

(注:ユーザIDが1000の場合。以下のlsコマンドでファイルが2つ表示されていれば~/.profileは正しく設定されている)
% ls -l /run/user/1000/wayland*
lrwxrwxrwx 1 gotoh gotoh 31  6月 16 20:48 /run/user/1000/wayland-0 -> /mnt/wslg/runtime-dir/wayland-0
lrwxrwxrwx 1 gotoh gotoh 36  6月 16 20:48 /run/user/1000/wayland-0.lock -> /mnt/wslg/runtime-dir/wayland-0.lock

~/.profileが正しく設定されていないのであれば、以下の「~/.profileの内容が適切に設定されているか?」の記述に従い~/.profileを設定する。

~/.profileの内容が適切に設定されているか?_

2025年6月現在、後藤の環境の~/.profile は以下のようになっている。

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

# Create symbolic link for wayland server
find "/mnt/wslg/runtime-dir/" -name wayland* -exec basename {} \; | xargs -r -I {} ln -sf /mnt/wslg/runtime-dir/{} /run/user/$(id -u)/{}

# For FCITX5
while true; do
  dbus-update-activation-environment --systemd DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY 2> /dev/null && break
done

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
if [ $SHLVL = 1 ] ; then
  (fcitx5 --disable=wayland -d --verbose '*'=0 &)
fi

以下の手順で~/.profileを置き替える。

  1. 既存の~/.profileのバックアップをとっておく
    % cd
    % cp -p ~/.profile ~/dot.profile.org
    
  2. 後藤の~/.profileをダウンロードする。ダウンロードできているか確認する。
    % wget https://www.aise.ics.saitama-u.ac.jp/~gotoh/Download/dot.profile.gotoh-20250616
    % ls -1 *profile*
    
  3. 置き替える
    % cp ./dot.profile.gotoh-20250616 ~/.profile
    
  4. Ubuntuをログアウトする。
    % exit
    
  5. Ubuntuを起動する。

emacs-pgtk はインストールされているか?_

emacs-pgtkがインストールされているか確認する。インストール済みとでていればOK.

 apt list emacs-pgtk
一覧表示... 完了
emacs-pgtk/noble,now 1:29.3+1-1ubuntu2 amd64 [インストール済み]

wl-clipboardがインストールされているか確認する。インストール済みとでていればOK.

% apt list wl-clipboard
一覧表示... 完了
wl-clipboard/noble,now 2.2.1-1build1 amd64 [インストール済み]

どちらか一方がインストールされていなければ、Wayland対応emacs(emacs-pgtk)でWindowsからコピー&ペーストする設定(2025年5月16日追加)に従い、pgtkをインストールし、設定する。

戻る_