安装Archlinux

安装系统

确定启动模式(UEFI/BIOS)

1
2
3
4
5
# 设置终端字号
setfont /usr/share/kbd/consolefonts/LatGrkCyr-12x22.psfu.gz

# 如果提示目录不存在,就是bios,否则是uefi
ls /sys/firmware/efi/efivars

联网(有线网不需要进行这步)

1
2
3
4
5
6
7
8
$ iwctl   //会进入联网模式
[iwd]# help //可以查看帮助
[iwd]# device list //列出你的无线设备名称,一般以wlan0命名
[iwd]# station <device> scan //扫描当前环境下的网络
[iwd]# station <device> get-networks //会显示你扫描到的所有网络
[iwd]# station <device> connect <network name>
password:输入密码
[iwd]# exit //退出当前模式,回到安装模式

更新系统时间

1
2
3
4
# 更新系统时间是有必要的,因为下载软件时,服务器会验证系统时间,
# 如果时间不正确,可能出现下载失败的情况。
timedatectl set-ntp true
timedatectl status # 查看一下系统时钟状态

分区

查看系统磁盘

1
fdisk -l

进入图形化分区工具进行分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cfdisk /dev/<硬盘名称>
# 如果提示你要选MBR还是GPT: UEFI启动选择gpt,BIOS启动选择dos,选中后回车。
# 1. BIOS启动只需要俩个分区,根分区和swap分区

# 2. UEFI启动需要分三个区:
# 1. boot分区,用于存储启动信息,类型为efi system
# 2. swap分区,也就是交换分区,类型为linux swap
# 3. 系统分区,用于安装系统和软件的分区,类型为linux

# 分区操作:
# 1.选中new
# 2.输入分区大小后选中primary回车
# 3.选中type,修改分区类型(根分区是Linux类型,swap分区是Linux swap/Solars类型)
# 4.确认分区无误后选择write 回车,输入yes,选择quit退出图形化分区界面
# 5.命令行输入lsblk,查看分区的初始状态

格式化分区

BIOS格式化

1
2
3
mkfs.ext4 /dev/<硬盘名称>   # eg:mkfs.ext4 /dev/sda2 格式化系统分区
mkswap /dev/<硬盘名称> # 格式化swap分区
swapon /dev/<硬盘名称> # 激活swap分区

UEFI格式化

1
2
3
4
mkfs.fat -F32 /dev/sda1		# 格式化boot分区
mkswap /dev/sda2 # 格式化swap分区
swapon /dev/sda2 # 激活swap分区
mkfs.ext4 /dev/sda3 # 格式化系统分区

挂载分区

BIOS挂载

1
mount /dev/sda2 /mnt		# 将系统分区/dev/sda2挂载到/mnt目录

UEFI挂载

1
2
3
mount /dev/sda3 /mnt		# 将系统分区/dev/sda3挂载到/mnt目录。
mkdir /mnt/boot # 创建boot分区的挂载点。
mount /dev/sda1 /mnt/boot # 将boot分区/dev/sda1挂载到/mnt/boot目录(需要在/mnt下新建一个boot文件夹)。

修改镜像源

1
2
3
4
5
# 很重要,不然等到天荒地老
vim /etc/pacman.d/mirrorlist # 加上一个国内源
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch

pacman -Syy # 更新一下

安装linux

1
2
3
4
5
6
7
8
9
pacstrap /mnt base base-devel linux linux-firmware linux-headers
pacstrap /mnt vim bash-completion iwd dhcpcd net-tools openssh man
# vim 命令行编辑工具
# bash-completion 命令行补全工具
# iwd 无线管理工具
# dhcpcd 有线管理工具
# net-tools 网络工具
# openssh ssh服务
# man 使用手册

写入分区表

1
2
genfstab -U /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab # 检查fstab文件是否正确

进入系统进行相关配置

进入系统

1
arch-chroot /mnt

设置时区

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

同步硬件时钟

1
hwclock --systohc

本地化设置

1
2
3
4
5
6
7
8
9
vim /etc/locale.gen
# 找到下面两项,取消注释
en_US.UTF-8 UTF-8 # 英
zh_CN.UTF-8 UTF-8 # 中

locale-gen # 生成locale信息
locale -a # 列出所有启用的locale
echo LANG=en_US.UTF-8 > /etc/locale.conf # 设置系统语言
locale # 查看一下

网络配置

