WSL默認安裝目錄

我當前在win11下進行以下操作,其它系統版本有問題可以留言

一、安裝WSL

  1. 前提條件:我們需要保證你的操作系統版本滿足 **Windows 10 版本 2004 及更高版本(內部版本 19041 及更高版本)或 Windows 11 ** 才能使用以下命令。
  2. 啓用適用於 Linux 的 Windows 子系統:打開powershell並輸入
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  3. 啓用虛擬化:以管理員打開powershell輸入下列命令:
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  4. 【可選/推薦】設置WSL默認版本爲wsl2:wsl --set-default-version 2(WSL2.0相比WSL1.0具備完整的Linux內核、託管VM和完全的系統調用兼容性,所以我們這裏使用WSL2.0)
  5. 直接安裝/指定內核版本安裝
    【直接安裝】WSL的安裝很簡單,可以參考官方手冊:
    可以使用單個命令安裝運行 WSL 所需的一切內容。 在管理員模式下打開 PowerShell 或 Windows 命令提示符,方法是右鍵單擊並選擇“以管理員身份運行”,輸入wsl --install命令,然後重啓計算機。
    【指定內核安裝】
    當然,可以選擇指定內核的方式來安裝wsl:
  • 若要更改安裝的發行版,請輸入:wsl --install -d <Distribution Name>。 將 <Distribution Name>替換爲要安裝的發行版的名稱。
  • 若要查看可通過在線商店下載的可用 Linux 發行版列表,請輸入:wsl --list --onlinewsl -l -o
  • 若要在初始安裝後安裝其他 Linux 發行版,還可使用命令:wsl --install -d <Distribution Name>

二、WSL修改默認安裝目錄到其他盤

