ラベル WSL の投稿を表示しています。 すべての投稿を表示
ラベル WSL の投稿を表示しています。 すべての投稿を表示

2024年7月18日木曜日

WSL2 の Ubuntu 24.04 環境を整える

やること

今使っている WSL2 のディストリビューションがまだ Ubuntu 22.04 だったので、 24.04 に切り替え、初期設定を行う。

インストール

WSL のアップデート

> wsl --update
更新プログラムを確認しています。
Linux 用 Windows サブシステムの最新バージョンは既にインストールされています。

インストール可能なディストリビューションの確認

> wsl --list --online
インストールできる有効なディストリビューションの一覧を次に示します。
'wsl.exe --install <Distro>' を使用してインストールします。

NAME                                   FRIENDLY NAME
Ubuntu                                 Ubuntu
Debian                                 Debian GNU/Linux
kali-linux                             Kali Linux Rolling
Ubuntu-18.04                           Ubuntu 18.04 LTS
Ubuntu-20.04                           Ubuntu 20.04 LTS
Ubuntu-22.04                           Ubuntu 22.04 LTS
Ubuntu-24.04                           Ubuntu 24.04 LTS
OracleLinux_7_9                        Oracle Linux 7.9
OracleLinux_8_7                        Oracle Linux 8.7
OracleLinux_9_1                        Oracle Linux 9.1
openSUSE-Leap-15.5                     openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4    SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5           SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed                    openSUSE Tumbleweed

Ubuntu 24.04 のインストール

