Featured image of post Arch Linux的安装流程与常用配置

Arch Linux的安装流程与常用配置

记录我在老电脑上安装Arch的流程

前言

最近苦于之前的老笔记本在运行Windows时越来越卡了,于是便萌生的重装系统的想法。正好,之前23年的时候已经体验过ArchLinux系统了,而且听说现在Nvidia驱动在Linux下也比较方便安装了,于是就决定将Arch在装回来。

预先准备

需要准备1个U盘,用来存放系统的镜像。

Arch Linux的镜像可以去镜像站下载,这里我选择中科大的镜像站来下载,这里选择archlinux-x86_64.iso即可下载了。

有了镜像还需要引导程序,这里我选择的是Ventoy。它的优势就是支持多种镜像,同时也不影响U盘正常的使用。

制作好后直接将iso文件拷贝到U盘里即可了。

安装

重启电脑,在BIOS中选择好U盘引导后,就可以进入到ArchLinux的安装界面了。与Windows这种图形化安装不同,Arch的安装是通过输入命令来完成的。不过现在官方已经提供了安装脚本来实现,这极大简化了我们的安装。后面我就通过安装脚本来进行安装。不过如果有更高级的安装需求,如双系统等等,那还是使用命令行安装吧。

联网

Arch的安装是需要连接互联网的,如果是有线网络的话就是自动连接,而如果需要连接WI-FI的话就需要输入命令了1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 进入iwctl命令行,当前行会显示[iwd]#
iwctl
# 列出所有的WiFi网卡
device list
# 此时会列出所有的WiFi网卡,一般使用第一个即可,也就是wlan0
# 如果设备或其相应的适配器已关闭,将其打开
adapter [adapter名称] set-property Powered on
# 扫描网络
station wlan0 scan
# 列出所有可以搜索到的网络
station wlan0 get-networks
# 连接网络
station wlan0 connect [SSID]
# 输入完密码后就连接上了,此时就可以退出了
exit
# 验证网络连接状态
ping baidu.com

archinstall

输入archinstall进入官方的安装脚本2

archinstall界面

此时界面全是英文,第一项似乎可以更改语言。但是,这里一定不要将其修改为中文,由于安装镜像里没有安装中文字体,一旦切换过去你就会看到一堆口口口。这里就保持默认的英文就好了。

错误的示范

第二项Locales:不用修改,保持默认即可

第三项Mirrors:需要去配置一下中国的镜像

镜像选择

这里选择China,并在下面的Optional repositories中打开multilib(按空格选中),这主要是为了给32位程序提供支持

开启multilib库

第四项Disk configuration:硬盘配置,**这是非常危险的一步,每一个操作一定小心谨慎,一旦失误不可挽回。请确保需要安装的硬盘中没有任何数据,这一步会清除掉硬盘上的所有数据。**这里我就直接按默认来了。

选择硬盘配置后点击Partitioning,之后使用默认设置,选择Use a best-effort default partition layout,接下来就是文件系统选择,这里直接选择btrfs,btrfs作为最新一代的Linux文件系统,支持很多高级特性。

选择完后会有两个子选项,是关于btrfs的特性的,这里也是直接都使用。

是否开启子系统,直接yes

子系统是btrfs特性之一,可以把同一个硬盘划分成多个子区,但是每个子区都拥有硬盘的所有剩余空间,相当于只要硬盘还有空间,每个子分区就都可以使用它。子分区还可以单独进行挂载等操作。

是否开启压缩

压缩(透明压缩)也是btrfs重要特性之一,作用是会对数据压缩存储从而牺牲CPU性能来提升硬盘性能。写时复制则是数据只有在被修改时才会进行复制。

btrfs还有个特性是支持快照,我们在Btrfs snapshots里选择Snapper来启用。

选择Snapper

第五项是Swap:这里直接保持默认就好了。

第六项是Bootloader:启动引导负责开机时引导电脑载入操作系统,这里我习惯使用Grub

第七项是Hostname:和Windows的主机名一样,就是给机器起的名字

第八项是Authentication:这里注意要给root设置一个密码,并创建一个普通用户供之后的使用。

Authentication 界面

之后创建一个新的用户

创建用户

这里给用户sudo权限,方便我们之后管理系统。

sudo权限