顯然,此時的wsl默認安裝在c盤,隨着系統的使用,會佔用我們C盤的空間,所以我們將其打包放到其它盤去。
1.查看WSL發行版本
在Windows PowerShell中輸入命令:
wsl -l --all -v
2.導出分發版爲tar文件到d盤
wsl --export Ubuntu-20.04 d:\wsl-ubuntu20.04.tar(Ubuntu-20.04修改成你現在的發行版名稱)
3.註銷當前分發版
wsl --unregister Ubuntu-20.04(Ubuntu-20.04修改成你現在的發行版名稱)
4.重新導入並安裝WSL在d:\wsl-ubuntu20.04(可以修改成你自己想要的目錄
wsl --import Ubuntu-20.04 d:\wsl-ubuntu20.04 d:\wsl-ubuntu20.04.tar --version 2
5.設置默認登陸用戶爲安裝時用戶名
ubuntu2004 config --default-user Username
6.刪除tar文件(可選)
del d:\wsl-ubuntu20.04.tar

經過以上操作後,就將WSL的默認安裝目錄遷移到D:\wsl-ubuntu20.04目錄(可以自己修改自己想要的目錄)下了。此目錄即爲WSL的跟文件系統。

 

位置在:

C:\Users\THINK\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

備註:THINK是我的Windows登錄用戶名,你換成自己的用戶名即可,知道了這個文件夾之後就可以方便地進行subsystem的文件管理了,寫好後的程序也可以轉移到自己的windows系統下,避免了程序丟失的煩惱。

 

一、WSL簡介

WSL的全稱是Windows Subsystem for Linux。
適用於 Linux 的 Windows 子系統可讓開發人員按原樣運行 GNU/Linux 環境 - 包括大多數命令行工具、實用工具和應用程序 - 且不會產生傳統虛擬機或雙啓動設置開銷。

二、開啓WSL功能

系統要求:win10/11 專業版,(家庭版無法使用)
打開控制面板 -> 程序 -> 啓用或關閉windows功能
將“適用於Linux的windows子系統”勾選
後續您的windows系統會進行更新,重啓後將會開啓WSL功能。
默認開啓的WSL版本是1.目前最新的版本是2.(但是之後可能會報錯還是要版本2.0的)


三、安裝kali子系統

進入微軟商店搜索kali,選擇kali進行安裝、沒有Windows Terminal也要裝
安裝完成後,在開始頁面可以看到Kali Linux。
首次完成會要求您完成的第一步是創建賬戶,包括用戶名和密碼。(但是不是很順利會報錯)

報錯的解決辦法在下面👇

此用戶名和密碼特定於安裝的每個單獨的 Linux 分發版,與 Windows 用戶名無關。
創建用戶名和密碼後,該帳戶將是分發版的默認用戶,並將在啓動時自動登錄。
此帳戶將被視爲 Linux 管理員,能夠運行 sudo (Super User Do) 管理命令。
在適用於 Linux 的 Windows 子系統上運行的每個 Linux 分發版都有其自身的 Linux 用戶帳戶和密碼。 每當添加分發版、重新安裝或重置時,都必須配置一個 Linux 用戶帳戶。
此時雖然爲管理員賬戶,可以使用sudo命令,但是不能使用root進行操作。
使用sudo passwd root命令,爲root修改密碼。

報錯1:8007019e

解決問題:WslRegisterDistribution failed with error: 0x8007019e

然後打開安裝好的Windows Linux子系統(WSL) 此時一般來說會遇到下面的問題:

 
  1. Installing, this may take a few minutes...
  2. WslRegisterDistribution failed with error: 0x8007019e
  3. The Windows Subsystem for Linux optional component is not enabled. Please enable it and try again.
  4. See https://aka.ms/wslinstall for details.
  5. Press any key to continue...
 

出現這個錯誤的原因是沒有安裝Windows子系統支持(如果前面打開那個功能過後就重啓就不會出現這個問題)。

解決辦法: 打開Windows PowerShell(Admin) 輸入: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 回車執行 重啓

 

報錯2:800701bc

問題解決WslRegisterDistribution failed with error: 0x800701bc

造成該問題的原因是WSL版本由原來的WSL1升級到WSL2後,內核沒有升級,前往微軟WSL官網下載安裝適用於 x64 計算機的最新 WSL2 Linux 內核更新包即可。

 

下載並安裝WSL2更新包

WSL2 Linux kernel update package for x64 machines​wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

將WSL2設置成默認

wsl --set-default-version 2

 

但是輸入wsl --set-default-version 2失敗,報錯“請啓用虛擬機平臺 windows 功能並確保在 bios 中啓用虛擬化"

解決辦法:運行這個指令要以管理員身份運行

bcdedit /set hypervisorlaunchtype auto

這個指令代表的意思是:設置Hyper-V虛擬化啓動類型爲自動。

 

報錯3:80370102

問題解決WslRegisterDistribution failed with error: 0x80370102

 
  1. Installing, this may take a few minutes...
  2. WslRegisterDistribution failed with error: 0x80370102
  3. Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
  4. For information please visit https://aka.ms/enablevirtualization
  5. Press any key to continue..
 

這個只要前面開啓那個虛擬化平臺也不會報錯
 

開啓虛擬機特性

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

 

報錯4:80004005

安裝報錯 WslRegisterDistribution failed with error: 0x80004005

我是從MS Store 安裝的,下載後點擊打開,彈出cmd窗口報錯信息:

 
  1. Installing, this may take a few minutes... 
  2. WslRegisterDistribution failed with error: 0x80004005 
  3. Error: 0x80004005 ???????
  4.  
  5. Press any key to continue...
 

解決方法:
將 LxssManager 服務修改爲自動啓動
從服務中修改會提示“拒絕訪問”,所以從註冊表改
win + R -> regedit -> \HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LxssManager ->

右鍵 Start 項 -> 將值修改爲 2(默認爲 3)

 
  1. 1 自動(延遲啓動)
  2. 2 自動
  3. 3 手動
  4. 4 禁用
 

 

更新wsl
管理員啓動 powershell:wsl --update

成功安裝
再次點擊打開

 
  1. Installing, this may take a few minutes...
  2. Please create a default UNIX user account. The username does not need to match your Windows username.
  3. For more information visit: https://aka.ms/wslusers
  4. Enter new UNIX username:
 

報錯5:80070005

WslRegisterDistribution failed with error: 0x80070005

解決方法
  1. 卸載:
  • Hyper-V
  • 虛擬機管理程序平臺
  • 容器
  • WSL的
  1. 重新啓動
  2. 重新安裝所有 4 個功能
  3. 重新啓動
  4. 再次調用 API。現在它起作用了。

如何刪除它?我在 Microsoft 商店中沒有卸載按鈕。

第一個,在“設置”中選中“應用程序”並找到它或在搜索欄中寫入Windows子系統,然後卸載

第二個,在“設置”中選中“應用程序”並找到它或在搜索欄中寫入kali,然後卸載

重新再來一遍就行...

 

修改默認安裝位置

一般來說都會默認按在 C 盤 ,所以我們可以使用下面的方法進行修改默認安裝位置,同時我們應該也可以使用這個方法進行一個分支保存

 
  1. # 1. 查看所有安裝的版本
  2. PS C:\Users\14894> wsl -l --all -v
  3. NAME STATE VERSION
  4. * kali-linux Running 2
  5. # 2. 導出分發版爲 tar文件到 D盤
  6. PS C:\Users\14894> wsl --export kali-linux D:\wsl-kali-linux.tar
  7. # 3. 註銷當前分發版
  8. PS C:\Users\14894> wsl --unregister kali-linux
  9. # 4. 重新導入並安裝WSL在D盤
  10. PS C:\Users\14894> wsl --import kali-linux D:\kali-linux D:\wsl-kali-linux.tar --version 2
  11. # 5. 設置默認登陸用戶爲安裝時用戶名
  12. PS C:\Users\14894> kali-linux config --default-user USERNAME
  13. # 6. 刪除 wsl-kali-linux.tar
  14. PS C:\Users\14894> del D:\wsl-kali-linux.tar
 

更新源和升級軟件

su vim /etc/apt/sources.list

# 官方源
# deb http://http.kali.org/kali kali-rolling main non-free contrib
# deb-src http://http.kali.org/kali kali-rolling main non-free contrib
#根據需要自己選一個,中科大的還可以
#中科大
deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
#阿里雲
#deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib
#deb-src http://mirrors.aliyun.com/kali kali-rolling main non-free contrib

安裝完整版Kali

執行:apt-get install kali-linux-everything
即使更換了更新源也需要經過漫長的等待,全部的安裝內容大約在19G左右。根據C盤容量,量力而行。

0 upgraded, 3891 newly installed, 0 to remove and 0 not upgraded.
Need to get 10.8 GB of archives.
After this operation, 30.8 GB of additional disk space will be used.
Do you want to continue? [Y/n]

0個已升級,3891個新安裝,0個要移除,0個未升級。
需要獲得10.8 GB的檔案。
執行此操作後,將使用30.8 GB的額外磁盤空間。
你想繼續嗎?[是/否]

kali-linux-everything 安裝kali提供的所有工具

kali-linux-large 安裝kali提供的默認工具

kali-linux-top10 安裝最流行的10個工具

 

"docker-credential-desktop.exe": executable file not found in $PATH 錯誤解決

 

1. 錯誤信息和解決方法

錯誤信息,

error getting credentials - err: exec: "docker-credential-desktop.exe": executable file not found in $PATH, out: ``
 
 

解決方法,

Delete the line with credsStore from ~/.docker/config.json.

Or rename credsStore to credStore

完結!

WSL2 默認安裝在 C 盤下,系統盤空間有限,推薦遷移安裝目錄。

1. 默認安裝的 WSL2 目錄

C:\Users\cheng\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\ext4.vhdx

在這裏插入圖片描述

2. 將安裝的 WSL2 遷移至指定目錄

  1. wsl --list --verbose - wsl -l -v

查看安裝在 Windows 計算機上的 Linux 發行版列表,其中包括狀態和運行發行版的 WSL 版本 (WSL 1 或 WSL 2)。

  1. wsl --shutdown

立即終止所有正在運行的發行版和 WSL 2 輕量級實用工具虛擬機。

Microsoft Windows [版本 10.0.22621.1265]
(c) Microsoft Corporation。保留所有權利。

C:\Users\cheng>wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

C:\Users\cheng>
C:\Users\cheng>wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

C:\Users\cheng>
C:\Users\cheng>wsl --shutdown

C:\Users\cheng>
C:\Users\cheng>wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         2

C:\Users\cheng>
  1. wsl --export Ubuntu-20.04 f:\ubuntu20.04.tar

將指定 tar 文件導出爲新的發行版。--export 選項後面是查看運行狀態中 Linux 系統的名字。

C:\Users\cheng>wsl --export Ubuntu-20.04 f:\ubuntu2004.tar

C:\Users\cheng>

在這裏插入圖片描述

  1. Unregister or uninstall a Linux distribution (註銷或卸載 Linux 發行版)

While Linux distributions can be installed through the Microsoft Store, they can’t be uninstalled through the store.
儘管可以通過 Microsoft Store 安裝 Linux 發行版,但無法通過 Store 將其卸載。

To unregister and uninstall a WSL distribution

wsl --unregister <DistributionName>

Replacing <DistributionName> with the name of your targeted Linux distribution will unregister that distribution from WSL so it can be reinstalled or cleaned up. Caution: Once unregistered, all data, settings, and software associated with that distribution will be permanently lost. Reinstalling from the store will install a clean copy of the distribution. For example, wsl --unregister Ubuntu would remove Ubuntu from the distributions available in WSL. Running wsl --list will reveal that it is no longer listed.
如果將 <DistributionName> 替換爲目標 Linux 發行版的名稱,則將從 WSL 取消註冊該發行版,以便可以重新安裝或清理它。警告:取消註冊後,與該分發版關聯的所有數據、設置和軟件將永久丟失。從 Store 重新安裝會安裝分發版的乾淨副本。 例如:wsl --unregister Ubuntu 將從可用於 WSL 的發行版中刪除 Ubuntu。運行 wsl --list 將會顯示它不再列出。

You can also uninstall the Linux distribution app on your Windows machine just like any other store application. To reinstall, find the distribution in the Microsoft Store and select Launch.
還可以像卸載任何其他應用商店應用程序一樣卸載 Windows 計算機上的 Linux 發行版應用。若要重新安裝,請在 Microsoft Store 中找到該發行版,然後選擇 Launch

C:\Users\cheng>wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         2

C:\Users\cheng>
C:\Users\cheng>wsl --unregister Ubuntu-20.04
正在註銷...

C:\Users\cheng>
C:\Users\cheng>wsl --list --verbose
適用於 Linux 的 Windows 子系統沒有已安裝的分發版。
可以通過訪問 Microsoft Store 來安裝分發版:
https://aka.ms/wslstore

C:\Users\cheng>
  1. wsl --import Ubuntu-20.04 f:\ubuntu_20_04 f:\ubuntu2004.tar

將指定 tar 文件導入爲新的發行版。

wsl --import <Distribution Name> <InstallLocation> <FileName>

C:\Users\cheng>wsl --import Ubuntu-20.04 f:\ubuntu_20_04 f:\ubuntu2004.tar

C:\Users\cheng>

遷移成功之後,可在安裝目錄下查看 vhdx 文件。
F:\ubuntu_20_04\ext4.vhdx
在這裏插入圖片描述

  1. ubuntu2004.exe config --default-user yongqiang

設置默認登陸用戶爲安裝時的用戶名。

C:\Users\cheng>ubuntu2004.exe config --default-user yongqiang

C:\Users\cheng>
  1. 刪除 f:\ubuntu2004.tar 文件
C:\Users\cheng>del f:\ubuntu2004.tar

C:\Users\cheng>

3. 通過終端打開 Ubuntu-20.04

  1. 在 Windows 圖標 [開始] 處點擊鼠標右鍵

在這裏插入圖片描述

  1. 終端 / 終端 (管理員)

在這裏插入圖片描述

References

https://yongqiang.blog.csdn.net/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章