Arch 安装及初始化配

调整控制台字体(可选)

终端字体以大号字体显示

setfont ter-132n

无线连接#

iwd: iNet wireless daemon

iwctl

device list

# <name> 为 device list 打印列表你中的名字,如 `station wlan0 scan`
station <name> scan

station <name> get-networks

# <ssid> 为 wifi名称
station <name> connect <ssid>

quit

# 测试网络连接
ping gnux.cn


ssh 安装 (可选)#

以远控安装, cv用起来~远控安装时建议目标机器一直处于 ping 状态OpenSSH

# openssh 在安装环境下已经预置了,不需要再安装, 验证 `pacman -Qi openssh`
# pacman -Syy openssh 
# 启动服务
systemctl start sshd

# 查看 ip
ip addr


ssh 连接#

# 另一台电脑 提示输入密码为前面设置的 root 密码
# <ip> 为上面查到的ip 地址,如:192.168.1.80
ssh root@<ip>


更新系统时间#

timedatectl set-ntp true

# 检查服务状态
timedatectl status


生成镜像源#

镜像源reflector

# 先停用自动更新服务,以防后面安装过程中进行自动更新把手动生成的覆盖掉
systemctl stop reflector.service

# 然后手动按需生成## 位于中国 近12小时活跃 https协议 按速度排序 文件保存
reflector --country China --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

# 查看生成结果cat /etc/pacman.d/mirrorlist

# 刷新源
pacman -Syy

磁盘分区#

gPT fdisk

# 查看磁盘及分区
lsblk

# <disk> 为 lsblk 中对应的磁盘名,如 `gdisk /dev/nvme0n1`
gdisk /dev/<disk>

# ? 查看帮助 p 打印分区 d 删除分区 n 新建分区 w 应用修改且退出 q 直接退出# 1 ef00 +512M
n
1
ENTER for default first sector
+512M
ef00

# 2 8300
n
2
ENTER for default first sector
ENTER for default last sector
ENTER for default type linux

# 保存并退出
w

# 确认分区
Y

# 查看磁盘分区情况
gdisk -l /dev/<disk>


格式化#

File systems创建文件系统

lsblk

# <part> 为 lsblk 中 ef00 对应的分区名,如 `mkfs.fat -F 32 /dev/nvme0n1p1`## 效果同 `mkfs.vfat /dev/<part>
mkfs.fat -F 32 /dev/<part>

# <part> 为 lsblk 中 8300 对应的分区名,如 `cryptsetup luksFormat /dev/nvme0n1p2`# 下面的 cryptroot 可自定义,但要注意后边安装过程也要保持一致
cryptsetup luksFormat /dev/<part>
YES
cryptsetup luksOpen /dev/<part> cryptroot
mkfs.btrfs /dev/mapper/cryptroot

# 查看格式化结果
lsblk -f


btrfs 子卷#

Btrfs很大原因是为以后如果要使用 timeshift 的 btrfs 类型备份时做预备In BTRFS mode, snapshots are taken using the in-built features of the BTRFS filesystem. BTRFS snapshots are supported only on BTRFS systems having an Ubuntu-type subvolume layout (with @ and @home subvolumes).

# 先挂载根分区,用以在根分区上创建 btrfs 子卷
mount /dev/mapper/cryptroot /mnt

# 添加子卷 @ @home @var @swap
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@var
btrfs subvolume create /mnt/@swap

ls /mnt

umount /mnt


挂载#

挂载文件系统

# 挂载 @
mount -o noatime,space_cache=v2,compress=zstd,ssd,discard=async,subvol=@ /dev/mapper/cryptroot /mnt

# 创建@home 及 efi 等挂载位置mkdir -p /mnt/{boot,home,var,swap}

# 挂载 @home
mount -o noatime,space_cache=v2,compress=zstd,ssd,discard=async,subvol=@home /dev/mapper/cryptroot /mnt/home

# 挂载 @var
mount -o noatime,space_cache=v2,compress=zstd,ssd,discard=async,subvol=@var /dev/mapper/cryptroot /mnt/var

# 挂载 @swap
mount -o noatime,space_cache=v2,ssd,subvol=@swap /dev/mapper/cryptroot /mnt/swap

# 挂载 efi# <part> 为 lsblk 中 ef00 对应的分区名,如 `mount /dev/nvme0n1p1 /mnt/boot`
mount /dev/<part> /mnt/boot

# 查看结果
lsblk


安装系统基本软件包#

安装必需的软件包

# btrfs-progs  btrfs 所需
pacstrap /mnt base base-devel linux linux-firmware linux-headers btrfs-progs


生成 fstab 文件#

fstab

# 用 -U 或 -L 选项设置 UUID 或卷标
genfstab -U /mnt >> /mnt/etc/fstab

