操作性環(huán)境:
? ?Windows 11 64bit 系統(tǒng)。
1.安裝wsl命令
特別說明,后續(xù)windows終端操作命令都需要在在管理員模式下打開 PowerShell 或 Windows 命令提示符,方法是右鍵單擊并選擇“以管理員身份運(yùn)行”。
1.1 前期準(zhǔn)備
安裝 WSL2之前,須啟用虛擬機(jī)平臺可選功能:
?
PS?C:WINDOWSsystem32>?dism.exe?/online?/enable-feature?/featurename:VirtualMachinePlatform?/all?/norestart 部署映像服務(wù)和管理工具 版本:?10.0.22000.653 映像版本:?10.0.22000.2057 啟用一個(gè)或多個(gè)功能 [==========================100.0%==========================] 操作成功完成。 PS?C:WINDOWSsystem32>
?
需要先啟用“適用于Linux 的 Windows 子系統(tǒng)”可選功能,然后才能在 Windows上安裝 Linux系統(tǒng),比如ubuntu系統(tǒng):
?
PS?C:WINDOWSsystem32>?dism.exe?/online?/enable-feature?/featurename:Microsoft-Windows-Subsystem-Linux?/all?/norestart 部署映像服務(wù)和管理工具 版本:?10.0.22000.653 映像版本:?10.0.22000.2057 啟用一個(gè)或多個(gè)功能 [==========================100.0%==========================] 操作成功完成。 PS?C:WINDOWSsystem32>
?
以上操作完成之后,并重啟計(jì)算機(jī)。
1.2 安裝wsl
可以使用單個(gè)命令安裝運(yùn)行 WSL。在管理員模式下打開 PowerShell 或 Windows 命令提示符,輸入 wsl --install 命令完成安裝然后重啟計(jì)算機(jī)。
?
Windows?PowerShell 版權(quán)所有(C) Microsoft Corporation。保留所有權(quán)利。 安裝最新的 PowerShell,了解新功能和改進(jìn)!https://aka.ms/PSWindows PS?C:WINDOWSsystem32>?wsl?--install 正在安裝:?虛擬機(jī)平臺 已安裝?虛擬機(jī)平臺。 正在安裝:?適用于?Linux?的?Windows?子系統(tǒng) 已安裝?適用于 Linux 的 Windows 子系統(tǒng)。 正在安裝:?Ubuntu 已安裝 Ubuntu。 請求的操作成功。直到重新啟動系統(tǒng)前更改將不會生效。
?
1.3 安裝Windows子系統(tǒng)ubuntu 20.04
查看支持安裝的系統(tǒng)版本:
?
PS?C:WINDOWSsystem32>?wsl?-l?-o 以下是可安裝的有效分發(fā)的列表。 使用?'wsl.exe --install'?安裝。 NAME???????????????????????????????????FRIENDLY?NAME Ubuntu?????????????????????????????????Ubuntu Debian?????????????????????????????????Debian?GNU/Linux kali-linux?????????????????????????????Kali?Linux?Rolling Ubuntu-18.04???????????????????????????Ubuntu?18.04?LTS Ubuntu-20.04???????????????????????????Ubuntu?20.04?LTS Ubuntu-22.04???????????????????????????Ubuntu?22.04?LTS OracleLinux_7_9????????????????????????Oracle?Linux?7.9 OracleLinux_8_7????????????????????????Oracle?Linux?8.7 OracleLinux_9_1????????????????????????Oracle?Linux?9.1 openSUSE-Leap-15.5?????????????????????openSUSE?Leap?15.5 SUSE-Linux-Enterprise-Server-15-SP4????SUSE?Linux?Enterprise?Server?15?SP4 SUSE-Linux-Enterprise-Server-15-SP5????SUSE?Linux?Enterprise?Server?15?SP5 openSUSE-Tumbleweed????????????????????openSUSE?Tumbleweed
?
安裝指定操作系統(tǒng)版本Ubuntu-20.04:
?
PS?C:WINDOWSsystem32>?wsl?--install?-d??Ubuntu-20.04 正在安裝:?Ubuntu?20.04?LTS 已安裝 Ubuntu 20.04 LTS。 正在啟動?Ubuntu?20.04?LTS...
?
1.4 遷移wsl2安裝的子系統(tǒng)到其他磁盤
默認(rèn)使用wsl安裝的子系統(tǒng)存儲在電腦C盤,由于安卓系統(tǒng)源碼比較大,至少考慮預(yù)留200G的空閑磁盤。如果你的C盤空間充足,可以不用考慮遷移。否則需要將子系統(tǒng)放到一個(gè)相對比較大的磁盤??梢园惭b如下步驟遷移wsl安裝的ubuntu子系統(tǒng)。以下以遷移到F盤為例說明:
?
PS?C:WINDOWSsystem32>?wsl?-l?--all?-v ??NAME????????????STATE???????????VERSION *?Ubuntu-20.04????Running?????????2 PS?C:WINDOWSsystem32>?wsl?--shutdown PS?C:WINDOWSsystem32> PS?C:WINDOWSsystem32>?wsl?--export?Ubuntu-20.04?????F:wslwsl-ubuntu20.04.tar 正在導(dǎo)出,這可能需要幾分鐘時(shí)間。 操作成功完成。 PS?C:WINDOWSsystem32> PS?C:WINDOWSsystem32>?wsl?--unregister?Ubuntu-20.04 正在注銷。 操作成功完成。 PS?C:WINDOWSsystem32>?wsl?--import?Ubuntu-20.04??F:wslwsl-ubuntu20.04???F:wslwsl-ubuntu20.04.tar??--version?2 正在導(dǎo)入,這可能需要幾分鐘時(shí)間。 操作成功完成。 PS?C:WINDOWSsystem32>
?
1.5 啟動進(jìn)入wsl子系統(tǒng)
執(zhí)行如下命令啟動安裝的Ubuntu子系統(tǒng):
?
PS?C:WINDOWSsystem32>?wsl?-d?Ubuntu-20.04 操作成功完成。
?
如果需要以root用戶進(jìn)入,執(zhí)行如下命令:
?
PS?C:WINDOWSsystem32>?wsl?-u?root
?
1.6 Windows端訪問子系統(tǒng)ubuntu文件夾
Windows端查看wsl系統(tǒng)方法:
在Windows文件欄輸入"\wsl$",回車就可以看到Ubuntu系統(tǒng)目錄。
1.7 可能遇到的啟動問題
啟動過程中可能出現(xiàn)錯(cuò)誤:
Installing, this may take a few minutes…
WslRegisterDistribution failed with error: 0x80370102
Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
For information please visit https://aka.ms/enablevirtualization
解決方法:
執(zhí)行如下命令然后重啟電腦。
?
wsl?--set-default-version?2 DISM?/Online?/Enable-Feature?/All?/FeatureName:Microsoft-Hyper-V bcdedit?/set?hypervisorlaunchtype?auto
?
2.源碼下載
依次參考執(zhí)行如下命令完成源碼下載:
?
PS?C:WINDOWSsystem32>?wsl?-d?Ubuntu-20.04 qiang@LAPTOP-GACS65HF:/mnt/c/WINDOWS/system32$?cd?/home qiang@LAPTOP-GACS65HF:/home$?ls qiang qiang@LAPTOP-GACS65HF:/home$?cd?qiang qiang@LAPTOP-GACS65HF:~$?ls AospCode qiang@LAPTOP-GACS65HF:~$?cd?AospCode/ qiang@LAPTOP-GACS65HF:~/AospCode$?ls qiang@LAPTOP-GACS65HF:~/AospCode$?mkdir?Aosp12 mkdir:?cannot?create?directory?‘Aosp12’:?Permission?denied qiang@LAPTOP-GACS65HF:~/AospCode$?ls?-la total?8 drwxr-xr-x?2?root??root??4096?Jul?10?18:49?. drwxr-xr-x?6?qiang?qiang?4096?Jul?10?17:20?.. qiang@LAPTOP-GACS65HF:~/AospCode$?cd?.. qiang@LAPTOP-GACS65HF:~$?ls AospCode qiang@LAPTOP-GACS65HF:~$?ls?-la total?40 drwxr-xr-x?6?qiang?qiang?4096?Jul?10?17:20?. drwxr-xr-x?3?root??root??4096?Jul?10?14:43?.. -rw-------?1?qiang?qiang??780?Jul?10?19:00?.bash_history -rw-r--r--?1?qiang?qiang??220?Jul?10?14:43?.bash_logout -rw-r--r--?1?qiang?qiang?3771?Jul?10?14:43?.bashrc drwx------?2?qiang?qiang?4096?Jul?10?14:47?.cache drwx------?3?qiang?qiang?4096?Jul?10?17:20?.config drwxr-xr-x?2?qiang?qiang?4096?Jul?10?14:47?.landscape -rw-r--r--?1?qiang?qiang????0?Jul?10?14:47?.motd_shown -rw-r--r--?1?qiang?qiang??807?Jul?10?14:43?.profile -rw-r--r--?1?qiang?qiang????0?Jul?10?15:54?.sudo_as_admin_successful drwxr-xr-x?2?root??root??4096?Jul?10?18:49?AospCode qiang@LAPTOP-GACS65HF:~$?chmod?777?AospCode/ chmod:?changing?permissions?of?'AospCode/':?Operation?not?permitted qiang@LAPTOP-GACS65HF:~$?chmod?777?AospCode chmod:?changing?permissions?of?'AospCode':?Operation?not?permitted qiang@LAPTOP-GACS65HF:~$?sudo?chmod?777?AospCode [sudo]?password?for?qiang: qiang@LAPTOP-GACS65HF:~$?ls AospCode qiang@LAPTOP-GACS65HF:~$?cd?AospCode/ qiang@LAPTOP-GACS65HF:~/AospCode$?mkdir?~/bin qiang@LAPTOP-GACS65HF:~/AospCode$?PATH=~/bin:$PATH qiang@LAPTOP-GACS65HF:~/AospCode$?curl?https://mirrors.tuna.tsinghua.edu.cn/git/git-repo?-o?~/bin/repo ??%?Total????%?Received?%?Xferd??Average?Speed???Time????Time?????Time??Current ?????????????????????????????????Dload??Upload???Total???Spent????Left??Speed 100?45797??100?45797????0?????0??63784??????0?----?----?----?63695 qiang@LAPTOP-GACS65HF:~/AospCode$?chmod?+x?~/bin/repo qiang@LAPTOP-GACS65HF:~/AospCode$?ls?-la total?8 drwxrwxrwx?2?root??root??4096?Jul?10?21:39?. drwxr-xr-x?7?qiang?qiang?4096?Jul?10?21:39?.. qiang@LAPTOP-GACS65HF:~/AospCode$?mkdir?Aosp12 qiang@LAPTOP-GACS65HF:~/AospCode$?ls Aosp12 qiang@LAPTOP-GACS65HF:~/AospCode$?cd?Aosp12/ qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?ls qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?git?config?--global?user.email?"test987654321@gmail.com" qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?git?config?--global?user.name?"testtest" qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?git?config?--global?url.https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/.insteadof?https://android.googlesource.com qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?export?REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo' qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?repo?init?-u?https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest?-b???android-12.0.0_r3 Downloading?Repo?source?from?https://mirrors.tuna.tsinghua.edu.cn/git/git-repo remote:?Enumerating?objects:?4545,?done. remote:?Counting?objects:?100%?(4545/4545),?done. remote:?Compressing?objects:?100%?(2187/2187),?done. remote:?Total?8138?(delta?4034),?reused?2358?(delta?2358),?pack-reused?3593 Receiving?objects:?100%?(8138/8138),?3.89?MiB?|?1.76?MiB/s,?done. Resolving?deltas:?100%?(5223/5223),?done. repo:?Updating?release?signing?keys?to?keyset?ver?2.3 qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?repo?init?-u?https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest?-b???android-12.0.0_r3 repo:?reusing?existing?repo?client?checkout?in?/home/qiang/AospCode/Aosp12 Testing?colorized?output?(for?'repo?diff',?'repo?status'): ??black????red??????green????yellow???blue?????magenta???cyan?????white ??bold?????dim??????ul???????reverse Enable?color?display?in?this?user?account?(y/N)??y repo?has?been?initialized?in?/home/qiang/AospCode/Aosp12 qiang@LAPTOP-GACS65HF:~/AospCode/Aosp12$?repo?sync remote:?Enumerating?objects:?6509,?done. remote:?Counting?objects:?100%?(6509/6509),?done. remote:?Compressing?objects:?100%?(1982/1982),?done. remote:?Total?80441?(delta?5492),?reused?4154?(delta?4129),?pack-reused?73932 Receiving?objects:?100%?(80441/80441),?17.02?MiB?|?2.41?MiB/s,?done. Resolving?deltas:?100%?(32744/32744),?completed?with?375?local?objects. Fetching:??0%?(4/1040)?4:35?|?4?jobs?|?4:35?platform/art?@?art
?
審核編輯:湯梓紅
評論
查看更多