# ArchLinux_Installation_and_Configure
# 下載Arch ISO
先到交大下載iso映像檔, 然後。。。後面不用我教了吧
[交大 archlinux iso](http://linux.cs.nctu.edu.tw/archlinux/iso/)
# 1 安裝 Arch Linux
## 1.1 分割硬碟
### 1.1.1 查找所有硬碟
```
lsblk
```
### 1.1.2 分配與切割磁碟
選擇要安裝系統的硬碟後使用以下指令分割硬碟的磁區
假設安裝在`sda`這個硬碟上
```
cfdisk /dev/sda
```
將其分配為
<table>
<tr>
<td>Device</td>
<td>Size</td>
<td>Type</td>
</tr>
<tr>
<td>/dev/sda1</td>
<td>550M</td>
<td>EFI System</td>
</tr>
<tr>
<td>/dev/sda2</td>
<td>跟你ram一樣大小</td>
<td>Linux Swap</td>
</tr>
<tr>
<td>/dev/sda3</td>
<td>100G</td>
<td>Linux root (x86-64)</td>
</tr>
<tr>
<td>/dev/sda4</td>
<td>剩下的空間</td>
<td>Linux Home</td>
</tr>
</table>
Linux swap 大小的議題可參考以下鏈接 https://itsfoss.com/swap-size/
## 1.2 格式化磁區
```
# EFI partion
mkfs.vfat /dev/sda1
# swap
mkswap /dev/sda2
# root、home
mkfs.ext4 /dev/sda3
mkfs.ext4 /dev/sda4
```
## 1.3 挂載磁區
```
# 將root mount 到 /mnt
mount /dev/sda3 /mnt
mkdir /mnt/boot
# 將boot mount 到 /mnt/boot
mount /dev/sda1 /mnt/boot
mkdir /mnt/home
# 將home mount 到 /mnt/home
mount /dev/sda4 /mnt/home
```
查看每個分割磁區的filesystem type
```
blkid /dev/sdXX
```
查看是否掛載成功
```
df -h
```
## 1.4 網絡連接
在這個之前,如果你是使用dhcp 或者 wifi的
### 1.4.1 WIFI 設定
```
iwctl
help
device list
device yourdevice set-property Powered on
station yourdevice scan # show nothing
station yourdevice get-networks
station yourdevice connect SSID
```
設定好後可以先ping Google所提供的DNS伺服器IP位址看看是否已經連接
```
ping -c 3 8.8.8.8
```
如果出現以下文字,説明你的網路沒問題,可以跳過這部分
```
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=113 time=10.6 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=113 time=10.4 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=113 time=10.6 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
```
如果沒有,説明你可能是使用固定IP,請跟著以下步驟
### 1.4.2 檢查網路卡
```
ip link show
```
執行結果:
```
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff permaddr XX:XX:XX:XX:XX:XX
```
所以本機的網路卡為 `enp7s0`
假設 Mac Address是 `ff:74:77:69:12:ab`
IP是 `198.111.121.3`
子網路遮罩是 `255.255.255.0`
route server是 `198.111.121.250`
### 1.4.3 設定網路卡實體位址
```
ip link set address ff:74:77:69:12:ab dev enp7s0
```
### 1.4.4 清除網路卡的IP設定
```
ip addr flush dev enp7s0
```
### 1.4.5 設定IP
prefix_len = 24 (255.255.255.0 = 8 + 8 + 8 + 0 = 24)
```
ip address add 198.111.121.3/24 broadcast + dev enp7s0
```
### 1.4.6 查看 IPv4 or IPv6 routes
```
# IPv4
ip route show
# IPv6
ip -6 show
```
### 1.4.7 增加route
```
ip route add default via 198.111.121.250 dev enp7s0
```
### 1.4.8 再次ping看看
```
ping -c 3 8.8.8.8
```
正常來説應該沒問題了
更多網路詳情可參考 https://wiki.archlinux.org/title/Network_configuration
## 1.5 設定 Mirrors Server
### 1.5.1 加入 mirrorlist
用vim /etc/pacman.conf編輯conf文件將,找到[core] [extra] [community]將交大的arch mirrorlist加入
```
[core]
Server = http://archlinux.cs.nctu.edu.tw/$repo/os/$arch
Include = /etc/pacman.d/mirrorlist
[extra]
Server = http://archlinux.cs.nctu.edu.tw/$repo/os/$arch
Include = /etc/pacman.d/mirrorlist
[community]
Server = http://archlinux.cs.nctu.edu.tw/$repo/os/$arch
Include = /etc/pacman.d/mirrorlist
```
### 1.5.2 排序鏡像站
安裝pacman-contrib腳本,這個腳本可以排序鏡像站
```
pacman -Sy pacman-contrib
```
排序"設定檔現有的"鏡像站前6快,並寫入檔案
```
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist
```
將英國和法國前5快的鏡像站,添加至鏡像列表中
```
curl -s "https://archlinux.org/mirrorlist/?country=FR&country=GB&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 - >> /etc/pacman.d/mirrorlist
```
可以將網址中的 `country=FR&country=GB&` 字樣刪除,將國家的篩選條件移除,或是自行更改選項
如果有些套件在安裝中出現類似以下訊息,可能是本機中儲存的鏡像站皆無法找到相依的套件,可以將鏡像站數量提高
```
error: failed retrieving file 'lpsolve-5.5.2.5-4-x86_64.pkg.tar.zst' from mirror.osbeck.com : The requested URL returned error: 404
```
也可以不定時使用這些指令更新鏡像站列表
## 1.6 安裝 base、base-devel、linux和linux-firmware packages
使用pacstrap來運行安裝系統基本組件
```
pacstrap /mnt base base-devel linux linux-firmware
```
正常安裝畫面,如果有出現 erro install pacakages to new root 要重新mount or 重新格式化硬碟比較好
## 1.7 安裝套件並更新套件資料庫資訊
```
pacman -Syy
```
## 1.8 建立Fstab
產生fstab file建立好後可以看一下檔案有沒有存在
```
genfstab -U /mnt >> /mnt/etc/fstab
```
## 1.9 chroot 至新系統
接下來我們要change root to new system
```
arch-chroot /mnt
```
# 2 設定 Arch
## 2.1 設定時區Time zone
```
ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
```
## 2.2 用 hwclock 來產生 /etc/adjtime:
```
hwclock --systohc
```
用 `hwclock --show` 來 check 時間是否正確
## 2.3 設定語言
```
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;
```
記得要執行locale-gen不然進入桌面會沒有英文字,連打字都無法,會很冏
```
locale-gen
```
## 2.4 設定電腦名稱hostname
```
echo "your-pc-name" > /etc/hostname
```
安裝vim
```
pacman -Sy vim
vim /etc/hosts
```
把以下加入/etc/hosts
```
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
127.0.1.1 myhostname.localdomain myhostname
```
## 2.5 建立initial ramdisk
mkinitcpio 是一個script可以幫忙建立Initial ramdisk
```
mkinitcpio -p linux
```
## 2.6 設定 root 密碼
```
passwd
```
## 2.7 設定Bootloader
先安裝grub
```
pacman -Sy grub os-prober efibootmgr
```
os-prober 可以偵測目前已安裝的其他系統,並在之後加入 grub 選單中
```
os-prober
```
```
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
grub-mkconfig -o /boot/grub/grub.cfg
```
注意!!!如果使用MSI主機板的朋友請參考以下的鏈接(不然你reboot後,什麽都不會出現)
https://wiki.archlinux.org/title/GRUB#Default/fallback_boot_path
## 2.8 安裝一些常用套件
```
pacman -Sy git pkgfile bash-completion sudo man
#pkgfile //套件 & 軟體名字不match
#bash-completion //自動補齊 for pacman…等
```
pacman 用法如下
```
# 安裝套件
# -S: sync
pacman -S <package>
# 更新套件(全系統)
# -u: upgrade
# 安裝套件並更新套件資料庫資訊
pacman -Sy <package> # 建議不要這樣使用,可能會造成 dependency issue
pacman -Syu <package> # 建議這樣用
sudo pacman -Syy #類似sudo apt-get update
# 安裝不在檔案庫的 package(例如 AUR 的 package)
pacman -U /path/to/package/package_name-version.pkg.tar.xz
pacman -U http://www.example.com/repo/example.pkg.tar.xz # 也可以從網址安裝
# 移除套件
# -R: remove
pacman -R <package>
# 移除套件及其相依套件
# -s: recursive
pacman -Rs <package>
```
## 2.9 安裝網路工具
```
pacman -Sy net-tools networkmanager wpa_supplicant wireless_tools;
```
## 2.10 重新啟動
離開chroot以前記得把dhcp服務加入systemd 的啟動選項中,如果出現dhcp.service does not exit記得先裝dhcp package or 先systemctl enable dhcpcd
如果是在學校有分配ip的話就不需要enable只要有裝就好
```
sudo pacman -S dhcp dhcpcd
systemctl enable dhcpcd.service
exit
umount -R /mnt
reboot
```
基本上,到這裡就會結束系統的安裝,接下來都是在系統上做設定了。
# 3 再次進入系統的設定
登入
```
username: root
password: 你剛設定的密碼
```
## 3.1 設定永久固定IP
* 方案 1 (dhcpcd)
使用剛安裝的 dhcpcd 設定固定 IP
到 `/etc/dhcpcd.conf` 增加
```
interface eth0
static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8
```
以上只是範例, 請跟著你的需求設定
重啓服務
```
systemctl restart dhcpcd.service
```
執行以下指令後, 不可以出現錯誤
```
systemctl status dhcpcd.service
```
* 方案 2 (NetworkManager)
安裝NetWorkManager
```
pacman -S networkmanager
```
開啟NetWorkManager
```
systemctl enable NetWorkManager;
systemctl start NetWorkManager;
```
如果使用固定ip的使用者,發現重啓後網路就連不上了可透過 nmtui 圖形化設定介面再設定網路(之後應該就不會在連不上了)
```
nmtui
# ethernet
# Mac
# ipv4 -> Mannual
# Address
# GateWay
# DNS
# ipv6 -> disabled
# 記得重新激活activate
# 記得重新激活activate
# 記得重新激活activate
```
## 3.2 建立新的使用者
設定sudo 群組 打開sudoer file並將%wheel ALL=(ALL)前面註解拿掉
```
vim /etc/sudoers
# Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL
```
建立新使用者,並加入 sudo 群組
```
useradd -m -u 1001 "your-user-name"
passwd "your-user-name"
usermod "your-user-name" -G wheel
```
重新開機
```
reboot
```
## 3.3 中文字體
除了設定中文 locale,還要安裝中文字體,才可正確顯示中文
不然你會看到環境界面以及瀏覽器都是會有奇怪的口口出現
這裡建議安裝noto-fonts-cjk 思源黑體,或是文泉驛正黑體(windows用的中文字體),文泉驛微米黑(Android)
```
sudo pacman -Su noto-fonts-cjk adobe-source-code-pro-fonts
```
# 4 安裝 Window Manager(圖形介面)
## 4.1 安裝 i3
```
sudo pacman -Syu
sudo pacman -S i3-gaps i3status nitrogen ttf-dejavu rofi
```
可以依照以下表格自己玩看看哦~
<table>
<tr>
<td>Name</td>
<td>Detail</td>
<td>Recommended</td>
</tr>
<tr>
<td>ttf-dejavu</td>
<td>更好看的字體</td>
<td>y</td>
</tr>
<tr>
<td>i3-gaps</td>
<td>i3的分支,注重於i3的美化 </td>
<td>y</td>
</tr>
<tr>
<td>rofi</td>
<td>圖形化的app/command啟動器 </td>
<td>y</td>
</tr>
<tr>
<td>compton</td>
<td>視窗透明化</td>
<td>y</td>
</tr>
<tr>
<td>nitrogen </td>
<td>更方便的桌布設置</td>
<td>y</td>
</tr>
<tr>
<td>i3-block</td>
<td>更好看的系統狀態列</td>
<td></td>
</tr>
<tr>
<td>i3status</td>
<td>i3的系統狀態列</td>
<td></td>
</tr>
</table>
## 4.2 安裝 xorg
```
sudo pacman -S xorg xorg-xinit xterm
```
<table>
<tr>
<td>Name</td>
<td>Detail</td>
</tr>
<tr>
<td>xorg</td>
<td>includes xorg-server but not xorg-xinit</td>
</tr>
<tr>
<td>xorg-server-utils</td>
<td>doesn’t exist anymore</td>
</tr>
<tr>
<td>xorg-xinit</td>
<td>installs: xorg-xinit, inetutils, includes /etc/X11/xinit/xinitrc</td>
</tr>
<tr>
<td>xorg-apps</td>
<td>group, everything in it is already included in xorg</td>
</tr>
<tr>
<td>xterm</td>
<td>You will probably want/need this</td>
</tr>
</table>
## 4.3 安裝 GPU driver
```
sudo pacman -S nvidia nvidia-utils # NVIDIA
sudo pacman -S xf86-video-amdgpu mesa # AMD
sudo pacman -S xf86-video-intel mesa # Intel
```
## 4.4 安裝音效支援
```
sudo pacman -S alsa-utils
# suggestion of ArchWiki
sudo pacman -S pipewire-pulse
sudo pacman -S pavucontrol
sudo pacman -S pamixer
```
## Starting with Xinit (startx)
更改 /etc/X11/xinit/xinitrc內容為如下所示:
```
.
.
.
#twm &
#xterm....
#exec xterm ....
exec i3
```
接著開啟Xinit
```
startx
```
進入i3後,可以使用預設的 "super+enter" 來啓動terminal,"super+shift+q" 來關閉terminal
super 就是你剛設定的 win or alt鍵
如果要查看或修改指令,請到 `~/.config/i3/config`
## 4.5 設定熒幕不休眠 (optional)
```
sudo pacman -S xorg-xset
xset -dpms
xset s off
```
# 5 系统配置
## 5.1 安裝 LigthDM
用 lightDM 作为系统的 display manager
```
sudo pacman -S lightdm lightdm-gtk-greeter
systemctl enable lightdm
reboot
```
## 5.2 安装主题及相关配置
這裏是使用 lightdm-webkit2-theme-glorious 的主題
```
git clone https://aur.archlinux.org/lightdm-webkit2-theme-glorious.git
cd lightdm-webkit2-theme-glorious
makepkg -sri
```
複製light-theme 到 `/usr/share/lightdm-webkit/themes/glorious`
```
cd ..
sudo cp -r lightdm-webkit2-theme-glorious /usr/share/lightdm-webkit/themes/glorious
```
## 5.3.1 下載 google-chrome 來獲取圖片
先下載`yay`以方便下載`google-chrome`
```
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
```
下載`google-chrome`
```
yay -S google-chrome
```
使用`google-chrome-stable`來啓動 chrome
## 5.3.2 主題背景图片
登录的背景图片位于目录`var/lib/AccountsService/wallpapers`。注意在命令行使用`lightdm-webkit2-greeter`,进入`Setting`,选择`background engine`为`image`。(见`lightdm-webkit2-greeter.conf`文件)。注意文件的权限。
## 5.4 登录头像
用户头像的目录位于`/var/lib/AccountsService/icons`。注意在`/var/lib/AccountsService/users`新建文件$USER,输入以下内容:
```
[User]
Icon=/var/lib/AccountsService/icons/myicon.jpg
```
## 5.5 lightDM 设置
编辑文件`/etc/lightdm/lightdm.conf`,设置`greeter-session=lightdm-webkit2-greeter`
```
.
.
.
# Seat configuration
.
.
[SeatDefaults]
greeter-session=lightdm-webkit2-greeter
.
.
[Seat:*]
```
## 5.6 lightDM-webkit-greeter 配置
修改 /etc/lightdm/lightdm-webkit-greeter.conf
[branding]下面可以修改你的登入背景, 登入logo, 登入頭像 的路徑
```
[greeter]
debug_mode = true
detect_theme_errors = true
screensaver_timeout = 300
secure_mode = true
time_format = LT
time_language = auto
webkit_theme = glorious
[branding]
background_images = /var/lib/AccountsService/wallpapers
logo = /usr/share/pixmaps/archlinux-logo.svg
user_image = /var/lib/AccountsService/icons/myicon.jpg
```
## 5.7 設定雙熒幕
可使用以下指令來檢查monitor
```
xrandr -q
```
假設設備是 `HDMI-1` 和 `DP-2`
```
xrandr --output HDMI-1 --auto --output DP-2 --auto --right-of HDMI-1
```
以上設定是 `HDMI-1` 在左邊,`DP-2` 在右邊
`--auto` 是自動選擇解析圖
可以使用 `--mode 1920x1080` 這樣來設定解析度
## 5.8 双显示器问题
可能存在双显示问题,自写脚本解决。在`/etc/lightdm.conf`,设置`display-setup-script=/usr/bin/lightDMScript.sh`。
```
#!bin/bash
xrandr | grep "HDMI-1 disconnected"
result=$?
if [ $result -gt 0 ]
then
xrandr --output eDP-1 --off --output HDMI-1 --primary --mode 2560x1440 --pos 0x0 --rotate normal --output DP-1 --off --output HDMI-2 --off
else
xrandr --output eDP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output HDMI-1 --off --output DP-1 --off --output HDMI-2 --off
fi
```
## 5.9 背景設定
先安裝 `feh`
```
sudo pacman -S feh
```
假設你的圖片路徑爲`~/Documents/bg.jpg`
到 `~/.config/i3/config` 並加入以下這一行
```
exec --no-startup-id feh --bg-fill ~/Documents/bg.jpg
```
## 5.10 polybar設定
```
git clone https://aur.archlinux.org/polybar.git
cd polybar
makepkg -si
cp -R /etc/polybar ~/.config/polybar
vim ~/.config/polybar/config.ini
```
如果有使用雙熒幕的朋友, 請到到 `[bar/example]` 下面增加一行字
```
.
.
[bar/example]
monitor = ${env:MONITOR:}
.
.
```
然後使用`vim ~/.config/polybar/launch.sh`創建`launch.sh`,來進行設定
```
# launch.sh 內容
if type "xrandr"; then
for m in $(xrandr --query | grep " connected" | cut -d" " -f1); do
MONITOR=$m polybar --reload example &
done
else
polybar --reload example &
fi
```
而後再到`~/.config/i3/config`增加
```
exec sh ~/.config/polybar/launch.sh
```
更多polybar的theme可以參考以下link
https://github.com/adi1090x/polybar-themes
# 6 雙系統 arch + window 10 啓動
如果沒有安裝雙系統的朋友,可以跳過這個part哦~
## 6.1 讓os-prober 可以偵測其他boot
```
sudo vim /etc/default/grub
uncomment GRUB_DISABLE_OS_PROBER=false
```
## 6.2 掛載 Windows
假設`windows10`系統被安裝在`sdb`裏面,而且`sdb1`是它的boot
可使用`lsblk`來確認
```
mkdir /mnt/windows10
mount /dev/sdb1 /mnt/windows10
```
## 6.3 偵測 Windows
```
os-prober
```
## 6.4 產生 grub 設定檔
```
grub-mkconfig -o /boot/grub/grub.cfg
reboot
```
在啓動界面就可以看到一個 `Windows Boot Manager (on /dev/sdb1)`, 點擊他就可以進入windows咯~~
如果覺得開機選單時間太短
```
vim /boot/grub/grub.cfg
```
收尋`set timeout=5` 把時間(5)更改成你想要的時間,如`set timeout=30`
# 7 安裝第三方軟體以及一些基本設定
透過以下的套件我們可以安裝第三方軟體, ex: google-chrome
`yay與paru較為方便,paru安裝時間較久。`
如果在安裝過程,系統說你的權限不足,可是又不能使用`sudo makepkg -si`
```
# 先把該檔案的root變成自己的
# me是你的username
chown -R me /home/me/yay
```
然後在進行`makepkg`的動作,應該就沒問題了
## 7.1 AUR(Ignore me)
```
git clone https://aur.archlinux.org/aurman.git
cd aurman
makepkg -si
```
## 7.2 yay
```
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
```
## 7.3 paru
```
sudo pacman -S --needed base-devel
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
```
## 7.4 snap (optional)
```
git clone https://aur.archlinux.org/snap.git
cd snapd
makepkg -si
```
如果上面失敗了,可使用
```
yay -S snapd
```
Enable snap
```
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
echo "export PATH=\$PATH:\/snap/bin/" | sudo tee -a /etc/profile
```
Start snap
```
sudo systemctl start --now snapd.socket
```
測試
```
sudo snap install hello-world
snap list
sudo snap remove hello-world
```
## 7.5 檔案總管 Thunar
```
sudo pacman -S thunar thunar-volman
sudo pacman -S thunar-archive-plugin xarchiver # 可以右鍵解壓縮
```
而後再到`~/.config/i3/config`增加
```
exec --no-startup thunar --daemon &
```
## 7.6 中文輸入法 fctix
有遇過chrome裝好後無法切換使用新酷音,但在其他編輯器及瀏覽器都可以使用情形,這時候可以用fcitx5-diagnose看一下是哪邊沒裝好~
fcitx5-chewing:新酷音
fcitx5-googlepinyin:google拼音
```
sudo pacman -S fcitx5-im fcitx5-chinese-addons fcitx5-material-color fcitx5-pinyin-zhwiki
```
安裝好後記得在~/.xprofile 新增以下變數, 如果沒有此檔案請要自行建立,
```
input=fcitx5
export XMODIFIERS=@im=fcitx5
export LC_CTYPE=zh_TW.UTF-8
export GTK_IM_MODULE=fcitx5
export QT_IM_MODULE=fcitx5
$input&
```
改好後就重啓
```
reboot
```
fcitx 可使用`ctrl+space`來切換英\中
fcitx5 可使用`ctrl+shift+f`來切換英\中
預設是注音,如果要使用拼音,可以使用`fcitx-configtool`的指令來進行設定
切換的按鍵也可在`fcitx-configtool`進行設定
`google pinyin`可使用`ctrl+shift+f`來進行繁體字與簡體字的切換
reference: https://www.bilibili.com/video/BV1Wu411o7Kd/?vd_source=b812d95e8999d70d8412cb26e9445513
## 7.7 下載`google-chrome`
```
yay -S google-chrome
```
使用 `google-chrome-stable` 打開
## 7.8 rofi
rofi是一個強而有力的搜尋工具
```
sudo pacman -S rofi
```
到 `~/.config/i3/config` 進行配置
```
bindsym $mod+d exec "rofi -modi drun,run -show drun"
# bindsym $mod+d exec --no-startup-id dmenu_run
```
可參考 https://github.com/adi1090x/rofi 進行rofi的配置
launcher/type-2/style 10

# 8 terminal與zsh的設定
terminal的部分,我自己先前是使用rxvt並使用學長的設定(也就是下面的設定啦)
可是我在(2023.03.31)發現以下rxvt的設定有問題,於是我目前是使用另一個terminal, alacritty
## 8.1.1 terminal(rxvt)
```
yay -S rxvt rxvt-unicode
```
在`.Xdefault`進行`rxvt`設定
```
vim ~/.Xdefault
```
可以參考以下設定
```
!# lefthaha s ~/.Xdefaults
!# after modified, use ` xrdb -merage ~/.Xdefaults ` to reload setting
!# then launch `urxvt` again to test
!# turn compile xft on
!#(copy from arch wiki,may increase performance)
!#URxvt.buffered: true
!# set colors
URxvt.background: #0a0a0a
URxvt.foreground: white
URxvt.cursorColor: green
!#URxvt.underlineColor: green
!# set transparency
URxvt.transparent: on
URxvt.shading: 20
!# set fonts
!#URxvt.font: xft:SourceCodePro:style=Regular:size=14
!#URxvt.font:xft:MesloLGS NF:regular:size=12
URxvt.font: xft:MesloLGS NF:size=12
!#URxvt.boldfont: xtf:Meslo LG S DZ for Powerline:bold:size=12
!#URxvt.italicFont: xtf:Meslo LG S DZ for Powerline:Italic:size=12
!#URxvt.boldItalicFont:
URxvt.letterSpace: -1
!# set input method
!#URxvt.inputMethod: gcin
URxvt.preeditType: Root
URxvt.imLocale: zh_TW.UTF-8
!# extern common
URxvt.perl-ext-common: default,clipboard,resize-font,matcher
!## copy, resize, url
!# set clickable URLs
URxvt.urlLauncher : /usr/bin/xdg-open
URxvt.matcher.button : 1
URxvt.matcher.rend.0: Uline Bold fg5
URxvt.colorUL: #4682B4
!# set window size
!#URxvt.geometry: 86x28
!# set misc
URxvt.scrollBar: False
!#URxvt.jumpScroll: True
!#URxvt.cursorUnderline: True
!#URxvt.cursorBlink: True
!# my config
URxvt.iso14755: false
URxvt.iso14755_52: false
!## scrollbak position
URxvt*scrollTtyOutput: false
URxvt*scrollWithBuffer: true
URxvt*scrollTtyKeypress: true
!## scrollbak buffer
URxvt.secondaryScreen: 1
URxvt.secondaryScroll: 0
!## cut and paste
URxvt.clipboard.autocopy: true
URxvt.keysym.M-c: perl:clipboard:copy
URxvt.keysym.M-v: perl:clipboard:paste
!## disable printing the therminal contents when pressing printscreen
URxvt.print-pipe: "cat > /dev/null"
! Tango color palette
URxvt*background: #2e3436
URxvt*foreground: #eeeeec
URxvt*cursorColor: #8ae234
! foreground color for underline
URxvt*colorUL: #8ae234
! line color for underline
URxvt*underlineColor: #92659a
! black dark/light
URxvt*color0: #2e3436
URxvt*color8: #6e706b
! red dark/light
URxvt*color1: #cc0000
URxvt*color9: #ef2929
! green dark/light
URxvt*color2: #4e9a06
URxvt*color10: #8ae234
! yellow dark/light
URxvt*color3: #edd400
URxvt*color11: #fce94f
! blue dark/light
URxvt*color4: #3465a4
URxvt*color12: #729fcf
! magenta dark/light
URxvt*color5: #92659a
URxvt*color13: #c19fbe
! cyan dark/light
URxvt*color6: #07c7ca
URxvt*color14: #63e9e9
! white dark/light
URxvt*color7: #d3d7cf
URxvt*color15: #eeeeec
```
安裝字形
```
yay -S ttf-meslo-nerd-font-powerlevel10k
```
使用`xrdb -merge ~/.Xdefault`來更新`rxvt`的設定
並使用`urxvt`來啓動
如果設定都沒問題,那麼要在開機時要重新進行設定
到`~/.config/i3/config`進行修改和新增
```
# 修改 bindsym $mod+Return exec i3-sensible-terminal
bindsym $mod+Return exec i3-sensible-terminal
# 新增
exec xrdb -merge ~/.Xdefault
```
如果在使用`rxvt`時發現在`vim`無法使用copy&paste別緊張
請在其他程序中(chrome、word...)使用`shift+鼠标左键`进行选择,並使用`shift+insert`到vim的文件下進行粘帖!!
## 8.1.2 alacritty
由於近期(2023.03.31)使用以上的urxvt設定,terminal會怪怪的
因此我轉用alacritty 作爲主力terminal(我就爛)
```
sudo pacman -Sy alacritty
```
到 `~/.config/alacritty/alacritty.yml` 進行設定
`/usr/share/doc/alacritty/example/alacritty.yml` 參考範例
懶惰可以直接到 https://gitlab.com/dwt1/dotfiles/-/blob/master/.config/alacritty/alacritty.yml
複製到 `~/.config/alacritty/alacritty.yml`
安裝 `picom` 來達到terminal到透明效果
```
sudo pacman -Sy picom
```
到 `~/.config/i3/config`加入
```
exec_always --no-startup-id picom
```
將`~/.config/alacritty/alacritty.yml`內的 opacity改成0~1之間 就可以調整terminal透明度
## 8.2 shell (oh-my-zsh)
```
yay -S zsh
yay -S neofetch
```
PowerLevel10k
* Terminal: urxvt (~/.Xdefaults)
* Shell: zsh (~/.zshrc)
## 8.2.1 透過 curl 來讀取已經配置好的設定
```
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```
## 8.2.2 更換主題
1. 編輯 `~/.zshrc`
2. 把 `ZSH_THEME="robbyrussell"` 改成 `ZSH_THEME="ys"`
ys 這個主題目前是我最喜歡的,如果想查看更多其它的主題,可查看 `~/.oh-my-zsh/themes/` 目錄
## 8.2.3 添加 plug-in
比如要把 sudo 加入 plug-in
1. 編輯 `~/.zshrc`
2. 把原本 `plugins=(git)` 改成 `plugins=(git sudo)`
說一下 `sudo` 這個 plug-in ,它的功能很簡單,只要連按兩次 `esc` 鍵,便會自動在指令最前方加上 `sudo`,使用起來十分方便。
## 8.2.4 powerlevel10k 設定
```
#powerlevel10k theme
yay -S --noconfirm zsh-theme-powerlevel10k-git
echo 'source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
```
設定Powerlevel10k
```
zsh
p10k configure
```
Change Shell
```
sudo chsh -s $(which zsh) $(whoami)
```
## 8.2.5 zsh-autosuggestions 設定
在使用kali linux時,覺得它的terminal很好用
在輸入一些指令後面會大致顯示出曾經下過的指令(也就是按tab後自動補齊的文字)
zsh-autosuggestions這個套件就可以達成這個效果

```
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
```
在 `~/.zshrc`裏加入
```
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
```
## 8.2.6 zsh-syntax-highlighting 設定
```
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting
```
在 `~/.zshrc`裏加入
```
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
```
## 8.2.7 安裝字型
```
mkdir -p ~/.local/share/fonts/NerdFonts
cd ~/.local/share/fonts/NerdFonts
wget https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Regular.ttf &&
wget https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Bold.ttf &&
wget https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Italic.ttf &&
wget https://github.com/romkatv/dotfiles-public/raw/master/.local/share/fonts/NerdFonts/MesloLGS%20NF%20Bold%20Italic.ttf
```
這裏建議大家去安裝 Nerd-Fonts, 請參考 https://www.nerdfonts.com/
## 8.2.8 啓動 zsh 時顯示 neofetch
1. 編輯 `~/.zshrc`
2. 添加 `neofetch`
事實上,作用不大,只是爲了耍帥一下XD
# 9 系统主题设置
安装 GTK2/GTK3 主题管理器: lxappearance
```
sudo pacman -S lxappearance
```
可使用 `lxappearance` 指令來選擇你喜歡的主題
## 9.1 GTK 主题选择
更多 GTK 主題可以參考 https://www.gnome-look.org/browse?cat=135
```
yay -S orchis-theme-git
```
## 9.2 ICON 主题选择
更多 icon 主題可以參考 https://www.gnome-look.org/browse?cat=132&ord=latest
```
yay -S papirus-icon-theme
```
## 9.3 QT 主題
QT 主题与 GTK 主题相统一, 首先安装 QT 主题管理器:
```
sudo pacman -S qt5ct
yay -S qt5-styleplugins
```
在~/.xprofile中添加:
```
export QT_QPA_PLATFORMTHEME=gtk2
```
打开qt5ct, 将 QT 主题设置为 gtk2
# 9.4 QT 與 GTK 的設定
```
# GTK settings
lxappearance
# QT settings
qt5ct
```
# 其他可能會用到的東東
## x.1 暫時關閉蜂鳴器(需要權限)
```
rmmod pcspkr
```
## x.2混成器安装
利用`picom`实现透明化及毛玻璃等特效
```
sudo pacman -S picom
```
此部分见配置文件picom.conf,并在 i3 配置文件中设置自启
## x.3 系統監控與進程管理軟件
htop是一個進階的系統監控與進程管理軟件
```
sudo pacman -S htop
```
## x.4 通知管理
安装dunst,作为通知管理的守护进程
```
sudo pacman -S dunst
```
dunst 配置
配置文件位于`~/.config/dunst/dunstrc`
在 i3 中配置`dunstctl action`用来跳转通知(即时通讯软件)。
## x.5 ranger
### x.5.1 主程序安装
```
sudo pacman -S ranger
```
啓動`ranger`來玩看看吧
### x.5.2 设置为默认文件浏览器
由于原始的`ranger.desktop`文件中存在`Terminal=true`,所以修改为由终端模拟器执行`ranger`
```
cp /usr/share/applications/ranger.desktop ~/.local/share/applications/ranger.desktop
vim ~/.local/share/applications/ranger.desktop
```
改变为以下的值
```
Terminal=false
Exec=Exec=alacritty -e ranger
```
在mimeapps.list添加ranger.desktop,并更新数据库
```
update-desktop-database ~/.local/share/applications
```
### x.5.3 在ranger裏加上icon
```
mkdir -p ~/.config/ranger/plugins/ranger_devicons
git clone https://github.com/alexanderjeurissen/ranger_devicons ~/.config/ranger/plugins/ranger_devicons
echo "default_linemode devicons" >> $HOME/.config/ranger/rc.conf
```
## x.6 回收站
```
sudo pacman -S trash-cli
```
回收站位于`~/.local/share/Trash`
更多可參考 https://github.com/andreafrancia/trash-cli
## x.7 磁盘清理工具
```
sudo pacman -S ncdu
```
## x.8 系统状态监视
```
sudo pacman -S conky
```
## x.9 VsCode
`archlinux`不再提供`visual-studio-code-bin`的二进制包,只能手动编译了
```
yay -S visual-studio-code-bin
```
现在`VsCode`自带同步功能,双系统很方便,直接同步
## x.10 office
安装 wps office:
```
yay -S wps-office
yay -S ttf-wps-fonts
```
## x.11 pptpclient
由於我所處於的實驗室是使用`PPTP`的方式來進行VPN
所以在這裏跟大家分享連接`PPTP`的方法
```
sudo pacman -S pptpclient
pptpsetup –create tunnel_name –server vpn.example.com –usrname alice –password pd –encrypt
```
Connect的方法
```
sudo pon tunnel_name
sudo ip route add default dev ppp0
```
Disconnect的方法
```
sudo ip route del default dev ppp0
sudo poff tunnel_name
```
## x.12 更新或想要下載套件,如果出現簽章信任等級不明無法更新
```
sudo pacman -Sy archlinux-keyring && pacman -Syyu
```
## x.13 連接nas
```
sudo pacman -Sy cifs-utils
```
新增儲存NAS資料的folder
```
mkdir /home/user/NAS
```
到 /etc/fstab 新增
```
//nasaddress/yourfile /home/user/NAS cifs auto,user,rw,username=yourusername,password=yourpassword 0 1
```
更新 /etc/fstab
```
mount -a
```
## x.14 discord
```
yay -S discord
```
## x.15 定时任务 crontab
不要小看 crontab
我們常常需要在某些時間做某些事
可是有懶惰爬起來打鍵盤
這時候就可以利用 crontab 來設定在某一時間做某一件事(需要root權限的也可以)
```
yay -S cronie
systemctl enable cronie.service
systemctl start cronie.service
```
更多crontab的設定可以參考鳥哥~
https://linux.vbird.org/linux_basic/centos7/0430cron.php
## x.16 solaar
由於我使用logitech的無線鍵盤與滑鼠
solaar是一個開源的管理工具
好用捏
```
sudo pacman -Sy solaar
```
## x.17 virtualbox
學習linux的路上難免需要進行多次的實驗,虛擬機再也重要不過了
我本人是習慣使用virtualbox,以下是安裝教學
安裝virtualbox,並設定group passwd,而後load virtualbox的kernel
注意:安裝virtualbox,記得選擇 `virtualbox-host-modules-arch`
```
sudo pacman -S virtualbox virtualbox-guest-iso
reboot // 重啓
sudo gpasswd -a $USER vboxusers
sudo modprobe vboxdrv
```
更新系統來取得virtualbox的extension package
```
yay -Syy
yay -S virtualbox-ext-oracle
```
啓動並檢查服務
```
sudo systemctl enable vboxweb.service
sudo systemctl start vboxweb.service
lsmod | grep -i vbox
```
## x.18 安裝 SpaceVim
SpaceVim 是一個進階版的 vim, 而且支持許多程式語言的開發.
```
curl -sLf https://spacevim.org/install.sh | bash
```
可到 https://spacevim.org/layers/colorscheme/#configuration 去參考並選擇自己喜歡的風格
我本人是選擇 `onedark` 風格.
```
vim ~/.SpaceVim/init.toml
```
```
[options]
# ...
# ...
# color_scheme = "gruvbox"
color_scheme = "onedark"
```
## x.19 XDG 用戶目錄
用戶目錄指位於 $HOME下的一系列常用目錄, 例如Documents, Downloads, Music, Desktop等等.
```
xdg-user-dirs-update
```
可到 ~/.config/user-dirs.dirs 或 /etc/xdg/user-dirs.defaults 進行配置
```
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_DESKTOP_DIR="$HOME/Desktop"
XDG_DOWNLOAD_DIR="$HOME/Downloads"
XDG_TEMPLATES_DIR="$HOME/Templates"
XDG_PUBLICSHARE_DIR="$HOME/Public"
XDG_DOCUMENTS_DIR="$HOME/Documents"
XDG_MUSIC_DIR="$HOME/Music"
XDG_PICTURES_DIR="$HOME/Pictures"
XDG_VIDEOS_DIR="$HOME/Videos"
```
## x.20 安裝HP Printer driver
CUPS是Apple公司為了自家的MacOS X和其他類Unix系統搞的一套基於標準的開源印表機系統
首先我們先安裝`cups`套件並啟動`org.cups.cupsd.service`
```
sudo pacman -S cups
sudo systemctl enable --now cups
```
大多數的HP印表機都採用`hplip`套件,內含HP印表機的安裝設定程式
```
sudo pacman -S hplip python-pyqt5
```
開始設定你的printer
```
sudo hp-setup
```
# 參考資料
* https://hackmd.io/Wi2N2PaEReOgQ8SQJVOaFQ
* https://hackmd.io/l5TcrZZmSbeLsFdwEQ84AQ
* https://github.com/shejialuo/OS-Configuration/tree/master/ArchLinux-i3/system_config
* https://github.com/manilarome/lightdm-webkit2-theme-glorious
* https://wusyong.github.io/posts/arch-dual-boot/
* https://forum.endeavouros.com/t/warning-os-prober-will-not-be-executed-to-detect-other-bootable-partitions-systems-on-them-will-not-be-added-to-the-grub-boot-configuration-check-grub-disable-os-prober-documentation-entry/13998
* https://www.reddit.com/r/archlinux/comments/97odv3/error_when_trying_to_install_an_aur_helper/
* https://github.com/polybar/polybar/wiki
* https://github.com/polybar/polybar/issues/763
* https://ankmak.com/tech/arch/oh-my-zsh.html
* https://github.com/andreafrancia/trash-cli
* http://liubin.name/post/vpn_pptp_in_archlinux/
* https://computingforgeeks.com/how-to-install-snap-on-arch-linux-manjaro/
* https://github.com/alexanderjeurissen/ranger_devicons
* https://www.linuxtechi.com/install-virtualbox-on-arch-linux/
* https://wiki.archlinux.org/title/GRUB#Default/fallback_boot_path
* https://spacevim.org/quick-start-guide/
* https://junyussh.github.io/p/arch-linux-install-hp-printer/
* https://unix.stackexchange.com/questions/359531/installing-hp-printer-driver-for-arch-linux