「WSL2+Ubuntu」環境下でさまざまなトライアンドエラーを行った結果、エラーが蓄積しリセットを行いたい場合がある。このような場合のために、WSL2+Ubuntuのリセットと削除方法について本記事では紹介する。

本記事の読者層は以下の方を想定しています。
- WSL2+Ubuntuのデータをリセットしたい方
- WSL2+Ubuntuをアンインストール・削除したい方
WSL2+Ubuntuの背景
「WSL2+Ubuntu」でLinux環境を実現するためトライアンドエラーを行った結果、内部エラーが蓄積しどうしようもなくなることがあります。このときLinux環境をリセットしたくなる場合があるでしょう。
Windows上で行える選択肢として、
- ①データの完全リセット
- ②アンインストール+再インストール
を行う手順を紹介します。
Ubuntuのリセット方法は以下2つの方法で行ってみます。
①Ubuntuアプリケーションからのリセット
②PowerSHell側からのリセット
注意
Linux環境下は、Windows11/10 WSL2アプリケーションで構築したUbuntu18.04/20.04を利用していると想定します。


Ubuntuアプリをリセットする方法
Ubuntu側からリセット


アプリをリセットする場合は上記のリセットボタンを押します。
基本、これだけで初期状態に戻りますがこれでも不具合が発生するようでしたら以下の方法を試してみてください。
Ubuntuのアンインストール+再インストール方法
PowerShell側からリセット
「Windows11スタートメニュー」を右クリックして、ターミナル(管理者)からPowerShellを立ち上げます。
> wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
Ubuntu-18.04 Running 2
Ubuntu Stopped 2
>wsl -l
Linux 用 Windows サブシステム ディストリビューション:
Ubuntu-20.04 (既定)
Ubuntu-18.04
Ubuntu
このように表されます。この中でRunningとなっているためUbuntu-18.04を落とします。
>wsl --shutdown Ubuntu-18.04
Ubuntu側からアンインストール
次にさらに以下の「アンインストール」を行う。


PowerSHell側からアンインストール
PowerShell側からも以下の方法でUbuntu-18.04を削除します。
>wsl --unregister Ubuntu-18.04
登録解除。
この操作を正しく終了しました。
wsl -l -v
NAME STATE VERSION
* Ubuntu-20.04 Running 2
Ubuntu Stopped 2
注意
Runningしている場合は削除しない方が良いです。
他に利用しているディストリビューションがない場合は以下のような表記となります。
> wsl -l -v
Linux 用 Windows サブシステムにインストールされているディストリビューションはありません。
使用可能なディストリビューションを一覧表示するには、'wsl.exe --list --online' を使用します
インストールするには 'wsl.exe --install <Distro>' と指定します。
ディストリビューションは、Microsoft Storeにアクセスしてインストールすることもできます:
https://aka.ms/wslstore
Error code: Wsl/WSL_E_DEFAULT_DISTRO_NOT_FOUND
これで完全アンインストールされます。
Ubuntuの再インストール
再インストール後に以下の表記を経てインストールを終了します。
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:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
この操作を正しく終了しました。
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
完全リセット後に再セットアップを行う際には、以下のプロセスを確認してみてください。


まとめ
「WSL2+Ubuntu」環境下でさまざまなトライアンドエラーを行った結果、エラーが蓄積しリセットを行いたい場合のリセット方法を学んだ。
- 完全リセット方法
- 完全アンインストール方法
次回の記事をご期待下さい。どうぞよろしくお願いいたします。
関連リンク








コメント