# 查看生成的文件cat /mnt/etc/fstab


进入安装的系统#

Chroot

arch-chroot /mnt

pacman -Syy


修改 root 密码#

passwd

添加普通用户#

用户管理

echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel

# liamrad 可自定义,但要注意后边的要和自定义的一致
useradd -m liamrad

# 用户组
usermod -aG wheel liamrad

# 配置密码
passwd liamrad


添加中国仓库源(可选)#

archlinuxcnOfficial repositories

# 编辑 /etc/pacman.confecho "\
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/\$arch" >> /etc/pacman.conf

# 查看编辑结果cat /etc/pacman.conf

# 安装 keyring
pacman -Syy archlinuxcn-keyring


时区#

时区硬件时钟

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

hwclock --systohc

语言环境#

Locale

echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen
echo 'zh_CN.UTF-8 UTF-8' >> /etc/locale.gen

cat /etc/locale.gen

locale-gen

echo 'LANG=en_US.UTF-8' > /etc/locale.conf

cat /etc/locale.conf


网络配置#

设置计算机名

# 配置主机名# archlinux 可自定义,但要注意后边的要和自定义的一致echo archlinux > /etc/hostname

# archlinux 为上面定义的主机名echo "\
127.0.0.1	localhost
::1		localhost
127.0.1.1	archlinux.localdomain	archlinux" >> /etc/hosts

# 查看 hostscat /etc/hosts

# 安装网络管理器
pacman -S networkmanager
# 自启动
systemctl enable NetworkManager


配置Initramfs#

# 先安装一下 vim,一个编辑器
pacman -Sy vim

# 编辑文件
vim /etc/mkinitcpio.conf

# 对应修改,添加 btrfs encrypt, 注意位置顺序
MODULES=(btrfs)
HOOKS=(base udev autodetect modconf block encrypt filesystems keyboard fsck)

# 生成新的参数配置
mkinitcpio -p linux


配置引导程序#

systemd-bootMicrocode

# amd-ucode / intel-ucode
pacman -S efibootmgr amd-ucode

# 安装 EFI 启动管理器
bootctl --path=/boot install

# 启动选单配置echo "\
timeout 10
default arch.conf" >> /boot/loader/loader.conf

# 增加启动选项 arch## 其中的 nvme0n1p2 替换为前面 8300 对应的分区## 其中的 nvme0n1p2 替换为前面 8300 对应的分区## 其中的 nvme0n1p2 替换为前面 8300 对应的分区echo -e "\
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options cryptdevice=UUID=`blkid -s UUID -o value /dev/nvme0n1p2`:cryptroot root=/dev/mapper/cryptroot rw rootflags=subvol=@ \c" > /boot/loader/entries/arch.conf

# 增加启动选项 arch-fallback## 其中的 nvme0n1p2 替换为前面 8300 对应的分区## 其中的 nvme0n1p2 替换为前面 8300 对应的分区## 其中的 nvme0n1p2 替换为前面 8300 对应的分区echo -e "\
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux-fallback.img
options cryptdevice=UUID=`blkid -s UUID -o value /dev/nvme0n1p2`:cryptroot root=/dev/mapper/cryptroot rw rootflags=subvol=@ \c" > /boot/loader/entries/arch-fallback.conf


显卡驱动#

Xorg: 驱动安装

# amd## GCN 3(不包含) 之前的需要安装 xf86-video-ati 替换 xf86-video-amdgpu## 现在新电脑无脑 xf86-video-amdgpu 就可以
pacman -S xf86-video-amdgpu vulkan-radeon mesa

# inter(未自测)
pacman -S xf86-video-inter vulkan-inter mesa

# nvidia(未自测)
pacman -S nvidia nvidia-setings nvidia-utils


字体#

Fonts

# 英文
pacman -S ttf-dejavu

# 中文
pacman -S wqy-zenhei wqy-microhei noto-fonts-cjk

# emoji
pacman -S noto-fonts-emoji


# 更多可按需添加,部分罗列
ttf-dejavu ttf-droid ttf-hack ttf-font-awesome otf-font-awesome ttf-lato ttf-liberation ttf-linux-libertine ttf-opensans ttf-roboto ttf-ubuntu-font-family

ttf-hannom noto-fonts noto-fonts-extra noto-fonts-emoji noto-fonts-cjk adobe-source-code-pro-fonts adobe-source-sans-fonts adobe-source-serif-fonts adobe-source-han-sans-cn-fonts adobe-source-han-sans-hk-fonts adobe-source-han-sans-tw-fonts adobe-source-han-serif-cn-fonts wqy-zenhei wqy-microhei


蓝牙#

蓝牙安装在虚拟机可不用安装,直接在虚拟机软件里使用宿主机的设备就可以