> wsl --install Ubuntu-24.04
インストール中: Ubuntu 24.04 LTS
Ubuntu 24.04 LTS がインストールされました。
Ubuntu 24.04 LTS を起動しています...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: mikoto
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 24.04 LTS (GNU/Linux 5.15.153.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Thu Jul 18 12:30:14 JST 2024

  System load:  0.52                Processes:             28
  Usage of /:   0.1% of 1006.85GB   Users logged in:       0
  Memory usage: 2%                  IPv4 address for eth0: 172.23.180.66
  Swap usage:   0%


This message is shown once a day. To disable it please create the
/home/mikoto/.hushlogin file.
mikoto@mnmain:~$

OK.

初期設定

apt upgrade

apt を更新。

sudo apt update
sudo apt upgrade

~/bin にパスを通す

いつも自作のシングルバイナリやスクリプトはここに入れているので、ディレクトリを作ってパスを通す。

mkdir ~/bin
echo 'export PATH="$PATH:~bin"' >> ~/.bashrc

継続して使いたいファイルのコピー

手抜きして 20.04 から .ssh, .gitconfig をコピー。 Windows のエクスプローラーでやったのち、 .ssh は権限を変更。

chmod 700 .ssh
chmod 700 .ssh/*

本当なら ssh-keygen で鍵を作って GitHub に登録。

.vim の配置

.vim 用のリポジトリがあるので、それをクローン。

git clone --recursive git@github.com:mikoto2000/dotvim .vim

docker のインストール

Dev container がないと開発できない体になってしまっているので、 docker をインストールする。

Install Docker Engine on Ubuntu | Docker Docs を見ながら作業実施。

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# 一般ユーザーが sudo 無しで docker コマンドを使えるようにする

```sh
sudo usermod -aG docker mikoto

ログアウトしてログインすると、 mikoto ユーザーが sudo 無しに docker コマンドを使えるようになる。

$ exit
> wsl -d Ubuntu-24.04
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:1408fec50309afee38f3535383f5b09419e6dc0925bc69891e79d84cc4cdcec6
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

OK.

使用ツールのダウンロード

なんだかんだ言って今使ってるのって devcontainer.vim だけか。 ~/bin にダウンロードする。

curl -L https://github.com/mikoto2000/devcontainer.vim/releases/download/v1.0.3/devcontainer.vim-linux-amd64 -o ~/bin/devcontainer.vim
chmod u+x ~/bin/devcontainer.vim

ひとまずはこれだけでいいはず。

devcontainer.vim の動作確認

最近作っている OASIZ_TimeLogger2 をクローンして開発環境を立ち上げられるか試す。

mkdir ~/project
cd ~/project
git clone git@github.com:mikoto2000/OASIZ_TimeLogger2
cd OASIZ_TimeLogger2
devcontainer.vim start .

初回起動が遅すぎて別ターミナル開いて ps aux してしまった。初回の docker build がすごく重い…

時間はかかったが Vim が起動し、ビルドも実行もできた。 WSLg で Windows 側に Window も表示された。 良さそう。

Ubuntu 20.04 をデフォルトに設定

良さそうなので Ubuntu 20.04 をデフォルトに設定する。

> wsl --set-default Ubuntu-24.04

新しく wsltty を開いて、デフォルトが効いているか確認。

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

OK.

以上。

参考資料

2022年3月22日火曜日

Docker の node コンテナで Tauri アプリに入門する

Rust 版 Electron の Tauri に入門する。プロジェクトのひな形を作るところまで。

前提

node のコンテナを起動

WSL2 上の Ubuntu で、以下コマンドを実行。

docker run -it --rm -v "$(pwd):/work" --workdir "/work" --name node \
    -e  DISPLAY=:0 \
    -e  WAYLAND_DISPLAY=wayland-0 \
    -e  XDG_RUNTIME_DIR=/tmp/wslg/runtime-di \
    -e  PULSE_SERVER=/mnt/wslg/PulseServer \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /mnt/wslg:/mnt/wslg \
    -v $HOME/.cargo:/home/node/.cargo \
    node bash
  • Docker Desktop で GUI を動かすために必要な設定
    • -e DISPLAY=:0
    • -e WAYLAND_DISPLAY=wayland-0
    • -e XDG_RUNTIME_DIR=/tmp/wslg/runtime-di
    • -e PULSE_SERVER=/mnt/wslg/PulseServer
    • -v /tmp/.X11-unix:/tmp/.X11-unix
    • -v /mnt/wslg:/mnt/wslg
  • Cargo からダウンロードしたものをキャッシュするディレクトリをマウントすることで、次回以降のプロジェクト作成時間短縮を図る
    • -v $HOME/.cargo:/home/node/.cargo

Tauri の環境構築

システムの依存を apt コマンドでインストール

apt update
apt install -y libwebkit2gtk-4.0-dev \
    build-essential \
    curl \
    wget \
    libssl-dev \
    libgtk-3-dev \
    libappindicator3-0.1-cil-dev \
    librsvg2-dev

node ユーザーへ切り替え

パッケージのインストールが完了したので、ここからは node コンテナに既に存在している node ユーザーで作業を行う。

su node

Rust のインストール

以下コマンドを実行し、インストーラーの指示に従ってインストール。

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup-setup.sh
chmod u+x rustup-setup.sh
./rustup-setup.sh -y

インストールが完了したら、以下コマンドで rust 関連コマンドにパスを通す。

source $HOME/.cargo/env

Tauri アプリの作成

create-tauri-app コマンドで Tauri アプリのひな形を作る。

今回は、 Vanilla.js で作成。

# npx create-tauri-app
Need to install the following packages:
  create-tauri-app
Ok to proceed? (y) y

We hope to help you create something special with Tauri!
You will have a choice of one of the UI frameworks supported by the greater web tech community.
This tool should get you quickly started. See our docs at https://tauri.studio/

If you haven't already, please take a moment to setup your system.
You may find the requirements here: https://tauri.studio/docs/getting-started/setting-up-linux/

Press any key to continue...
? What is your app name? tauri-app-firststep
? What should the window title be? Tauri App Firststep
? What UI recipe would you like to add? Vanilla.js (html, css, and js without the bundlers)
>> Running initial command(s)
>> Installing any additional needed dependencies

added 2 packages, and audited 3 packages in 3s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

added 3 packages, and audited 6 packages in 5s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
>> Updating "package.json"
>> Running "tauri init"

> tauri
> tauri "init" "--app-name" "tauri-app-firststep" "--window-title" "Tauri App Firststep" "--dist-dir" "../dist" "--dev-pa
th" "../dist"

>> Updating "tauri.conf.json"
>> Running final command(s)

    Your installation completed.

    $ cd tauri-app-firststep
    $ npm install
    $ npm run tauri dev

Tauri アプリの実行

cd tauri-app-firststep
npm install
npm run tauri dev

これで、 Tauri アプリが起動する。

今回の手順を元に作った Docker イメージを以下に作成した。

以上。

参考資料

2022年3月15日火曜日

Windows の Docker Desktop で、 GUI アプリを動かす

Debian コンテナで xeyes を実行し、目玉を確認するところまで。

前提

事前準備

Docker Desktop の WSL Integration を有効にする

Docker Desktop では、 WSL2 ディストリビューションから Docker Desktop の Docker Engine へアクセスするための仕組み「WSL Integration」を提供している。

WSL Integration を有効にすることで、 WSL ディストリビューション内で docker コマンドが実行可能となり、そのコマンドで Docker Desktop の Docker Engine へアクセスできるようになる。

  1. タスクトレイ内の Docker アイコン右クリック -> Setting -> Resources -> WSL INTEGRATION を選択
    • Docker を実行する WSL2 ディストリビューションを選択
    • 今回は、デフォルトディストリビューションの Ubuntu-20.04 を利用するため、 Enable integration with my default WSL distro にチェックを入れる

Docker で GUI アプリを実行

Debian コンテナをで、 xeyes を実行する。

WSL ディストリビューション起動

WSL2 ディストリビューションの、 Ubuntu-20.04 を起動。

コンテナ起動

WSL2 のディストリビューションには、 WSLg で GUI を実行するための環境変数とディレクトリが用意されている。 それをマウントしながら Docker コンテナを起動する。

Ubuntu 上で以下コマンドを実行。

docker run -it --rm \
    -e  DISPLAY=$DISPLAY \
    -e  WAYLAND_DISPLAY=$WAYLAND_DISPLAY \
    -e  XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
    -e  PULSE_SERVER=$PULSE_SERVER \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /mnt/wslg:/mnt/wslg \
    debian bash

WSLg に必要な環境変数・ディレクトリは以下 6 つ。

  • -e DISPLAY=$DISPLAY
  • -e WAYLAND_DISPLAY=$WAYLAND_DISPLAY
  • -e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR
  • -e PULSE_SERVER=$PULSE_SERVER
  • -v /tmp/.X11-unix:/tmp/.X11-unix
  • -v /mnt/wslg:/mnt/wslg

xeyes をインストールして実行

起動した Debian コンテナ上で以下コマンドを実行。

apt update
apt install -y x11-apps
xeyes

これで、Windows 上に、 xeyes の目玉が表示されるはず。

参考資料

2021年11月7日日曜日

WSL2 で Debian 11 (Bullseye) を使う

/etc/apt/sources.list を修正して、 apt update, apt full-upgrade するのが楽かもしれない。

しかし、WSL2 のルートファイルシステムも Docker と同じ感じて作れるようなので、 Bullseye のルートファイルシステムを作って WSL2 へインポートしてみる。

前提

  • ゲスト OS: Ubuntu 20.04(WSL2)
  • Docker: Docker version 20.10.8, build 3967b7d

Debian 11 のルートファイルシステム作成

Docker コンテナ起動

debootstrap して作成したルートファイルシステムを Windows に持っていけるように、ボリュームをマウントしつつ Debian コンテナを起動。

PowerShell 上で、以下コマンドを実行。

docker run -it --rm -v "$(pwd):/work" --workdir "/work" -name debian debian:buster-slim

以降、起動した Debian コンテナ上でルートファイルシステムを作成していく。

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

apt-get update
apt-get install -y debootstrap

debootstrap 実行

debootstrap で Debian 11 のルートファイルシステムを作成し、 tar で固める -> Windows へ渡すため、マウントしたフォルダへコピー。

cd
debootstrap bullseye ./bullseye http://deb.debian.org/debian
cd bullseye/
tar cfv ../debian-bullseye.tar .
cp ../debian-bullseye.tar /work

作成したら Debian コンテナはもう使わないので、停止。

WSL2 に Debian 11 をインポート

WSL2 ディストリビューションのディスク格納フォルダを作って、そこにインポートする。

PowerShell 上で以下コマンドを実行。

New-Item -ItemType Directory -p $HOME\wsl\debian\bullseye
wsl --import Debian-11 $HOME\wsl\debian\bullseye\ .\debian-bullseye.tar

Debian 11 の環境構築

Debian 11 のディストリビューション起動

PowerShell 上で以下コマンドを実行。

wsl -d Debian-11

Debian のアップグレードと必須パッケージインストール

アップグレードして sudo をインストールする。

起動した WSL 上で以下コマンドを実行。

apt-get update
apt-get upgrade -y
apt-get install -y sudo

一般ユーザー追加・設定

一般ユーザーを追加し、パスワード設定と sudo グループへの追加を行う。

useradd -m -s /bin/bash mikoto
passwd mikoto
gpasswd -a mikoto sudo

apt ソースリストの更新

適当に更新。

cat << EOF > /etc/apt/sources.list
deb http://ftp.jp.debian.org/debian/ bullseye main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ bullseye main contrib non-free

deb http://ftp.jp.debian.org/debian/ bullseye-updates main contrib non-free
deb-src http://ftp.jp.debian.org/debian/ bullseye-updates main contrib non-free

deb http://security.debian.org/ bullseye-security main
deb-src http://security.debian.org/ bullseye-security main
EOF

デフォルトユーザー設定

/etc/wsl.conf を更新し、WSL2 起動時に追加した一般ユーザーでログインする設定を行う。

cat << EOF > /etc/wsl.conf
[user]
default=mikoto
EOF

WSL2 再起動

これで、追加したユーザー(今回は mikoto) でログインした状態で Debian 11 が起動する。

Debian をログアウトして、 PowerShell 上で以下コマンドを実行する。

wsl -t Debian-11
wsl -d Debian-11

バージョン確認

/etc/os-release で、 Debian 11 がインストールされていることを確認する。

再起動後の Debian 上で、以下コマンドを実行・確認する。

mikoto@DESKTOP-CO13JB2:~$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

以上、あとはよしなに。

参考資料

更新履歴

日付 更新内容
2021/11/7 新規作成
2021/11/10 sources.list の内容が適当すぎたので修正。
あわせて参考資料を追加。

Ubuntu 20.04 on WSL2 で GUI アプリケーション(mikutter) を動かす

Twitter と Mastodon をひとまとめに確認したいと思って、 mikutter を導入した。

とりあえず動いているようなので、作業メモを残す。

※ ROM なので日本語入力環境構築までやっていない

前提

  • ホスト OS: Windows 11 Pro ビルド 22000.282
  • ゲスト OS: Ubuntu 20.04(WSL2)

WSL 環境構築

Windows 11にWSL 2、WSLgをインストール | AsTechLog を参考に実施。

GUI サポートを有効にするため、 WSL をアップデートする。

PowerShell を管理者権限で起動し、以下コマンドを実行。

wsl --update

Ubuntu 20.04 のインストール

管理者権限でない PowerShell を開いて、以下コマンドで Ubuntu 20.04 をインストール。

wsl --install -d Ubuntu-20.04

mikutter 環境構築・実行

Ubuntu のアップグレードと必要パッケージのインストール

Ubuntu 20.04 のインストールが完了したら、ベースシステムのアップグレードと、 mikutter の実行に必要なパッケージ一式をインストール。

sudo apt update
sudo apt upgrade -y
sudo apt install -y gcc make ruby libgtk2.0-dev libidn11-dev fonts-noto fonts-noto-cjk fonts-noto-mono ttf-ancient-fonts ruby-dev

mikutter インストール

本体と、 Twitter 用プラグインをインストールする。

ソースコード取得

mkdir ~/project
cd ~/project
git clone git://mikutter.hachune.net/mikutter.git

Twitter 用プラグインインストール

基本的に mikutter/twitter_bootstrap: The most popular Twitter client for mikutter plugin, teokure first projects on the Linuxとか desktop. の通りだが、今回は saved_search の挙動がよくわからなかったのでそれは削除している。また、インライン画像表示してくれる moguno/mikutter-subparts-image: mikutterで画像をインライン表示するプラグイン を追加した。

mkdir ~/.mikutter/plugin
cd ~/.mikutter/plugin
for i in api_request_file_cache direct_message followingcontrol home_timeline list list_for_profile list_settings mentions message_detail_view message_favorite message_retweet ratelimit rest streaming twitter twitter_activity twitter_datasource twitter_settings user_detail_view; do git clone https://github.com/mikutter/$i.git ~/.mikutter/plugin/$i; done
git clone https://github.com/moguno/mikutter-subparts-image.git

コンシューマーキーは昔勉強用に作ったものを流用。

必要な gem のインストール

bundle でインストール。

sudo gem install bundler
cd ~/project/mikutter
bundle config --local path vendor/bundle
bundle install

mikutter 起動

cd ~/project/mikutter
bundle exec ruby mikutter.rb

以下のような感じで GUI が表示される。

ショートカット作成

Windows 側でショートカットを作って、リンク先を wslg.exe -d Ubuntu-20.04 ~/mikutter.sh という感じで、 wslg から起動シェルスクリプトを叩くような形にする。

これで、ショートカットダブルクリックか、スタートメニューから実行できるようになる。

以上。

参考資料

2021年10月24日日曜日

WSL2 の Ubuntu 18.04 で WSL2 カーネルをビルドして差し替える

Windows -> WSL2 Ubuntu への USB カメラパススルーを行う前準備として、 USB/V4L2 関連の機能を有効にしたカーネルをビルドし、差し替える方法をまとめた。

現時点で USB カメラへの接続まで確認できていないが、とりあえず作業記録を残す。

前提

  • ホスト OS: Windows 11 Pro 21H2
  • ゲスト OS: Ubuntu 18.04(WSL2)

検証環境の準備

以前使っていた環境が残っていたので、 Ubuntu 環境を削除して作り直す

PS C:\Users\mikoto> wsl -l
Linux 用 Windows サブシステム ディストリビューション:
Ubuntu-18.04 (既定)
docker-desktop-data
docker-desktop
PS C:\Users\mikoto> wsl --unregister Ubuntu-18.04
登録を解除しています...
PS C:\Users\mikoto> wsl -l
Linux 用 Windows サブシステム ディストリビューション:
docker-desktop-data (既定)
docker-desktop
PS C:\Users\mikoto> wsl --install -d Ubuntu-18.04
Ubuntu 18.04 LTS は既にインストールされています
Ubuntu 18.04 LTS を起動しています...

この流れで Ubuntu が起動するので、続けて作業していく。

パッケージアップグレードと必要パッケージのインストール

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y build-essential flex bison libssl-dev libelf-dev libncurses-dev autoconf libudev-dev libtool

カーネル更新

現在のカーネルバージョンを確認

mikoto@DESKTOP-CO13JB2:~$ uname -r
5.4.91-microsoft-standard-WSL2

カーネルバージョンにあったカーネルをチェックアウト

sudo git clone --depth 1 https://github.com/microsoft/WSL2-Linux-Kernel -b linux-msft-5.4.91 /usr/src/5.4.91-microsoft-standard

念のためチェックアウトしたブランチを確認。

mikoto@DESKTOP-CO13JB2:~$ cd /usr/src/5.4.91-microsoft-standard/
mikoto@DESKTOP-CO13JB2:/usr/src/5.4.91-microsoft-standard$ git log
commit 807335635710b9038f2bb95019878d846130501a (grafted, HEAD, tag: linux-msft-5.4.91)
Author: Vivek Yadav <vyadav@microsoft.com>
Date:   Wed Jan 20 18:25:17 2021 +0000

    Merge remote-tracking branch 'msft/linux-msft-wsl-5.4.y' into linux-msft-wsl-5.4.y
mikoto@DESKTOP-CO13JB2:/usr/src/5.4.91-microsoft-standard$ cd -
/home/mikoto

linux-msft-5.4.91 のタグがチェックアウトされているのを確認できる。

現在のカーネル設定をコピー

cd /usr/src/5.4.91-microsoft-standard/
sudo cp /proc/config.gz config.gz
sudo gunzip config.gz
sudo mv config .config

カーネルモジュール設定

make menuconfig で、カーネルモジュールの設定を行う。

sudo make menuconfig

以下に今回変更したものだけ記載する。環境によって差があるかも…。

■ USB 関連

Device Drivers
    +- [*] USB support
        +- <M> Support for Host-side USB
        +- <M> USB Modem (CDC ACM) support
        +- <M> USB Mass Storage support
        +- <M> USB/IP support
        |   +- <M> VHCI hcd
        +- <M> USB Serial Converter support
        |   +- <M> USB FTDI Single Port Serial Driver
        +- USB Physical Layer drivers
        |   +- <M> NOP USB Transceiver Driver
        +- Network device support
            +- <M> USB Network Adapters
                +- <M> Multi-purpose USB Networking Framework
                |   +- <M> Host for RNDIS and ActiveSync devices
                +- <M> Multi-purpose USB Networking Framework

■ V4L2 関連

Device Drivers
    +- <M> Multimedia support
        +- [*] Cameras/video grabbers support
        +- [*] Media USB Adapters
            +- <M> USB Video Class (UVC)

カーネルのビルドとインストール

gcc 8 以上でないとコンパイルできないコードがあるため、 gcc のバージョンを上げて make する。

sudo apt-get install -y gcc-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8
sudo make -j 12 && sudo make modules_install -j 12 && sudo make install -j 12

カーネルを Windows から見られる場所へコピー

sudo mkdir /mnt/c/Users/mikoto/.wsl
sudo cp /usr/src/5.4.91-microsoft-standard/vmlinux /mnt/c/Users/mikoto/.wsl/

新カーネルで WSL 起動

起動カーネル設定

~/.wslconfig で、使用するカーネルを指定する。

[WSL2]
kernel=C:\\Users\\mikoto\\.wsl\\vmlinux

WSL 再起動

wsl --shutdown
wsl -d Ubuntu-18.04

uname で確認すると、新しいカーネルで起動しているのがわかる。

mikoto@DESKTOP-CO13JB2:/mnt/c/Users/mikoto$ uname -a -r
Linux DESKTOP-CO13JB2 5.4.91-microsoft-standard-WSL2+ #1 SMP Sun Oct 24 09:46:32 JST 2021 x86_64 x86_64 x86_64 GNU/Linux

ここから Windows -> Ubuntu への USB カメラパススルーまでもっていきたかったけど、 IP 経由でやり取りするためにアプリインストールとかあるらしくめげた。今日はここまで。

以上。

参考資料