Closed10

WSL2 セットアップ

狐崎 めずもな狐崎 めずもな

以下でまっさらな Ubuntu 環境を登録
$INSTANCE_NAME は好きな名前に置き換え。

wsl --import $INSTANCE_NAME C:\path\to\instances\dir C:\path\to\rootfs\ubuntu-lunar-wsl-amd64-wsl.rootfs.tar.gz

狐崎 めずもな狐崎 めずもな

ログインユーザーが root になっているので、作業用のユーザーに変更して再起動

adduser mezum # password 以外は空で良い。
usermod -aG sudo mezum

cat << 'EOF' >/etc/wsl.conf
[user]
default=mezum
EOF
exit
wsl -t $INSTANCE_NAME
wsl -d $INSTANCE_NAME
狐崎 めずもな狐崎 めずもな

CUDA Toolkit を入れて WSL 上でも動かせるようにしておく。
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=WSL-Ubuntu&target_version=2.0&target_type=runfile_local

sudo apt-key del 7fa2af80
sudo apt install -y gcc
wget https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run
sudo sh cuda_12.2.2_535.104.05_linux.run

再起動

exit
wsl -t $INSTANCE_NAME
wsl -d $INSTANCE_NAME
狐崎 めずもな狐崎 めずもな

Windows 側の日本語フォントを読めるようにしておく。

cat << 'EOF' | sudo tee /etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
    <dir>/mnt/c/Windows/Fonts</dir>
    <dir>/mnt/c/Users/mezum/AppData/Local/Microsoft/Windows/Fonts</dir>
</fontconfig>
EOF
# ユーザー名は Windows 側に合わせる。
狐崎 めずもな狐崎 めずもな

日本語入力を WSLg 上で動かせるようにしておく。

sudo apt install -y fcitx-mozc dbus-x11 x11-xserver-utils
dbus-uuidgen | sudo tee /var/lib/dbus/machine-id
cat << 'EOF' >>~/.profile
# IM
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS='@im=fcitx'
export DefaultIMModule=fcitx
if [ $SHLVL -eq 1 ]; then
    (fcitx-autostart >/dev/null 2>&1 &)
    xset -r 49
fi
EOF
source ~/.profile
fcitx-configtool
# Keyboard - Japanese を追加 (必要に応じて Only Show Current Language のチェックを外す)
# Keyboard - English を削除
# Mozc を追加
# Global Config > Show Advanced Options > Hotkey > Activate/Inactivate Input Method にて
#「変換」「無変換」キーを割り当てておく
このスクラップは2023/10/16にクローズされました