pacman -S bluez bluez-utils

# 蓝牙服务自启动
systemctl enable bluetooth


声音#

Advanced Linux Sound Architecture,ALSAPulseAudioPipeWire

#pacman -S alsa-utils pulseaudio pulseaudio-bluetooth
pacman -S pipewire pipewire-alsa pipewire-pulse pipewire-jack xdg-desktop-portal xdg-desktop-portal-kde


打印机#

CUPS

pacman -S cups

# 打印机服务自启动
systemctl enable cups


输入法#

Fcitx5 是继 Fcitx 后的新一代输入法框架。

pacman -S fcitx5-im fcitx5-chinese-addons

# 字库(推荐)
pacman -S fcitx5-pinyin-zhwiki

# 配置环境变量,以在应用程序中正常使用echo "\
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx" >> /etc/environment

# 检查编辑结果cat /etc/environment


图形界面#

XorgDesktop environment 桌面环境Display manager 显示管理器kde

pacman -S xorg

# 桌面环境 plasma & 显示管理器 sddm## plasma-wayland-session 可选
pacman -S plasma sddm

# sddm 自启动
systemctl enable sddm

# 一些应用## kde-applications 全套kde应用安装
pacman -S kde-applications
## 1. 也可以自己挑选单独的子软件包组按需安装### https://archlinux.org/packages/extra/any/kde-applications-meta/
pacman -S kde-accessibility-meta kde-system-meta ...
## 2. 或单独安装所需的软件:文件管理器 浏览器 文本编辑器 终端
pacman -S dolphin chromium kate konsole

# 一些工具软件(可选)# vim 终端中的文本编辑器# git 分布式版本管理工具# openssh ssh# bash-completion bash命令补全# reflector 镜像列表生成# print-manager kde 上的打印机 GUI 管理
pacman -S vim git openssh bash-completion reflector print-manager


重启进入系统界面#

安装完毕,至日常可用状态

# 退出 chroot 环境exit

# 手动卸载被挂载的分区(可选)## 这有助于发现任何「繁忙」的分区,并通过 fuser(1) 查找原因
umount -R /mnt

# systemd 将自动卸载仍然挂载的任何分区
reboot


交换文件(推荐)#

Btrfs: 交换文件Swap Fileswap 分区大小参考

创建交换文件#

# root 用户模式
su

# 禁用写时复制## /swap 就是前面挂载 @swap 子卷的位置### [参数 C](https://man.archlinux.org/man/chattr.1#C)
chattr +C /swap

# swapfile 可自定义,但要注意后边的要和自定义的一致truncate -s 0 /swap/swapfile

# bs 与 count 的乘积为内存的1-1.5倍,我的内存是32G, 设置 40960 为40G (40 * 1024)dd if=/dev/zero of=/swap/swapfile bs=1M count=40960 status=progress

# 权限设置 仅所有者可读写,目前在 su 下,所有者是 rootchmod 600 /swap/swapfile

# 格式化为 swap 分区
mkswap -U clear /swap/swapfile

# 启用 swap
swapon /swap/swapfile

# 编辑表文件echo '/swap/swapfile none swap defaults 0 0' >> /etc/fstab

# 检查cat /proc/swaps
free -h


删除交换文件#

# 先关闭 swap
swapoff /swap/swapfile

# 然后删除文件rm -rf /swap/swapfile

# 编辑 /etc/fstab 移除创建时添加的行## 如移除:/swap/swapfile none swap defaults 0 0
vim /etc/fstab


休眠(推荐)#

休眠到交换文件休眠

# root 用户模式
su

# wget 命令行下载工具# bc 命令行计算器
pacman -S wget bc

# 下载
wget https://raw.githubusercontent.com/osandov/osandov-linux/master/scripts/btrfs_map_physical.c

# 编译
gcc -O2 -o btrfs_map_physical btrfs_map_physical.c

# 执行
./btrfs_map_physical /swap/swapfile

# physical offset## `./btrfs_map_physical /swap/swapfile` 的结果 PHYSICAL OFFSET 位于第九列,取不算行头对应的第一行的值
./btrfs_map_physical /swap/swapfile | cut -f 9 | head -2 | tail -1

# PAGESIZE
getconf PAGESIZE

# physical offset / PAGESIZE,计算得到商( resume_offset )echo `./btrfs_map_physical /swap/swapfile | cut -f 9 | head -2 | tail -1` / `sudo getconf PAGESIZE` | bc

# 打印resume( resume )
blkid -s UUID -o value /dev/mapper/cryptroot

# 存到会话变量里export myresumeoffset=`echo \`./btrfs_map_physical /swap/swapfile | cut -f 9 | head -2 | tail -1\` / \`getconf PAGESIZE\` | bc`
export myresume=`blkid -s UUID -o value /dev/mapper/cryptroot`