第九项是Profile:这里是预装什么软件,对于桌面环境,新手推荐的就是KDE,这里我们选择TypeDesktopKDE Plasma

桌面环境选择

这里我还额外勾选了Hyprland ,这里是一个现代的平铺式窗口管理器(这也是我选Linux的理由之一),配置有些麻烦,新手可以不选。

之后是显卡驱动选择,这里我是Intel核显+Nvidia独显的组合,所以我这里选择安装Nvidia闭源驱动,并在后面手动安装Intel核显驱动。

显卡驱动选择

之后是欢迎界面,这个保持默认的sddm即可

第十项是Applications:蓝牙根据需求开启,音频(Audio)建议选pipewire

第十一项是Kernels:这里内核选择可以选linux-zen,包含一些常用的优化

第十二项是Network configuration:这里选择第三个即可

从上往下分别是“复制当前网路配置”“自己配置”“使用网络管理器”

第十三项Timezone:时区选择Asia/Shanghai

第十四项NTP:自动同步时间,保持默认开启即可

最后选择Install就会自动安装了。

安装完成界面

安装完成后我们选择第三个,再去装一些需要的包

首先是中文字体

1
pacman -S noto-fonts-cjk

之后就是Intel的显卡驱动3

1
pacman -S mesa lib32-mesa vulkan-intel lib32-vulkan-intel intel-media-driver

完成后就可以重启进入系统了

1
2
exit
reboot

KDE配置

在登录界面我们选择Plasma(Wayland),并输入好密码后,就进入到KDE中了。

这里给出我装机后的一些配置方法

设置镜像源

在安装时,我们是配置过镜像了,但是当时它列出了许多的镜像,正常使用不需要这么多,我们就保留1-2个就好了,这里我直接用命令切换了。

1
2
echo 'Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
' | sudo tee /etc/pacman.d/mirrorlist

之后是启用Arch Linux CN 软件源

在 /etc/pacman.conf 文件末尾添加两行:

1
2
[archlinuxcn]
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch

之后就是更新软件包

1
2
sudo pacman -Syyu
sudo pacman -S archlinuxcn-keyring

设置中文环境

默认的系统是没有中文的环境的,我们需要为其配置对应的locale。4

首先是编辑/etc/locale.gen文件,将zh_CN.UTF-8 UTF-8前面的注释取消

之后是执行 locale-gen 命令,便可以在系统中使用这些 locale。 对于KDE,我们可以在设置里进行语言的切换。

切换语言设置

添加简体中文并放到最上

设置完成后重启即可生效了

设置中文输入法

输入法这里我们选择fcitix+rime即可

1
sudo pacman -S fcitx5-im fcitx5-rime

之后安装rime-ice,这是大佬维护的rime词库,能很方便的配置好输入法,此包在archlinuxcn里有所以我们直接pacman安装即可

1
sudo pacman -S rime-ice-git

之后在KDE的虚拟键盘设置里,选择fcitx5即可启用

KDE虚拟键盘设置

对于双拼用户,rime-ice也提供了对应的设置,只需要在~/.local/share/fcitx5/rime/下创建三个配置文件即可:

default.custom.yaml

1
2
3
patch:
  schema_list:
    - schema: double_pinyin_flypy

melt_eng.custom.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
patch:
  # 修改为双拼的拼写派生规则,因为不在同一个文件了,前面要加上文件名
  speller/algebra:
    # __include: melt_eng.schema.yaml:/algebra_rime_ice       # 全拼
    # __include: melt_eng.schema.yaml:/algebra_double_pinyin  # 自然码双拼
    __include: melt_eng.schema.yaml:/algebra_flypy            # 小鹤双拼
    # __include: melt_eng.schema.yaml:/algebra_mspy           # 微软双拼
    # __include: melt_eng.schema.yaml:/algebra_sogou          # 搜狗双拼
    # __include: melt_eng.schema.yaml:/algebra_abc            # 智能ABC双拼
    # __include: melt_eng.schema.yaml:/algebra_ziguang        # 紫光双拼
    # __include: melt_eng.schema.yaml:/algebra_jiajia         # 拼音加加双拼