1
2
3
4
5
6
vim /etc/hostname		# 编辑hostname文件,输入主机名(可以自己命名)
vim /etc/hosts

127.0.0.1 localhost
::1 localhost
127.0.1.1 主机名.localdomain 主机名

安装grub引导

BIOS 安装 grub 引导程序

1
2
3
4
5
6
7
8
9
10
pacman -S grub
grub-install /dev/sda # 安装grub。
grub-mkconfig -o /boot/grub/grub.cfg # 生成grub的配置文件。

若报错则执行下面
vim /etc/default/grub
GRUB_DISABLE_OS_PROBER=false # 取消GRUB_DISABLE_OS_PROBER=false注释(让grub识别别的系统)
# 建议修改GRUB_TIMEOUT,加快启动时间

grub-mkconfig -o /boot/grub/grub.cfg # 再执行一次

UEFI 安装 grub 引导程序

1
2
3
4
5
6
7
8
9
10
11
12
13
# 下载grub和efibootmgr软件包
pacman -S grub efibootmgr

# 安装grub
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Arch --recheck
# --bootloader-id=name 其中 name 可以更改为自己想要的名称,建议简短明确

vim /etc/default/grub
GRUB_DISABLE_OS_PROBER=false # 取消GRUB_DISABLE_OS_PROBER=false注释(让grub识别别的系统)
# 建议修改GRUB_TIMEOUT,加快启动时间

# 生成grub的配置文件。
grub-mkconfig -o /boot/grub/grub.cfg
  • 如果出现错误,请回头检查命令是否输入错误或者配置是否出错,安装时的一点错误都可能成为你无法开机的原因或者以后使用时的bug.

设置root密码,新建用户

1
2
3
4
5
6
7
8
passwd
useradd -m -G wheel <用户名>
passwd <用户名>

# 加入sudo,打开 /etc/sudoers
如果EDITOR=vim
执行visudo
找到%wheel ALL=(ALL) ALL 把前面的注释去掉

配置启动项

1
2
3
sudo systemctl enable dhcpcd
sudo systemctl enable sshd
sudo systemctl enable iwd

安装一些硬件设备

1
2
3
4
5
6
7
8
9
10
11
12
13
# CPU编码
pacman -S intel-ucode (intel的cpu装这个)
pacman -S amd-ucode (amd的cpu装这个)

# 显卡驱动
pacman -S xf86-video-intel(Intel核心显卡驱动,用Intel核显就装,否则不用装)
pacman -S mesa nvidia(-lts) nvidia-settings nvidia-dkms nvidia-utils nvidia-prime(nvidia显卡驱动,用nvidia显卡就装,否则不用装)
pacman -S xf86-video-amdgpu (AMD显卡驱动,用amd显卡的就装)

# 这里举两个例子,我的笔记本,i7-11代,搭配intel核显以及3050显卡,所以安装前两个。我的台式机,e3-1230垃圾CPU,搭配HD6950显卡,所以装第三个。nvidia-dkms 与 nvidia-lts 不兼容,如果装lts驱动的话无需安装dkms 。注意:nvidia驱动的安装与前面选择的内核有关,如果你安装的是linux-lts内核,那么需要将nvidia更换为nvidia-lts,linux-zen不支持nvidia显卡(务必对号入座),如果你选择安装新内核,则需要修改一下ibt=off ,否则无法进入系统

# 声卡驱动
pacman -S pipewire (alsa-utils) pipewire-pulse pipewire-jack pipewire-alsa

使用cn源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
vim /etc/pacman.conf		# 删除Color前的#号

# 在/etc/pacman.conf最后添加
[archlinuxcn]
SigLevel = Optional TrustedOnly
Include = /etc/pacman.d/archlinuxcn

