天天看點

win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令

win10添加 Microsoft store中自帶的Ubuntu18.04

在win10的系統有支援linux核心的工具wsl

在工作列總搜尋“功能”

win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令
win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令

勾選适用于Linux的windows子系統;等待更新。

然後在Microsoft store中查找Ubuntu

win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令

我這裡使用的是18.04,是以主要說下這個版本的。

下載下傳好之後,等待安裝、重新開機電腦、win鍵中會有一個Ubuntu的圖示以後使用時便可以點選這裡進去

附加:更新wsl、啟用systemctl(該版本預設未啟用)、安裝docker

系統設定中找到"更新與安全"--->将版本更新至最新版(可能需要30 - 60min)

之後參考官方的文檔來操作:

https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

https://discourse.ubuntu.com/t/using-snapd-in-wsl2/12113

win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令

運作以上兩行指令(切記使用管理者身份)

這裡就是進行了兩項設定:make sure that both the Virtual Machine Platform and Windows Subsystem for Linux optional components are installed.

大概就是啟用了了Virtual Machine Platform and Windows Subsystem 這兩個

然後将wsl的版本更新到2.0版本,還是在PowerShell中或者cmd中(管理者身份)

win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令

<Distro> 這個參數使用 wsl -l來檢視;例如:

win10添加 Microsoft store中自帶的Ubuntu18.04、啟用systemctl指令

啟用systemctl

https://discourse.ubuntu.com/t/using-snapd-in-wsl2/12113

進入到Ubuntu系統中,運作一下兩行指令:

sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
           
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME
           

具體含義可以參考官網的文檔!

現在就可以是用systemctl 指令了;

繼續閱讀