# 配置引导程序## 在起初创建文件时使用了 -e 参数以及 \c 特殊字符,这两个作用就是在最后不添加换行符号## 以便在这里将新内容直接添加在 options 所在行echo "resume=UUID=$myresume resume_offset=$myresumeoffset" >> /boot/loader/entries/arch.conf
echo "resume=UUID=$myresume resume_offset=$myresumeoffset" >> /boot/loader/entries/arch-fallback.conf

# 配置Initramfs
vim /etc/mkinitcpio.conf

# 对应修改,添加 resume,注意位置顺序
HOOKS=(base udev autodetect modconf block encrypt filesystems resume keyboard fsck)

# 生成新的参数配置
mkinitcpio -p linux

# 重启以应用
reboot

# 验证while true ; do date ; sleep 1 ; done

# 重新开一个终端# 休眠
systemctl hibernate

# 然后开机,查看用于验证的终端是否再继续打印,以及中间有一段时间的空闲,那是电脑休眠的时间

AUR(推荐)#

paru——一个 aur助手,集成下载构建安装

# 准备克隆
sudo pacman -S git

git clone https://aur.archlinux.org/paru-bin

cd paru-bin

# (在非root用户下执行)
makepkg -si

# 使用帮助
paru --help


timeshift(推荐)#

快照备份

paru -S timeshift-bin

# 自动备份(可选)## 更新时自动增加更新前的快照
paru -S timeshift-autosnap


更多#

软件包存档#

archive

启用 root 的 ssh 连接#

不推荐,不过可以在安装完后再改回去 #PermitRootLogin prohibit-password

# 需要先安装 ssh 才有这个文件
pacman -S openssh

vim /etc/ssh/sshd_config
# 将 PermitRootLogin 值改为 yes 并取消注释

命令行配置网络#

NetworkManager

# 获取网络设备名称(因为新系统不一定与前面获取的一致)
ip addr

# 进入 tui
nmtui

# edit a connection# Add# Wi-Fi# Device: 网络设备名称# SSID: 无线名称# Security: WPA & WPA2 Personal# Password: 无线密码# Ok# Back# Quit

ip addr

# 测试网络连接
ping -c 4 baidu.com


清除缓存#

pacman -Scc


freetype2 渲染#

# freetype2 渲染
vim /etc/profile.d/freetype2.sh

# 去除注释 export ...

禁用蜂鸣器#

su

rmmod pcspkr

echo "blacklist pcspkr" >> /etc/modprobe.d/nobeep.conf

exit


ssd优化#

TRIM#

pacman -S util-linux

# 定时任务
systemctl enable fstrim.timer


性能#

arch wiki

# pacman -S nvme-cli

discover: not application back-ends found#

解决方案

pacman -S packagekit-qt5


KDE WALLET#

kde Writing login information to the keychain failed with error ‘GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.secrets was not provided by any .service files’.github issuepr

# 暂未合并, 目前可以通过 aur 安装
paru -S kwallet-secrets

# 或
pacman -S gnome-keyring


固定DNS以防被污染#

vim /etc/resolv.conf

# 填入以下内容
nameserver 8.8.8.8
nameserver 114.114.114.114

# 只读文件保存并退出 :wq!# 防止程序覆盖
chattr +i /etc/resolv.conf


makepfg#

减少编译时间

# 获得可用处理器的个数nproc

vim /etc/makepkg.conf
# 将 MAKEFLAGS 后面值中的数字部分改为不大于上面个数的数字,并取消注释

linux 关机时间长#

通过减少默认停止超时来加快 Linux 中的关机速度

vim /etc/systemd/system.conf

# 修改 DefaultTimeoutStopSec 并取消注释## 如 5秒
DefaultTimeoutStopSec=5s


pacman 一些偏好设置#

vim /etc/pacman.conf

# 并行下载(默认依次下载)## 修改 ParalleDownloads 为正整数,正整数就是所要并行下载的包的数量# 升级前对比版本## 要查看旧版和新版的有效安装包,请取消/etc/pacman.conf中"VerbosePkgLists"的注释

zram#

zram

# 禁用zswapecho 0 > /sys/module/zswap/parameters/enabled

# 安装(其中某些文件可能需要T)
paru -S zramd

# 配置文件
vim /etc/default/zramd

# 启动## --now Start or stop unit after enabling or disabling it
systemctl enable --now zramd.service

# 查看是否多出一个swap 设备
lsblk


sddm 开启虚拟键盘#

# 安装
pacman -S qt5-virtualkeyboard

# 配置# /etc/sddm.conf.d/virtualkbd.conf
[General]
InputMethod=qtvirtualkeyboard