# Arch Linux + Hyprland 安裝
:::info
正確標題:Arch Linux + Hyprland with ML4W Dotfiles 安裝過程
:::
不知道為什麼我用archinstall script都會報錯,所以改成自己手動裝,裝了好幾次才成功把要的東東弄好,所以記錄一下方便下一次重裝
第1次:用archinstall script安裝,無視報錯,結果切換user的頁面會卡死
...
第n次:沒裝iwd,查了很多資料還是連不到wifi
第n+1次:不小心改到權限,2ㄏ2ㄏ
## 下載iso & 製作開機碟
iso下載:
https://archlinux.org/download/
利用Rufus製作開機碟:
https://rufus.ie/zh_TW/
## 安裝Arch Linux
### 設定網路
```bash=
iwctl
# 進入 [iwd] 之後
device list
station [device_name] scan
station [device_name] connect [Network_name]
exit # 連完退出[iwd]
```
### 分割硬碟
```linux=
lsblk #顯示目前硬碟的分割狀態
cfdisk /dev/nvme0n1 #用圖形化介面分割硬碟
```
我的分區
* `/dev/nvme0n1p1`:EFI system
* `/dev/nvme0n1p2`:swap
* `/dev/nvme0n1p3`:root
* `/dev/nvme0n1p4`:home
官方推薦分區

