# Tips for Archlinux installation
## Prerequisite
1. security boot is disabled
2. boot in UEFI mode
## Network
check network interfaces:
```bash
ip link
```
start dhcpcd service:
```
start dhcpcd
```
check dns
```
cat /etc/resolv.conf
```
check network connection:
```
ping www.baidu.com
```
**Note**: Remember to setup the network config before exit the archiso!
```bash
pacman -S dhcpcd net-tools iproute2
```
## GPT Partition
recommand `parted`.
### check current disks:
```bash
lsblk
# or
fdisk -l
```
take `/dev/nvme0n1` for example, enter `parted` interactive command line:
```bash
parted /dev/nvme0n1
```
### create efi partition
```bash
(parted) mkpart primary fat32 1MiB 261MiB
(parted) set 1 esp on
```
## create data partition
```bash
(parted) mkpart primary ext4 261MiB 100%
```
more partition examples : https://wiki.archlinux.org/index.php/Parted#UEFI/GPT_examples
## format
```bash
mkfs.fat -F32 /dev/nvme0n1p1 # efi partition
mkfs.ext4 /dev/nvme0n1p2 # data partition
```
if you created a swap partition:
```bash
mkswap /dev/sdX2
swapon /dev/sdX2
```
## Setup chroot environment
### mount partition:
```bash
mount /dev/nvme0n1p2 /mnt
mkdir /mnt/boot
mount /dev/nvme0n1p1 /mnt/boot
```
### generate fstab:
```bash
genfstab -U /mnt >> /mnt/etc/fstab
```
### datetime sync
datetime **must** synced using ntp service before install packages:
```bash
timedatectl set-ntp true
# check status, until system clock is synced.
timedatectl status
```
install base packages to `/mnt`:
```bash
pacstrap /mnt base linux linux-firmware
```
### chroot
```shell
arch-chroot /mnt
```
## Config system
### timezone
```sh
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc
```
### localization
edit `/etc/local.gen` uncomment `en_US.UTF-8 UTF-8` and `zh_CN.UTF-8 UTF-8`
then:
```bash
locale-gen
```
edit the environment: `/etc/locale.conf`
```conf
LANG=en_US.UTF-8
LC_CTYPE=zh_CN.UTF-8
```
### kernel and boot loader
#### Initramfs
```bash
mkinitcpio -P
```
#### systemd-boot
```bash
bootctl install
```
config boot options:
1. `/boot/loader/loader.conf`:
```
default arch
timeout 4
console-mode max
```
2. `/boot/loader/entries/arch.conf`:
```
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=PARTUUID=14420948-2cea-4de7-b042-40f67c618660 rw
```
2.1 PARTUUID can be achieved via:
```
blkid -s PARTUUID -o value /dev/nvme0n1p2
```
2.2 you can add microcode parameters if you want: https://wiki.archlinux.org/index.php/Microcode
### other essential
```bash
passwd # set up root passwod
```
prepare the network environment for current system:
```bash
pacman -S dhcpcd net-tools iproute2
```
### exit and restart
```bash
exit # exit the chroot
reboot # reboot system
```
## pacman init
select the best mirrors from `/etc/pacman.d/mirrorlist`.
initialize the gpg key:
```
pacman-key --init
pacman-key --populate archlinux
pacman -Syyu
pacman -S archlinux-keyring
```
**troubleshooting**: `Key BD8984D2 was created x seconds in the future`:
make sure system time is UTC, delete current gnupg keys, sync datetime then retry.
```bash
rm -rf /etc/pacman.d/gnupg
timedatectl set-ntp true
```
## archlinuxcn && yaourt
edit `/etc/pacman.conf`, add following:
```ini
[archlinuxcn]
Server = https://repo.archlinuxcn.org/$arch
```
then run:
```bash
pacman -Syy
pacman -S archlinuxcn-keyring
pacman -S base-devel yaourt
```
## user management
add a non-admin user:
```bash
useradd -m -G wheel -s /bin/bash kevin
passwd kevin # set up password
```
run `visudo` then uncomment one of following lines to allow `wheel` group using `sudo`
```bash
# %wheel ALL=(ALL) ALL
# %wheel ALL=(ALL) NOPASSWD: ALL
```
## Xorg
```bash
pacman -S xorg-server
```
## Display drivers
find your devices:
```bash
lspci | grep -e VGA -e 3D
```
### intel
```bash
pacman -S xf86-video-intel mesa
```
### nvidia
```bash
pacman -S nvidia nvidia-utils
```
### reboot
**must** reboot.
more details: https://wiki.archlinux.org/index.php/Xorg#Installation
## i3wm
### install
```bash
pacman -S i3-gaps # or i3-wm
```
### startx
```bash
pacman -S xorg-xinit
```
make sure you are non-root user:
```bash
su kevin
```
cp the default config to user dir:
```bash
cp /etc/X11/xinit/xinitrc ~/.xinitrc
```
edit `~/.xinitrc` replace:
```bash
twm & ...
exec xterm ...
```
with:
```bash
exec i3
```
### config
pull my i3dotfile:
```bash
git clone https://github.com/stkevintan/i3dotfile ~/.config/i3
```
#### dependencies:
basic:
```
i3blocks
i3status
dmenu
quickswitch-i3 #AUR
xfce4-terminal
```
apps:
```
fcitx
xfce4-clipman
xfce4-appfinder
xfce4-notifyd
nitrogen #wallpapers
lxappearance-gtk3 # gtk themes
deepin-screenshot # screenshot
```
fonts:
```
Titillium Web # Download from fonts.google
Fira Code(with nerd patch) # pacman -S nerd-fonts-fira-code
Font Awesome 5 Free # pacman -S ttf-font-awesome
wqy-microhei
wqy-zenhei
```
## audio
```bash
sudo pacman -S pulseaudio pulseaudio-alsa alsa-utils alsa-firmware
```
Optional, you can install a cli management frontend for pulseaudio:
```bash
sudo pacman -S pacmixer
```
reboot your system.
## fcitx
basic install:
```bash
sudo pacman -S fcitx-im fcitx-ui-light fcitx-configtool
```
add environmant: `~/.pam_environment`
```
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
```
### rime
```bash
sudo pacman -S fcitx-rime
```
open fcitx-configtool add rime as a input method and **Disable** the option `Extra key for trigger input method`
basic rime config:`~/.config/fictx/rime/default.custom.yaml`
```yaml
patch:
switcher/hotkeys:
- Alt+grave
switcher/caption: '-'
menu/page_size: 9 # 候选列表size
switcher/fold_options: false
key_binder/bindings:
- send: Page_Up
accept: minus
when: has_menu
- send: Page_Down
accept: equal
when: has_menu
- send: Page_Up
accept: comma
when: paging
- send: Page_Down
accept: period
when: has_menu
- toggle: full_shape
accept: Shift+space
when: always
# 使用shift直接英文上屏
ascii_composer/switch_key:
Caps_Lock: noop
Shift_R: inline_ascii
Control_L: clear
Control_R: commit_text
Shift_L: commit_code
```
## ranger
command line filemanager
```bash
sudo pacman -S ranger
```
suggestions:
```bash
sudo pamcan -S atool zip unzip unrar # for preview archives
sudo pacman -S w3m # for preview images & html pages
sudo pacman -S poppler # for preview pdf
sudo pacman -S ffmpegthumbnailer # for preview video
```
## fonts
### install font:
```bash
mkdir -p ~/.local/share/fonts # first time.
cp *.ttf ~/.local/share/fonts
fc-cache -f -v # refresh the cache
fc-list # show the font list
```
### font config:
edit: `~/.config/fontconfig/fonts.conf`
```xml
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- 具体设置在这里 -->
<!-- 显示器使用的像素排列方式. 现代显示器基本都是用rgb排列. -->
<match target="font">
<edit mode="assign" name="rgba">
<const>rgb</const>
</edit>
</match>
<!-- 字体微调的程度, 可选为 hintnone, hintslight (默认), hintmedium, hintfull. -->
<!-- 简单来说,更高的 hinting 等级可以使字体更锐利,但同时也会损失更多的细节. -->
<!-- 如果你的显示器的 DPI 高得不像话 (>=300), 那么就可以关闭 hinting, 因为字体会自然对齐像素. -->
<match target="font">
<edit mode="assign" name="hintstyle">
<const>hintslight</const>
</edit>
</match>
<!-- 抗锯齿. 除非你的屏幕DPI奇高否则建议开启. -->
<match target="font">
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>
<!-- 全局默认字体 -->
<!-- Default font (no fc-match pattern) -->
<match>
<edit mode="prepend" name="family">
<string>FiraCode Nerd Font</string>
</edit>
</match>
<!-- 全局默认中文字体 -->
<!-- Default font for the zh_CN locale (no fc-match pattern) -->
<match>
<test compare="contains" name="lang">
<string>zh_CN</string>
</test>
<edit mode="prepend" name="family">
<!-- 更改下一行即可, 以下同理 -->
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
<!-- 默认无衬线字体 -->
<!-- Default sans-serif font -->
<match target="pattern">
<test qual="any" name="family">
<string>sans-serif</string></test>
<edit name="family" mode="prepend" binding="same">
<string>WenQuanYi Micro Hei</string>
</edit>
</match>
<!-- 默认衬线字体 -->
<!-- Default serif fonts -->
<match target="pattern">
<test qual="any" name="family">
<string>serif</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>WenQuanYi Zen Hei</string>
</edit>
</match>
<!-- 默认等宽字体 -->
<!-- Default monospace fonts -->
<match target="pattern">
<test qual="any" name="family">
<string>monospace</string>
</test>
<edit name="family" mode="prepend" binding="same">
<string>FiraCode Nerd Font</string>
</edit>
</match>
</fontconfig>
```
## zsh
```bash
sudo pacman -S zsh
chsh -s zsh # change default shell to zsh
zsh # change to zsh
```
### prezto
```bash
# install prezto
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
rm -rf .zshrc .zpreztorc .zlogin .zlogout .zprofile .zshenv .zhistory .zcompdump
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
# resource the zshrc
source .zshrc
```
config:
```bash
# 主题列表
prompt -l
# 预览主题
prompt -p NAME
# 做个备份
mv .zpreztorc .zpreztorc.tmp
# 添加常用插件(不要第二次运行,而是手动修改.zpreztorc文件)
awk -v s="syntax-highlighting git command-not-found pacman history-substring-search autosuggestions" \
'BEGIN{n=split(s,m)}/'\''utility'\''\s+\\/{for(i=1;i<=n;i++)printf(" '\''%s'\'' \\\n",m[i])}{print}' .zpreztorc.tmp > .zpreztorc
# 修改默认主题(推荐 minimal)
sed -i "s/\(zstyle.*theme\s\).*/\1'minimal'/" .zpreztorc
```
## Multi Screen Layout
use `arandr` as a gui frontend tool for `xrandr`
```bash
sudo pacman -S arandr
```
After config the monitors, click `Apply` then click `Save As` in the menu.
Please save the config shell to `~/.screenlayout/normal.sh`
Note: **if you do not set a primary monitor, the system tray will not show up.**