Last updated on 3 years ago
前言
之前安裝雙系統Arch感覺太麻煩,加上我對Linux需求不大,就開始使用WSL來作爲補充了。現在主要是在WSL寫blog,然後就沒有了,畢竟我不是程序猿,加上我菜菜,安裝這一部分都copy來的再加上一點修改。
來個neofetch

安裝前準備
先安裝個Windows Terminal,這個東西是比較好用且好看的terminal了。
再安裝powershell 7.
使用管理員powershell啓用WSL
1
| dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
|
然後輸入這一行啓用虛擬平臺然後重啓
1
| dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
|
然後在這裏下載Linux内核升級包並安裝。
然後在管理員pswh設置wsl版本為2
1
| wsl --set-default-version 2
|
安裝scoop
scoop是Windows下的包管理軟件,方便對一些免安裝軟件的一鍵(一行)安裝,十分方便。
打開powershell 7,輸入
1 2
| Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh') #安裝scoop
|
添加Extra repo
安裝LxRunOffline
只要一句話即可搞定
1
| scoop install lxrunoffline
|
安裝Arch Linux WSL
先準備文件夾放Arch Linux,如我放在c盤根目錄。
然後從清華tuna源下載Arch Linux bootstrap iso。
下載好之後在Powershell 7中敲打
1 2 3
| LxRunOffline i -n <您喜歡的系統名> -f <Arch iso位置目錄> -d <安裝系統的位置> -r root.x86_64 #示例 LxRunOffline i -n ArchLinux -f C:\Users\rin\Downloads\archlinux-bootstrap-2021.06.01-x86_64.tar.gz -d C:\ArchLinux -r root.x86_64
|
完成後就系統裝好了
最後需要將系統設置成wsl2
1 2
| wsl --set-version ArchLinux 2 #wsl --set-version <您自定義的系統名> 2
|
配置系統
先進系統
1 2 3
| wsl -d <您自定義的系統名>
wsl -d ArchLinux
|
然後刪除/etc/resolv.conf
重啓虛擬機
1 2 3 4 5 6
| exit
wsl --shutdown ArchLinux
wsl -d ArchLinux
|
添加軟件源及安裝必要軟件
在Arch中輸入
1 2 3
| cd /etc/ explorer.exe .
|
找到pacman.conf
利用記事本或vs code打開進行修改,在最後添加:
1 2
| [archlinuxcn] Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
|
然後在/etc/pacman.d/
中找到mirrorlist
,用vs code打開,將喜愛的中國内的源的注釋(也就是#)打掉
然後在Terminal執行以下操作
1 2 3 4 5
| pacman -Syy pacman-key --init pacman-key --populate pacman -S archlinuxcn-keyring pacman -S base base-devel vim git wget yay neofetch zsh nano
|
設置賬戶
先給root賬戶設置密碼,在Terminal輸入
然後建立普通賬戶
1 2
| useradd -m -G wheel -s /bin/bash <用戶名> passwd <用戶名>
|
然後将文件/etc/sudoers
中的%wheel ALL=(ALL) ALL
那一行前面的注釋(#)去掉
查看當前用戶id,記下這個id
然後按exit退出系統,在powershell執行
1
| lxrunoffline su -n <您的arch名字> -v <用戶id>
|
對Shell做人性化處理
前面安裝了zsh,直接安裝oh my zsh。接下來就是一氣呵成配置了。
1 2 3 4
| sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
|
在 ~/.zshrc
設置
1 2 3 4
| ZSH_THEME="powerlevel10k/powerlevel10k" plugins=(git archlinux adb npm node zsh-syntax-highlighting zsh-autosuggestions zsh-completions)
autoload -U compinit && compinit
|
然後安裝部分上述插件
1 2 3 4 5 6
| git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
|
這樣就大功告成了
未解決的bug
即使安裝了powerline字體還是無法顯示powerline的特殊字符,讓我覺得奇怪
參考資料
https://zhuanlan.zhihu.com/p/266585727
https://ohmyz.sh/
https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins
https://github.com/zsh-users/zsh-syntax-highlighting
https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md
https://github.com/zsh-users/zsh-completions