radical_pinyin.custom.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
patch:
  # 修改为双拼的拼写派生规则,因为不在同一个文件了,前面要加上文件名
  speller/algebra:
    # __include: radical_pinyin.schema.yaml:/algebra_pinyin         # 全拼
    # __include: radical_pinyin.schema.yaml:/algebra_double_pinyin  # 自然码双拼
    __include: radical_pinyin.schema.yaml:/algebra_flypy            # 小鹤双拼
    # __include: radical_pinyin.schema.yaml:/algebra_mspy           # 微软双拼
    # __include: radical_pinyin.schema.yaml:/algebra_sogou          # 搜狗双拼
    # __include: radical_pinyin.schema.yaml:/algebra_abc            # 智能ABC双拼
    # __include: radical_pinyin.schema.yaml:/algebra_ziguang        # 紫光双拼
    # __include: radical_pinyin.schema.yaml:/algebra_jiajia         # 拼音加加双拼

设置好后右键输入法图标,选择重新部署即可使用

重新部署

安装zsh和oh-my-zsh

默认的bash用起来还是有点不爽,所以直接换成zsh

1
2
3
4
# 安装zsh
sudo pacman -S zsh git
# 安装oh-my-zsh
REMOTE=https://gitee.com/mirrors/oh-my-zsh.git sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

这里我使用了Gitee的镜像,这样在国内能加速下载

之后就是安装插件,我常用的就是命令高亮,这样就能很方便看出输入的命令是否正确了

1
2
3
4
5
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

vim  ~/.zshrc
# 在plugins=(xxx)里添加zsh-syntax-highlighting
source ~/.zshrc

安装浏览器

Linux上支持最好的浏览器就是firefox,这里直接安装一手

1
sudo pacman -S firefox

之后在设置页面,选择Set Alternatives找到中文并应用

firefox语言设置

但是大部分网页对于Chrome的支持还是更好的,所以这里我选择再安装edge浏览器

由于edge是在AUR上的,所以首先要安装paru包管理器

1
sudo pacman -S paru

之后就可以安装edge了

1
paru -S microsoft-edge-stable-bin

edge安装完后还需添加启动命令以便使用,在~/.config/microsoft-edge-stable-flags.conf里输入

1
2
--ozone-platform-hint=auto
--enable-features=AcceleratedVideoDecodeLinuxGL,AcceleratedVideoDecodeLinuxZeroCopyGL

分别是启用原生Wayland支持和GPU硬解

设置默认字体

默认的字体对于中文的显示有问题,在之前的文章中就讨论过这个问题,这里我就直接贴方法了,详细的内容可以看我之前的文章

安装字体

1
sudo pacman -S ttc-iosevka ttf-nerd-fonts-symbols

编辑~/.config/fontconfig/fonts.conf配置文件:

📃展开代码
  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
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'urn:fontconfig:fonts.dtd'>
<fontconfig>
  <!--rendering options-->
  <match target="font">
    <edit name="autohint" mode="assign">
      <bool>false</bool>
    </edit>
    <edit name="hinting" mode="assign">
      <bool>true</bool>
    </edit>
    <edit name="hintstyle" mode="assign">
      <const>hintslight</const>
    </edit>
    <edit name="antialias" mode="assign">
      <bool>true</bool>
    </edit>
    <edit name="lcdfilter" mode="assign">
      <const>lcddefault</const>
    </edit>
    <edit name="rgba" mode="assign">
      <const>rgb</const>
    </edit>
  </match>

  <!--
    https://caniuse.com/extended-system-fonts
    GitHub uses this for code blocks.
  -->
  <match target="pattern">
    <test qual="any" name="family">
      <string>ui-monospace</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>monospace</string>
    </edit>
  </match>

  <match target="pattern">
    <test qual="any" name="family">
      <string>ui-sans-serif</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>sans-serif</string>
    </edit>
  </match>

  <match target="pattern">
    <test qual="any" name="family">
      <string>ui-serif</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>serif</string>
    </edit>
  </match>

  <match target="pattern">
    <test qual="any" name="family">
      <string>-apple-system</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>sans-serif</string>
    </edit>
  </match>

  <!-- Replace Source Han -->
  <match target="pattern">
    <test qual="any" name="family">
      <string>Source Han Sans</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>Noto Sans CJK SC</string>
    </edit>
  </match>
  <match target="pattern">
    <test qual="any" name="family">
      <string>Source Han Serif</string>
    </test>
    <edit name="family" mode="assign" binding="same">
      <string>Noto Serif CJK SC</string>
    </edit>
  </match>

  <!-- Default system-ui fonts -->
  <match target="pattern">
    <test name="family">
      <string>system-ui</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>sans-serif</string>
    </edit>
  </match>

  <!-- Default sans-serif fonts-->
  <match target="pattern">
    <test name="family">
      <string>sans-serif</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Noto Sans CJK SC</string>
      <string>Noto Sans</string>
      <string>Symbols Nerd Font</string>
    </edit>
  </match>

  <!-- Default serif fonts-->
  <match target="pattern">
    <test name="family">
      <string>serif</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Noto Serif CJK SC</string>
      <string>Noto Serif</string>
      <string>Symbols Nerd Font</string>
    </edit>
  </match>

  <!-- Default monospace fonts-->
  <match target="pattern">
    <test name="family">
      <string>monospace</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Noto Sans Mono CJK SC</string>
      <string>Symbols Nerd Font</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="family" compare="contains">
      <string>Source Code</string>
    </test>
    <edit name="family" binding="strong">
      <string>Iosevka Extend</string>
    </edit>
  </match>

  <!-- Replace english fonts-->
  <match target="pattern">
    <test name="prgname" compare="not_eq">
      <string>msedge</string>
    </test>
    <test name="family" compare="contains">
      <string>Noto Sans Mono CJK</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Iosevka Extend</string>
    </edit>
  </match>

  <!-- Replace fonts for Chinese (Hong Kong) -->
  <match target="pattern">
    <test name="lang">
      <string>zh-HK</string>
    </test>
    <test name="family">
      <string>Noto Sans CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans CJK HK</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>zh-HK</string>
    </test>
    <test name="family">
      <string>Noto Serif CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <!-- not have HK -->
      <string>Noto Serif CJK TC</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>zh-HK</string>
    </test>
    <test name="family">
      <string>Noto Sans Mono CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans Mono CJK HK</string>
    </edit>
  </match>

  <!-- Replace fonts for Chinese (Taiwan) -->
  <match target="pattern">
    <test name="lang">
      <string>zh-TW</string>
    </test>
    <test name="family">
      <string>Noto Sans CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans CJK TC</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>zh-TW</string>
    </test>
    <test name="family">
      <string>Noto Serif CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Serif CJK TC</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>zh-TW</string>
    </test>
    <test name="family">
      <string>Noto Sans Mono CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans Mono CJK TC</string>
    </edit>
  </match>

  <!-- Replace fonts for Japanese -->
  <match target="pattern">
    <test name="lang">
      <string>ja</string>
    </test>
    <test name="family">
      <string>Noto Sans CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans CJK JP</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>ja</string>
    </test>
    <test name="family">
      <string>Noto Serif CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Serif CJK JP</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>ja</string>
    </test>
    <test name="family">
      <string>Noto Sans Mono CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans Mono CJK JP</string>
    </edit>
  </match>

  <!-- Replace fonts for Korean -->
  <match target="pattern">
    <test name="lang">
      <string>ko</string>
    </test>
    <test name="family">
      <string>Noto Sans CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans CJK KR</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>ko</string>
    </test>
    <test name="family">
      <string>Noto Serif CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Serif CJK KR</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang">
      <string>ko</string>
    </test>
    <test name="family">
      <string>Noto Sans Mono CJK SC</string>
    </test>
    <edit name="family" binding="strong">
      <string>Noto Sans Mono CJK KR</string>
    </edit>
  </match>

  <!-- 解决全角引号 -->
  <match target="pattern">
    <test name="lang" compare="contains">
      <string>en</string>
    </test>
    <test name="family" compare="contains">
      <string>Noto Sans CJK</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Noto Sans</string>
    </edit>
  </match>
  <match target="pattern">
    <test name="lang" compare="contains">
      <string>en</string>
    </test>
    <test name="family" compare="contains">
      <string>Noto Serif CJK</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Noto Serif</string>
    </edit>
  </match>

</fontconfig>

小结

Arch的安装和常用配置大概就是这些了,Arch的优势就是自定义程度高,大家也可以按照自己的喜爱去安装对应的包。