我會再多分一個`/home`
[官方文件解釋](https://wiki.archlinuxcn.org/zh-hant/%E5%88%86%E5%8C%BA#/home)
### 格式化分區
```linux=
# UFI system
mkfs.fat /dev/[partition_name]
mkfs.fat /dev/nvme0n1p1
# swap
mkswap /dev/[partition_name]
mkswap /dev/nvme0n1p2
# root和home
mkfs.ext4 /dev/[partition_name]
mkfs.ext4 /dev/nvme0n1p3
mkfs.ext4 /dev/nvme0n1p4
```
### 掛載分區
```linux=
# root
mount /dev/nvme0n1p3 /mnt
# EFI
mkdir /mnt/efi
mount /dev/nvme0n1p1 /mnt/efi
# home
mkdir /mnt/home
mount /dev/nvme0n1p4 /mnt/home
# swap
swapon /dev/nvme0n1p2
```
### 安裝系統
```linux=
vim /etc/pacman.conf
```
新增鏡像
[隨便選一個Address](https://archlinux.org/mirrorlist/?country=TW&protocol=http&protocol=https&ip_version=4)
```linux=
[core]
Server = http://mirror.archlinux.tw/ArchLinux/$repo/os/$arch
```
### 安裝套件
```linux=
pacstrap /mnt base base-devel linux linux-firmware
```
然後可以更新一下
```linux=
pacman -Syu
```
### 配置系統
#### Fstab
```linux=
genfstab -U /mnt >> /mnt/etc/fstab
```
#### chroot到新系統
```linux=
arch-chroot /mnt
```
#### 設定時區
```linux=
ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
hwclock --systohc
```
#### 設定語言
```linux=
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen;
echo "zh_TW.UTF-8 UTF-8" >> /etc/locale.gen;
echo "LANG=en_US.UTF-8" > /etc/locale.conf;
```
||[`>` 和 `>>` 的差別](https://blog.csdn.net/wenxuechaozhe/article/details/52564394) (對,我不知道)||
接著執行 locale-gen 以生成 locale 資訊:
```linux=
locale-gen
```
#### 設定電腦名稱
```linux=
echo "your-pc-name" > /etc/hostname
```
安裝vim
```linux=
pacman -Sy vim
vim /etc/hosts
```
然後寫入
```linux=
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.1.1 myhostname.localdomain myhostname
```
#### Initramfs
```linux=
mkinitcpio -p linux
```
#### 設定 Root 密碼
```linux=
passwd
```
#### 設定 Bootloader
```linux=
pacman -Sy grub os-prober efibootmgr
os-prober
# for BIOS
grub-install /dev/sda
# for UEFI
grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=grub
grub-mkconfig -o /boot/grub/grub.cfg
```
#### 安裝網路工具
```linux=
pacman -S net-tools dhclient dhcp
wpa_supplicant wireless_tools
dhcpcd
pacman -S iwd # 連無線網路好用
```
#### 常用 package
:::spoiler
```bash=
vim # text editor
pkgfile # 檢查官方軟件倉庫中軟體包文件的工具
bash-completion # 按tab會幫你打字的東東
sudo # substitute user do 你懂的
git # 讓你可以git別人的東東
```
:::
#### pacman 筆記
:::spoiler
```linux=
# 安裝
pacman -S [package_name]
pacman -S [package_name1] [package_name2] [package_name3]
# 同步
pacman -Sy
# 更新
pacman -Su
# 同步 + 更新全部 package
pacman -Syu
# 移除沒安裝的 cached package
pacman -Sc
# 移除所有在cache資料夾的檔案
pacman -Scc
# 移除 package
pacman -R [package_name]
# 把 dependencies 一起移除
pacman -Rs [package_name]
```
:::danger
如果只做 `pacman -Sy`,可能會造成dependency issue
:::
#### 重新啟動
```linux=
systemctl enable dhcpcd.service
exit
umount -R /mnt
reboot
```
## 好耶開機
### 設定網路
```linux=
# 啟動 iwd 服務
sudo systemctl start iwd
iwctl
# 後面就跟安裝的時候一樣步驟設定網路
```
### 設定新 user
```linux=
# 新增使用者
sudo useradd -m -G wheel -s /bin/bash username
# 設定使用者密碼
sudo passwd username
```
### 新增權限
```linux=
usermod -aG wheel username
visudo
```
進去檔案編輯之後
把這行的註解刪掉
```linux=
# %wheel ALL=(ALL) ALL
```
變成這樣
```linux=
%wheel ALL=(ALL) ALL
```
檢查權限
```linux=
sudo -lU ostechnix
```
:::warning
如果碰到錯誤
`visudo: no editor found (editor path = /usr/bin/vi)`
可以利用下面指令將預設editor從`vi`改成`vim`
(如果你有vim的話)
```linux=
ln -s /usr/bin/vim /usr/bin/vi
```
或是安裝`vi`
```linux=
pacman -S vi
```
:::
## 安裝 Hyprland
> 記得不要用root裝
### 安裝 git
```linux=
sudo pacman -S git
```
### 安裝||~~帕魯~~||paru
有兩種方法安裝
#### 用AUR裝
:::spoiler
```linux=
sudo git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
```
:::warning
如果makepkg時碰到
```linux=
==> Missing dependcies:
->cargo
==> ERROR: Could not resolve all dependcies.
```
安裝rustup
```linux=
sudo pacman -S rustup
```
然後你可能又會碰到
```linux=
error: rustup could not choose a version of rustc to run, because one wasn't specified explicitly, and no default is configured.
help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain.
```
就按照他說的跑
```linux=
rustup default stable
```
:::
#### 用yay||師傅||裝
:::spoiler
我不是用這方法,但大概邏輯是這樣
```linux=
sudo git clone https://aur.archlinux.org/yay-git.git
cd yay-git/
sudo chown -R username:username ~/yay-git
makepkg -si
# 裝好之後
yay -S paru
```
:::
### 安裝 ml4w
```linux=
paru -S ml4w-hyprland
```
### 讓他慢慢跑
```linux=
ml4w-hyprland-setup
```
基本上介面淺顯易懂
選擇你要的設定就好了
### 好了

## 一些我碰到的問題
### WARNING: Possibly missing firmware for module: 'XXXXX'
自己對照一下去下載對應的檔案
https://wiki.archlinux.org/title/Mkinitcpio#Possibly_missing_firmware_for_module_XXXX
### Discord 不能打中文
如果你已經裝了fcitx5注音但還是不能打中文
可以試試看這個方法
#### 找到啟動設定檔
```linux=
find /usr/share/applications ~/.local/share/applications -name "*discord*.desktop"
```
#### 編輯
```linux=
vim /usr/share/applications/discord.desktop
```
#### 在 `Exec=/usr/bin/discord` 後面加上 `--enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime`
```linux=
Exec=/usr/bin/discord --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime
```
### 設定連結開啟預設瀏覽器
```linux=
xdg-settings set default-web-browser microsoft-edge.desktop
```
## Reference
### 大部分內容節錄自:
* [Arch Linux官方文件](https://wiki.archlinux.org/title/Installation_guide_(%E6%AD%A3%E9%AB%94%E4%B8%AD%E6%96%87))
* [Arch linux 安裝 (By Eric Lin)](https://hackmd.io/@PIFOPlfSS3W_CehLxS3hBQ/r1xrYth9V)
* [ML4W Dotfiles 2.9.6 as AUR. Easy installation of HYPRLAND for Arch Linux, Garuda, Manjaro and more (By My Linux For Work)](https://youtu.be/6B4Kf30CWLg?si=0OZR_RfVwf5FbHJG)