C drive が OS、D drive が大容量の人向け。
実験装置を使うため Windows で、それを Linux のみのツールを解析したい人は一定数いるはず?
この場合、WSL2 も D drive に置き、解析に使うファイルを WSL2 の root にコピーして使うのが良さそう。
WSL2 の D drive へのインストールを AI に聞いても公式情報か不明の答えばっかりだった(実際、公式情報が散らばっていた)ので、公式情報をまとめた。
前提
wsl コマンドが powershell で使える。
まだの場合は、powershell で
wsl --install --no-distribution
方法1 WSL2 を C drive で使ったことがない人向け
公式情報
-
https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro#import-the-tar-file-into-wsl
- 任意の linux distribution を任意の location に置くときのコマンドを使う
-
wsl.exe --import <Distro> <InstallLocation> <FileName> [Options] Options: --version <Version> --vhd
-
https://cloudinit.readthedocs.io/en/latest/howto/launch_wsl.html#option-2-the-ubuntu-image-server
-
wsl --importを使う際の tar ファイルの場所について - Ubuntu 開発元の Canonical 社によるソフトの document を参照
- 一部 image の場所が古いのは自分で判断して修正する
-
Ubuntu-24.04 の場合の例
-
https://cloud-images.ubuntu.com/wsl/releases/noble/current/ にて
ubuntu-noble-wsl-amd64-wsl.rootfs.tar.gzをダウンロード(D:\Downloads に置いたとする) - WSL のインストール先のフォルダを作る
mkdir D:\WSL\Ubuntu2404 - Powershell で以下
wsl.exe --import Ubuntu-24.04 D:\WSL\Ubuntu2404 D:\Downloads\ubuntu-noble-wsl-amd64-wsl.rootfs.tar.gz
方法2 WSL2 を C drive で使っていて、移行したい人向け
公式情報
# Export your distro to that folder as a VHD
wsl --export <Distro, e.g: Ubuntu> <FileName, e.g: D:\WSLDistros\Ubuntu\ext4.vhdx> --format vhd
# Unregister your old distro
# Please note this will erase your existing distro's file contents, please ensure the backup file you created in the 2nd step is present at the location and that the export operation completed successfully.
# Please exercise caution when using this command, as it is destructive and could cause data loss.
wsl --unregister <Distro, e.g: Ubuntu>
# Import your VHD backup
wsl --import-in-place <Distro, e.g: Ubuntu> <FileName, e.g: D:\WSLDistros\Ubuntu\ext4.vhdx>
実はこっちのほうが単純かも。
いったん公式情報に沿って C drive にインストールしてから、上記の方法で D drive に移してもよいかも。
(ただ、この場合 C drive で 1 GB 程度の書き込み&消去を行うため、最初から D drive へインストールする方がドライブには優しい。)