vim /etc/pacman.d/archlinuxcn # 写入以下源
## OpenTUNA (China CDN) (ipv4, https)
Server = https://opentuna.cn/archlinuxcn/$arch
## 北京外国语大学 (北京) (ipv4, ipv6, http, https)
## Added: 2020-05-18
Server = https://mirrors.bfsu.edu.cn/archlinuxcn/$arch
## 腾讯云 (Global CDN) (ipv4, http, https)
## Added: 2018-11-23
Server = https://mirrors.cloud.tencent.com/archlinuxcn/$arch
## 网易 (China CDN) (ipv4, http, https)
Server = https://mirrors.163.com/archlinux-cn/$arch
## 阿里云 (Global CDN) (ipv4, ipv6, http, https)
## Added: 2020-07-03
Server = https://mirrors.aliyun.com/archlinuxcn/$arch
## 华为云 (Global CDN) (ipv4, http, https)
## Added: 2020-10-31
Server = https://repo.huaweicloud.com/archlinuxcn/$arch
## 清华大学 (北京) (ipv4, ipv6, http, https)
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
## 中国科学技术大学 (安徽合肥) (ipv4, ipv6, http, https)
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
## 哈尔滨工业大学 (黑龙江哈尔滨) (ipv4, ipv6, http, https)
## Added: 2021-01-09
Server = https://mirrors.hit.edu.cn/archlinuxcn/$arch
## 浙江大学 (浙江杭州) (ipv4, http, https)
## Added: 2017-06-05
Server = https://mirrors.zju.edu.cn/archlinuxcn/$arch
## 重庆大学 (重庆) (ipv4, ipv6, https)
Server = https://mirrors.cqu.edu.cn/archlinuxcn/$arch
## 重庆邮电大学 (重庆) (ipv4, http, https)
Server = https://mirrors.cqupt.edu.cn/archlinuxcn/$arch
## SJTUG 软件源镜像服务 (上海) (ipv4, ipv6, https)
## Added: 2018-05-21
Server = https://mirrors.sjtug.sjtu.edu.cn/archlinux-cn/$arch
## 南京大学 (江苏南京) (ipv4, ipv6, http, https)
Server = https://mirrors.nju.edu.cn/archlinuxcn/$arch
## 莞工 GNU/Linux 协会 开源软件镜像站 (广东东莞) (ipv4, https)
## Added: 2018-11-03
Server = https://mirrors.dgut.edu.cn/archlinuxcn/$arch
## 南方科技大学 (广东深圳) (ipv4, ipv6, http, https)
## Added: 2021-08-17
Server = https://mirrors.sustech.edu.cn/archlinuxcn/$arch

sudo pacman -Syy
sudo pacman -S archlinuxcn-keyring
1
2
3
4
5
6
# 想简单点就直接在/etc/pacman.conf最后添加
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch

sudo pacman -Syy
sudo pacman -S archlinuxcn-keyring

使用aur

paru

1
2
3
4
5
6
7
8
9
10
11
$ git clone https://aur.archlinux.org/paru.git
$ cd paru
$ makepkg -si

注:archlinuxcn源中有paru,直接sudo pacman -S paru

$ paru # 约等于 sudo pacman -S Syyu 对软件进行更新并升级
$ paru 包名

sudo vim /etc/paru.conf
取消BottomUp的注释 # 使最常用的软件显示在下方

退出系统重启

1
2
3
exit
umount -R /mnt
reboot

系统软件

桌面环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sudo pacman -S xorg xorg-server xorg-xinit xorg-xrandr
sudo pacman -S feh # 壁纸
sudo pacman -S udisks2 udiskie # U盘
xrandr # 查看有哪些显示器

