筆者發(fā)現(xiàn)使用wsl(Windows Subsystem for Linux,適用于 Linux 的 Windows 子系統(tǒng))編譯openharmony鏡像比傳統(tǒng)虛擬機(jī)快3倍以上。編譯環(huán)境換成wsl后,編譯ohos只需要傳統(tǒng)虛擬機(jī)上三分之一的時(shí)間。下面分享使用經(jīng)驗(yàn)如下:
為什么使用WSL2比傳統(tǒng)虛擬機(jī)編譯OpenHarmony快?
以下是微軟官方給的解釋:https://learn.microsoft.com/zh-cn/windows/wsl/about
-
Windows Subsystem for Linux(適用于 Linux 的 Windows 子系統(tǒng))可讓開發(fā)人員按原樣運(yùn)行 GNU/Linux 環(huán)境 - 包括大多數(shù)命令行工具、實(shí)用工具和應(yīng)用程序 - 且不會(huì)產(chǎn)生傳統(tǒng)虛擬機(jī)或雙啟動(dòng)設(shè)置開銷。
-
WSL2使用最新、最強(qiáng)大的虛擬化技術(shù)在輕量級(jí)實(shí)用工具虛擬機(jī) (VM) 中運(yùn)行 Linux 內(nèi)核。但是,WSL2不是傳統(tǒng)的 VM 體驗(yàn)。
-
傳統(tǒng)的 VM 體驗(yàn)可能啟動(dòng)速度慢,是獨(dú)立的,消耗大量資源,需要你花費(fèi)時(shí)間進(jìn)行管理。WSL 2 沒有這些屬性。
以下是筆者的感受:
具體點(diǎn)說就是編譯openharmony時(shí)cpu的利用率可以達(dá)到90%以上。而且編譯直接占用的是電腦的內(nèi)存,而不是給傳統(tǒng)虛擬機(jī)上分配的內(nèi)存。
而傳統(tǒng)虛擬機(jī)還要設(shè)置虛擬機(jī)參數(shù),性能是受到制約的。
配置WSL環(huán)境
檢查運(yùn)行 WSL 2 的要求
若要更新到 WSL 2,需要運(yùn)行 Windows 10。
-
對(duì)于 x64 系統(tǒng):版本 1903 或更高版本,內(nèi)部版本為 18362 或更高版本。
-
對(duì)于 ARM64 系統(tǒng):版本 2004 或更高版本,內(nèi)部版本為 19041 或更高版本。
或 Windows 11。
若要檢查 Windows 版本及內(nèi)部版本號(hào),選擇 Windows 徽標(biāo)鍵 + R,然后鍵入“winver”,選擇“確定”。
安裝 WSL 命令
現(xiàn)在,可以在管理員 PowerShell 或 Windows 命令提示符中輸入此命令,然后重啟計(jì)算機(jī)來安裝運(yùn)行適用于 Linux 的 Windows 子系統(tǒng) (WSL) 所需的全部?jī)?nèi)容。
wsl --install
(左右移動(dòng)查看全部?jī)?nèi)容)
啟用適用于 Linux 的 Windows 子系統(tǒng)
需要先啟用“適用于 Linux 的 Windows 子系統(tǒng)”可選功能,然后才能在 Windows 上安裝 Linux 分發(fā)。
以管理員身份打開 PowerShell(“開始”菜單 >“PowerShell” >單擊右鍵 >“以管理員身份運(yùn)行”),然后輸入以下命令:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
(左右移動(dòng)查看全部?jī)?nèi)容)
啟用虛擬機(jī)功能
安裝 WSL 2 之前,必須啟用“虛擬機(jī)平臺(tái)”可選功能。計(jì)算機(jī)需要虛擬化功能才能使用此功能。
以管理員身份打開 PowerShell 并運(yùn)行:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
(左右移動(dòng)查看全部?jī)?nèi)容)
按要求重啟使設(shè)置生效。
下載 Linux 內(nèi)核更新包
1.下載最新包:
適用于 x64 計(jì)算機(jī)的 WSL2 Linux 內(nèi)核更新包
2.運(yùn)行上一步中下載的更新包。(雙擊以運(yùn)行 - 系統(tǒng)將提示你提供提升的權(quán)限,選擇“是”以批準(zhǔn)此安裝。)
將 WSL 2 設(shè)置為默認(rèn)版本
使用 wsl --install 命令安裝的新 Linux 安裝將默認(rèn)設(shè)置為 WSL 2。
wsl --set-default-version 2
(左右移動(dòng)查看全部?jī)?nèi)容)
安裝所選的 Linux 分發(fā)
打開 Microsoft Store,并選擇你偏好的 Linux 分發(fā)版。
編譯openharmony只能安裝Ubuntu 20.04和Ubuntu 18.04
首次啟動(dòng)新安裝的 Linux 分發(fā)版時(shí),將打開一個(gè)控制臺(tái)窗口,系統(tǒng)會(huì)要求你等待一分鐘或兩分鐘,以便文件解壓縮并存儲(chǔ)到電腦上。未來的所有啟動(dòng)時(shí)間應(yīng)不到一秒。
然后,需要為新的 Linux 分發(fā)版創(chuàng)建用戶帳戶。
wsl2到底安裝在windows系統(tǒng)的那個(gè)位置呢?
C:Users用戶名AppDataLocalPackagesCanonicalGroupLimited.Ubuntu18.04LTS_79rhkp1fndgscLocalState
切換源
在Linux終端輸入命令
sudo vim /etc/apt/sources.list
(左右移動(dòng)查看全部?jī)?nèi)容)
把etc/apt/sources.list文件內(nèi)容清楚,換下述其中一個(gè)源。(以下是vim的使用)
-
按一下字母「i」就可以進(jìn)入「插入模式(Insert mode)」,就可以開始輸入文字了。
-
編輯好后按ESC鍵退出。
-
最后鍵盤輸入:wq,然后文件存盤并退出vim。
#163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#阿里云源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
#清華源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
(左右移動(dòng)查看全部?jī)?nèi)容)
筆者換的是清華源。
最后更新源
sudo apt update
sudo apt upgrade
(左右移動(dòng)查看全部?jī)?nèi)容)
在windowsx下的vscode里面下載好remote - wsl拓展
還可以通過使用 VS Code 中的快捷方式 CTRL+SHIFT+P 調(diào)出命令面板,以訪問更多 VS Code 遠(yuǎn)程選項(xiàng)。
使用WSL1編譯OpenHarmony可以嗎?
編譯不了,筆者已經(jīng)踩過坑了。
比較 WSL 1 和 WSL 2:
使用wsl2編譯openharmony鏡像
源碼獲取和編譯工具安裝的部分不多作介紹了,社區(qū)有很多優(yōu)秀的參考文章值得參考。
提示:本文由電子發(fā)燒友社區(qū)發(fā)布,轉(zhuǎn)載請(qǐng)注明以上來源。如需社區(qū)合作及入群交流,請(qǐng)?zhí)砑游⑿臙EFans0806,或者發(fā)郵箱[email protected]。
更多熱點(diǎn)文章閱讀
- 鴻湖萬聯(lián)產(chǎn)品推薦官招募!啟鴻OpenHarmony開發(fā)板免費(fèi)體驗(yàn)
- 國(guó)產(chǎn)龍芯 LoongArch 平臺(tái)已初步支持OpenHarmony操作系統(tǒng)
- 在DAYU200上實(shí)現(xiàn)OpenHarmony視頻播放器
- 九聯(lián)科技發(fā)布搭載OpenHarmony 3.1小型系統(tǒng)終端設(shè)備半球機(jī)攝像頭和槍機(jī)攝像頭
- HUAWEI AppGallery Connect全新升級(jí),支持HarmonyOS生態(tài)全生命周期服務(wù)!
END
想了解更多開源技術(shù)?后臺(tái)留言,立刻安排!就喜歡獎(jiǎng)勵(lì)一個(gè)“”和“在看”唄~
原文標(biāo)題:使用WSL2編譯OpenHarmony DAYU200鏡像效率翻倍
文章出處:【微信公眾號(hào):電子發(fā)燒友開源社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
-
OpenHarmony
+關(guān)注
關(guān)注
25文章
3753瀏覽量
16673
原文標(biāo)題:使用WSL2編譯OpenHarmony DAYU200鏡像效率翻倍
文章出處:【微信號(hào):HarmonyOS_Community,微信公眾號(hào):電子發(fā)燒友開源社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
OpenHarmony源碼編譯后燒錄鏡像教程,RK3566鴻蒙開發(fā)板演示
![<b class='flag-5'>OpenHarmony</b>源碼<b class='flag-5'>編譯</b>后燒錄<b class='flag-5'>鏡像</b>教程,RK3566鴻蒙開發(fā)板演示](https://file1.elecfans.com/web3/M00/04/41/wKgZO2dyAH2AFFx6AAB2FN45Lh8124.png)
dayu200 rk3568 openharmony5.0 sim卡 通話服務(wù)
用SecureCRT連接串口卻沒有登錄Ubuntu界面
【米爾-瑞米派 Remi Pi 創(chuàng)意秀】 01 - 開發(fā)環(huán)境搭建
【龍芯2K0300蜂鳥板試用】OpenHarmony代碼
[2K300適配OpenharmonyV4.1]根文件系統(tǒng)制作請(qǐng)教
潤(rùn)開鴻“龍芯+OpenHarmony”開發(fā)平臺(tái)DAYU431先鋒派新品發(fā)布
![潤(rùn)開鴻“龍芯+<b class='flag-5'>OpenHarmony</b>”開發(fā)平臺(tái)<b class='flag-5'>DAYU</b>431先鋒派新品發(fā)布](https://file1.elecfans.com//web2/M00/01/F0/wKgaomazGRqANL8jABIkVTw-o4o792.png)
OpenHarmony之開機(jī)優(yōu)化
在wsl2中安裝的idf,在monitor時(shí)會(huì)報(bào)錯(cuò)的原因?
鴻蒙OpenHarmony開發(fā):【編譯構(gòu)建指導(dǎo)】
![鴻蒙<b class='flag-5'>OpenHarmony</b>開發(fā):【<b class='flag-5'>編譯</b>構(gòu)建指導(dǎo)】](https://file1.elecfans.com/web2/M00/BB/D3/wKgaomWWcCGAPFfJAABSkqmLjyM439.jpg)
鴻蒙OpenHarmony【標(biāo)準(zhǔn)系統(tǒng) 編譯】(基于RK3568開發(fā)板)
![鴻蒙<b class='flag-5'>OpenHarmony</b>【標(biāo)準(zhǔn)系統(tǒng) <b class='flag-5'>編譯</b>】(基于RK3568開發(fā)板)](https://file1.elecfans.com/web2/M00/C9/99/wKgaomYeL0WAZFDHAAACSiKnE8w930.jpg)
【鴻蒙】OpenHarmony運(yùn)行docker詳細(xì)步驟
![【鴻蒙】<b class='flag-5'>OpenHarmony</b>運(yùn)行docker詳細(xì)步驟](https://file1.elecfans.com/web2/M00/C2/57/wKgZomXh0VCACWOzAAZrDdB3vEI484.png)
OpenHarmony鴻蒙應(yīng)用如何使用滾動(dòng)類組件
![<b class='flag-5'>OpenHarmony</b>鴻蒙應(yīng)用如何使用滾動(dòng)類組件](https://file1.elecfans.com//web2/M00/C0/D0/wKgZomXYsuCAL1fZAALr7TRuZmo976.png)
評(píng)論