0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows環境にWSLを立ち上げる自分的簡易メモ

Posted at

:sailboat: この記事の目的

Windows環境でWSLを複数立ち上げたり、削除したりする際のコマンドのメモです。
詳しい解説はありません。必要事項のみ記載します。

:sailboat: Ubuntuイメージのダウンロードサイト

以下からWSL向けのtar.gzファイルを取得する。

Ubuntu WSL Images
https://cloud-images.ubuntu.com/wsl/

:sailboat: 実行コマンド集

現存のWSL環境を確認

wsl -l -v

WSLイメージファイルを取得

※PowerShellで実行

curl <ネット上のファイル名> -outfile <ローカルの保存先ファイル名>

実行例

curl "https://cloud-images.ubuntu.com/releases/focal/release-20221018/ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz" -OutFile "c:\ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz"

インポート

コマンド例
wsl --import <環境名> <展開先フォルダ名> <イメージファイル名>
 ・環境名 = "wsl -l -v"コマンドでWSLの一覧に表示される名前
 ・展開先フォルダ名 = この中にext4.vhdxファイルが作成される

wsl --import ubuntu_new "c:\ubuntu_new" "c:\ubuntu-20.04-server-cloudimg-amd64-wsl.rootfs.tar.gz"

作成後の確認

wsl -l -v

実行

wsl -d <環境名>

削除

wsl --unregister <環境名>

Ubuntu内にユーザを追加

以下はUbuntu内、rootユーザで作業

useradd -m -G sudo -s /bin/bash (username)
sudo passwd (username)
echo -e "[user]\ndefault=(username)"
cat /etc/wsl.conf
exit

確認

停止

wsl -t <環境名>

開始

wsl -d <環境名>

以上

:paperclip: 参考サイト
WSLにまっさらな新規のUbuntu環境をつくる
https://goodbyegangster.hatenablog.com/entry/2022/10/25/015309

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?