cp /etc/X11/xinit/xinitrc ~/.xinitrcS
vim ~/.xinitrc # 删除最后几行没用的,添加以下几行
fcitx5 & # 开启中文输入法且后台运行
xrandr --output Virtual-1(显示器名称) --mode 1920x1080 --rate 60.00(显示器配置)
feh --bg-fill --randomize /usr/share/backgrouds/archlinux/* # 先设置分辨率再设置壁纸
picom -b &
exec slstatus &
末行添加 exec dwm

systemctl enable udisk2 # 识别U盘
startx # 进入dwm

ctrl+shift+pageup # 放大字体
xrandr -q # 查看显示器设置
xrandr --output Virtual-1(显示器名称) --mode 1920x1080 --rate 60.00(显示器配置)

电池优化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
yay -S tlp tlp-rdw tlpui                                       ## 安装电源管理及图形界面
sudo vim /etc/tlp.conf ## 编辑配置文件,防止Btrfs文件系统损坏
SATA_LINKPWR_ON_BAT=max_performance ## 更改内容为
sudo systemctl enable tlp.service ## 设置tlp服务开机自启动
sudo systemctl enable NetworkManager-dispatcher.service ## 设置开机自启动
sudo syatemctl mask systemd-rfkill.service ## 屏蔽服务,防止冲突
sudo syatemctl mask systemd-rfkill.socket ## 屏蔽,防止冲突
sudo tlp start ## 启动服务

# 使用TLP显示系统信息
sudo tlp-stat -b ## 显示电池信息
sudo tlp-stat -d ## 显示磁盘信息
sudo tlp-stat -e ## 显示 PCI 设备信息
sudo tlp-stat -g ## 显示 GPU 信息
sudo tlp-stat -p ## 显示 CPU 信息
sudo tlp-stat -s ## 显示系统数据信息

声音

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
sudo pacman -S alsa-utils

# 查看有几个声卡设备
cat /proc/asound/cards

# 查看声卡的card number和device number
aplay -h # 查看帮助
aplay -l # 列出所有的声卡和数字音频设备

# 设置默认声卡
# nvim /etc/asound.conf
defaults.pcm.card 1
defaults.pcm.device 0
defaults.ctl.card 1

# 开启声音
amixer sset Master toggle # 交换开启状态
amixer sset Master Capture # 交换开启状态

# 关闭自动静音
# 方法一
amixer -h # 查看帮助
amixer sset Master unmute
amixer sset Speaker unmute
amixer sset Headphone unmute
amixer set Master 10%+ # Master增加10%的音量
amixer set Master 10%- # Master减少10%的音量
amixer set Master 70% # Master音量设定为70%

# 播放音频
aplay -D hw:1,0 /usr/share/sounds/test.wav # hw后的的数字分别代表卡号和设备号

# 在终端中输入alsamixer打开设置
在 alsamixer 中,下方标有 MM 的声道是静音的,而标有 00 的通道已经启用。
使用 ← 和 → 方向键,选中 Master 和 PCM 声道。按下 m 键解除静音。使用 ↑ 方向键增加音量,直到增益值为0。该值显示在左上方 Item: 字段后。过高的增益值会导致声音失真。

背光

1
2
3
4
5
sudo pacman -S light
sudo usermod -aG video <user>
light -U 10 # 屏幕亮度降低10%
light -A 10 # 屏幕亮度升高10%
light -G # 得到当前亮度

蓝牙

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// blueman更方便
sudo bluetooth on # 手动启动蓝牙
sudo bluetooth off # 手动关闭蓝牙
sudo bluetooth toggle # 手动切换蓝牙状态

sudo pacman -S pulseaudio-bluetooth pavucontrol # 安装蓝牙音频
sudo pacman -S bluez bluez-utils
sudo systemctl enable bluetooth.service
sudo systemctl start bluetooth.service

# 使用Bluetoothctl进入蓝牙控制台
$ bluetoothctl --help 查看帮助命令
$ bluetoothctl -v 查看蓝牙版本
$ bluetoothctl 进入蓝牙管理工具环境
[bluetooth]# power on 打开蓝牙
[bluetooth]# agent on 开启代理
[bluetooth]# scan on 扫描蓝牙设备
[bluetooth]# pair xx:xx:xx:... 配对该设备
[bluetooth]# trust xx:xx:xx:... 信任该设备
[bluetooth]# connect xx:xx:... 连接该设备
[bluetooth]# disconnect xx:xx:... 断开蓝牙
[bluetooth]# help 查看帮助信息
[bluetooth]# show 查看本机蓝牙信息
[bluetooth]# discoverable yes 设置蓝牙可被发现
[bluetooth]# info xx:xx:xx:... 查看该蓝牙设备的信息

pulseaudio -k 或者 sudo killall pulseaudio # 确保没有pulseaudio启动
pulseaudio --start # 启动pulseaudio服务
pavucontrol # 管理声音输出

触控板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
sudo pacman -S libinput xf86-input-libinput

libinput配置文件位置
1.libinput默认的配置文件在/usr/share/X11/xorg.conf.d/40-libinput.conf,可以设置鼠标加速、额外的鼠标按键、触控板、触控屏等。
2.由于同一个设备的不同驱动程序可以共存,如果你打算为一个设备使用 libinput 驱动,请确保它在其他驱动中 /etc/X11/xorg.conf.d/ 拥有优先级。
举个栗子:
如果你同时安装了 libinput 和 synaptics 并使用其默认配置(即 /etc/X11/xorg.conf.d/ 中没有属于两者中任一的文件),synaptics 将因其在默认安装目录中拥有更高的数字顺序 70- 而获得优先级。为了避免这种情况,您可以将默认的 libinput 配置文件(40-libinput.conf)软链接到目录搜索顺序优先于 70-synaptics.conf 的 /etc/X11/xorg.conf.d/ 中去取代它。
sudo ln -s /usr/share/X11/xorg.conf.d/40-libinput.conf /etc/X11/xorg.conf.d/40-libinput.conf

# 更改libinput配置
# vim /etc/X11/xorg.conf.d/40-libinput.conf
MatchIsPointer “on” # 小红点
MatchIsKeyboard “on” # 软键盘
MatchIsTouchpad “on” # 触控板
MatchIsTouchscreen “on” # 触控屏

常用选项
1.当检测到 USB 鼠标时,它将禁用触摸板。
Option "SendEventsMode" "disabled-on-external-mouse"
2.允许单指和双指触击分别调用鼠标左右键,而不用按触控板的物理按键
Option "Tapping" "True"
3.防止打字时误触触控板
Option "DisableWhileTyping" "True"
4.触摸板不再拥有区域的区分,与之代替的是双指代表右键,三指代表中键。
Option "ClickMethod" "clickfinger"
5.轻击后手指按住会使单个按钮关闭,此手指的所有动作都将转换为拖动动作。
Option "TappingDrag" "True"
6.自然滚动(反方向滚动)
Option "NaturalScrolling" "True"
7.启用鼠标加速配置文件。这有助于使鼠标手指的速度更自然一些,迟钝感更小。建议使用 Adaptive,因为其会根据您的输入更改。您也可以尝试“flat”选项。
Option "AccelProfile" "adaptive"
8.更改鼠标指针的加速速度。使用 -1 到 1 之间的值。数值越大,指针移动的速度越高。大多数人倾向于使用 0.2 以获得较慢的响应速度,使用 0.5 获得较快的响应速度。
Option "AccelSpeed" "0.3"

# https://wiki.archlinuxcn.org/wiki/Touchpad_Synaptics?rdfrom=https%3A%2F%2Fwiki.archlinux.org%2Findex.php%3Ftitle%3DTouchpad_Synaptics_%28%25E7%25AE%2580%25E4%25BD%2593%25E4%25B8%25AD%25E6%2596%2587%29%26redirect%3Dno
9.在synaptics上启用自然滚动(触摸屏那种滚动).只要将VertScrollDelta和HorizScrollDelta的值设定为负就行(翻转滚动方向):
Option "VertScrollDelta" "-111"
Option "HorizScrollDelta" "-111"

# 举例:
Section "InputClass"
Identifier "touchpad"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
Option "Tapping" "True"
Option "TappingButtonMap" "lrm"
Option "DisableWhileTyping" "True"
Option "TappingDrag" "True"
Option "NaturalScrolling" "True"
Option "SendEventsMode" "disabled-on-external-mouse"
EndSection

通用软件

输入法

1
2
3
4
5
6
7
8
9
10
11
12
# 安装fcitx5
sudo pacman -S fcitx5-im fcitx5-chinese-addons fcitx5-material-color
# 有些应用仍然不能使用中文,去archwiki搜fcitx5查看解决方法

# nerd fond
sudo pacman -S ttf-jetbrains-mono-nerd

# 英文
sudo pacman -S ttf-dehavu ttf-droid ttf-font-awesome otf-font-awesome ttf-liberation ttf-linux-libertine ttf-opensans ttf-roboto ttf-ubuntu-font-family

# 中文
sudo pacman -S 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-cn-fonts wqy-microhei

zsh

1
2
cat /etc/shells  # 查看zsh的具体地址
chsh -s path # zsh的详细路径

wps

1
2
3
paru wps-office-cn wps-office-mui-zh-cn ttf-wps-fonts
$ 解决粗体黑块
paru freetype2-wps

software

1
2
3
4
5
6
7
8
9
10
11
sudo pacman -S unzip git neovim tmux joshuto python xclip
paru iwgtk # iwctl的图形界面
sudo pacman -S capnet-assist # 有些网络需要网页登陆
paru google-chrome
sudo pacman -S clash-verge-rev
sudo pacman -S scrot # 截图
sudo pacman -S flameshot # 截图
sudo pacman -S sioyek # pdf
sudo pacman -S rofi # dmenu
# rofi -dump-config > ~/.config/rofi/config.rasi
# rofi options -theme ~/.config/rofi/powermenu/style.rasi -show drun