# 在WSL2安裝Arch Linux(2023 ver.)
## 安裝
1. 參考Mircosoft官方寫的wsl2啟用網站[https://learn.microsoft.com/zh-tw/windows/wsl/install]()
2. 到github的[ArchWSL2](https://github.com/sileshn/ArchWSL2)下載安裝檔
3. 解壓縮後在目的地的資料夾點選"Arch.exe"安裝
4. 進入Powerbash更改預設啟動(非必要, 可選)
`wsl --unregister Ubuntu`(刪除預設的Ubuntu)
`wsl --set-default Arch`(設定啟動時預設以Arch啟動)
## 初步設定Arch
### 啟動Arch
```bash
wsl -d Arch #啟動Arch
```
然後進入自動安裝流程
### 更新pacman
```bash=
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman -S archlinux-keyring
sudo pacman -Syu
```
### 安裝必要程式
```bash=
sudo pacman -S base base-devel vim git wget neofetch zsh nano bash-completion
```
### 安裝yay
```bash=
cd /opt
sudo git clone https://aur.archlinux.org/yay.git
sudo chown -R $USER:users ./yay # '$USER'要替換為使用者的名字
cd yay
makepkg -si
```
### 設定zsh
```bash=
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#安裝oh my zsh
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
#安裝powerlevel10k主題
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
#安裝zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
#安裝zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
#安裝zsh-completions
vim ~/.zshrc
#進入設定
```
In zshrc:
```bash=
ZSH_THEME="powerlevel10k/powerlevel10k"
plugins=(git archlinux adb npm node zsh-syntax-highlighting zsh-autosuggestions zsh-completions)
#為zsh-completions在文件最下面加上這句話
autoload -U compinit && compinit
```
### 設定語言(在檔案新增#後的文字)
```bash=
sudo vim /etc/locale.gen
#en_US.UTF-8 UTF-8
#zh_TW.UTF-8 UTF-8
sudo vim /etc/locale.conf
#LANG=en_US.UTF-8
sudo locale-gen
```
### 安裝輔助軟體
```bash=
sudo pacman -S htop pv ccze
```
### 安裝KDE(尚未嘗試完成)
```bash=
wget https://diii.neocities.org/xfce.txt
chmod +x xfce.txt
sh xfce.txt
```
然後安裝[VcXsrv](https://sourceforge.net/projects/vcxsrv/)並使用default設定開啟
接著:
```bash=
export DISPLAY=$(cat /mnt/wsl/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0
export LIBGL_ALWAYS_INDIRECT=1
startxfce4
```
## 系統備份
```bash=
sudo pacman -S rsync
rsync -aAXHv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup
```
## 系統
### 重啟
In Powershell
```bash=
Get-Service LxssManager | Restart-Service
```
### 關閉
```bash=
wsl --shutdown
```
## Reference
1. [https://github.com/sileshn/ArchWSL2/blob/main/README.md]()
2. [https://gist.github.com/ld100/3376435a4bb62ca0906b0cff9de4f94b]()
3. [https://dev.to/jrcharney/how-to-install-arch-linux-for-wsl-184a]()
4. [https://blog.rin.moe/arch-wsl/]()
5. [https://www.linuxadictos.com/zh-TW/yay-como-instalar-este-asistente-de-aur-en-distros-basadas-en-arch-linux.html]()
6. [https://zhuanlan.zhihu.com/p/613454594]()
7. [https://hackmd.io/@PIFOPlfSS3W_CehLxS3hBQ/r1xrYth9V]()
8. [https://linux.cn/article-14846-1.html]()
9. [https://mycomputernest.wordpress.com/2020/10/25/install-and-configure-arch-linux-in-wsl-wsl2-with-gui/]()
10. [https://www.jianshu.com/p/23104ab4fa67]()
11. [https://ivonblog.com/posts/install-archlinux/#26-%E5%AE%89%E8%A3%9Dkde%E6%A1%8C%E9%9D%A2%E7%92%B0%E5%A2%83]()
12. [https://wiki.archlinuxcn.org/wiki/Rsync#As_a_backup_utility]()
13. [https://bbs.archlinuxcn.org/viewtopic.php?id=13677]()
14. [https://zhuanlan.zhihu.com/p/51270874]()
15. [https://github.com/microsoft/WSL/issues/8842]()