开始之前

​ Arch Linux 是一个轻量、灵活、滚动更新的 Linux 发行版,适合有时间、有兴趣、热爱自由的朋友们。由于 Arch Linux 仅提供了一个很简洁的安装环境,用户有极大的空间根据自己的喜好安装和配置 Arch Linux,因此初学者往往感到难以适应。本文将简明扼要地介绍一个通用的安装过程,尽可能遵循官方安装指南[1],希望能帮助初学者顺利进入 Arch Linux 的世界。

本教程要求您

  • 拥有一台以 UEFI 模式启动的 x86_64 架构电脑,目前运行 Windows 8 及以上操作系统(如果您不知道这是什么意思,也不影响继续阅读本文,只要您的电脑预装了 Windows 8 及以上系统,就符合上述要求[2])
  • 准备一个 U 盘,将 U 盘文件全部备份到电脑中
  • 备份好电脑中全部资料,防止安装过程中误删分区(您可以在不经常使用的电脑上安装,也可以在虚拟机中尝试)
  • 对 Linux 有一定了解,使用过终端(命令行),理解磁盘分区的概念

如果在安装过程中遇到问题,可以从如下途径获得帮助:

下载镜像

​ [从官网下载最新镜像](Arch Linux - Downloads)

连接无线网络

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 使用iwd工具命令iwctl 进入配置
iwctl
# 查看开启无线设备列表(以下命令在[iwd]#状态下输入)
station list
# 如果列表为空,则查看无线设备列表
device list
# 查看无线设备状态,以wlan0为例
device wlan0 show
# 扫描WiFi,以wlan0为例
station wlan0 scan
# 显示WiFi列表,以wlan0为例
station wlan0 get-networks
# 链接WiFi ,以wlan0为例,ssid为WiFi名称
station wlna0 connect ssid

查看是否支持EFI

1
ls /sys/firmware/efi/efivars

如下输出表示支持

1
2
3
4
5
6
7
8
9
10
11
12
13
root@archiso ~ # ls /sys/firmware/efi/efivars
Boot0000-8be4df61-93ca-11d2-aa0d-00e098032b8c ErrOut-8be4df61-93ca-11d2-aa0d-00e098032b8c PlatformLangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0001-8be4df61-93ca-11d2-aa0d-00e098032b8c KEKDefault-8be4df61-93ca-11d2-aa0d-00e098032b8c PlatformLang-8be4df61-93ca-11d2-aa0d-00e098032b8c
Boot0002-8be4df61-93ca-11d2-aa0d-00e098032b8c KEK-8be4df61-93ca-11d2-aa0d-00e098032b8c SbConfigState-793d9786-44dc-4709-b57f-85b8e8fdbfd2
Boot0003-8be4df61-93ca-11d2-aa0d-00e098032b8c LangCodes-8be4df61-93ca-11d2-aa0d-00e098032b8c SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c
BootCurrent-8be4df61-93ca-11d2-aa0d-00e098032b8c Lang-8be4df61-93ca-11d2-aa0d-00e098032b8c SetupMode-8be4df61-93ca-11d2-aa0d-00e098032b8c
BootOptionSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c MTC-eb704011-1402-11d3-8e77-00a0c969723b SignatureSupport-8be4df61-93ca-11d2-aa0d-00e098032b8c
BootOrder-8be4df61-93ca-11d2-aa0d-00e098032b8c MemoryOverwriteRequestControlLock-bb983ccf-151d-40e1-a07b-4a17be168292 dbDefault-8be4df61-93ca-11d2-aa0d-00e098032b8c
ConInDev-8be4df61-93ca-11d2-aa0d-00e098032b8c MemoryOverwriteRequestControl-e20939be-32d4-41be-a150-897f85d49829 dbxDefault-8be4df61-93ca-11d2-aa0d-00e098032b8c
ConIn-8be4df61-93ca-11d2-aa0d-00e098032b8c MemoryTypeInformation-4c19049f-4137-4dd3-9c10-8b97a83ffdfa dbx-d719b2cb-3d3a-4596-a3bc-dad00e67656f
ConOutDev-8be4df61-93ca-11d2-aa0d-00e098032b8c OsIndicationsSupported-8be4df61-93ca-11d2-aa0d-00e098032b8c db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
ConOut-8be4df61-93ca-11d2-aa0d-00e098032b8c PKDefault-8be4df61-93ca-11d2-aa0d-00e098032b8c
ConsoleOutMode-793d9786-44dc-4709-b57f-85b8e8fdbfd2 PK-8be4df61-93ca-11d2-aa0d-00e098032b8c

磁盘分区

1. 根据需要创建分区大小:root、swap、efi分区

建议分区大小:EFI:300M,swap:内存2倍,内存大于4G可以不设置,root:随意

查看磁盘

1
fdisk -l
1
2
3
4
5
6
7
8
9
10
11
12
root@archiso ~ # fdisk -l
Disk /dev/sda: 320 GiB, 343597383680 bytes, 671088640 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/loop0: 680.04 MiB, 713076736 bytes, 1392728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

2. 设置分区,此处格式选择gpt

选择cfdisk图形化分区方式

1
cfdisk /dev/sda

分区结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@archiso ~ # fdisk -l
Disk /dev/sda: 320 GiB, 343597383680 bytes, 671088640 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: D7DECC34-AD99-0640-8E8D-EA1D382EB13E

Device Start End Sectors Size Type
/dev/sda1 2048 616447 614400 300M EFI System
/dev/sda2 616448 17393663 16777216 8G Linux swap
/dev/sda3 17393664 671086591 653692928 311.7G Linux root (x86-64)


Disk /dev/loop0: 680.04 MiB, 713076736 bytes, 1392728 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

3. 格式化分区

1
2
3
4
5
6
# 格式化EFI分区
mkfs.fat -F32 /dev/sda1
# 格式化交换分区
mkswap /dev/sda2
# 格式化root分区
mkfs.ext4 /dev/sda3

4. 挂载分区

1
2
3
4
5
6
7
8
# 挂载root分区
mount /dev/sda3 /mnt
# 创建放置EFI引导文件目录
mkdir -p /mnt/boot
# 挂载EFI分区
mount /dev/sda1 /mnt/boot
# 启用交换分区
swapon /dev/sda2

系统安装

1. 配置镜像源

清华源:Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch

阿里源:Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch

163源: Server = http://mirrors.163.com/archlinux/$repo/os/$arch

北外: Server = https://mirrors.bfsu.edu.cn/archlinux/$repo/os/$arch

1
nano /etc/pacman.d/mirrorlist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
################################################################################
################# Arch Linux mirrorlist generated by Reflector #################
################################################################################

# With: reflector @/etc/xdg/reflector/reflector.conf
# When: 2022-08-15 09:41:30 UTC
# From: https://archlinux.org/mirrors/status/json/
# Retrieved: 2022-08-15 09:39:17 UTC
# Last Check: 2022-08-15 01:34:10 UTC

# 配置的源
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch

Server = https://mirror.lty.me/archlinux/$repo/os/$arch
Server = https://at.arch.mirror.kescher.at/$repo/os/$arch
Server = https://de.arch.mirror.kescher.at/$repo/os/$arch
Server = https://america.mirror.pkgbuild.com/$repo/os/$arch
Server = https://asia.mirror.pkgbuild.com/$repo/os/$arch
Server = https://europe.mirror.pkgbuild.com/$repo/os/$arch
Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch
Server = https://mirror.telepoint.bg/archlinux/$repo/os/$arch

2. 安装

1
pacstrap /mnt base linux linux-firmware base-devel

创建fstab文件

1
genfstab -U /mnt >> /mnt/etc/fstab

3. 切换到系统目录

1
arch-chroot /mnt

4. 配置时区

1
2
3
4
# 设置时区为上海
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 刷新时钟
hwclock --systohc

5. 设置硬件时间为本地时间

systemd 默认系统时间为 UTC,若跳过这一步,凡是连接此移动硬盘跑过系统的机器主板时间将被刷新为 UTC 时间,造成 Windows 系统时间慢 8 个小时。

1
timedatectl set-local-rtc true

如果出现错误:System has not been booted with systemd as init system (PID 1). Can’t operate.Failed to connect to bus: Host is down

是因为systenctl没有安装或者无法正常使用,执行下边命令安装即可

1

6. 安装基础工具

此为文本编辑器,个人习惯使用nano,使用vi,vim都是非常好的。

1
pacman -S nano zsh git curl net-tools yakuake zip

7. 设置语言

将/etc/locale.gen中

en_US.UTF-8

zh_CN.UTF-8

zh_CN.GB18030 GB18030

zh_CN.GBK GBK

zh_CN.UTF-8 UTF-8
zh_CN GB2312

的注释(#)去掉

1
2
3
4
5
6
# 编辑文件
nano /etc/locale.gen
# 然后生成一下
locale-gen
# 在 /etc/locale.conf文件中写入LANG=en_US.UTF-8
echo LANG=en_US.UTF-8 >> /etc/locale.conf

8. 设置root用户密码

1
passwd

9. 安装网络依赖

1
2
3
4
# 
pacman -S iwd wpa_supplicant dialog net-tools networkmanager dhcpcd
# 设置开机启动
systemctl enable NetworkManager dhcpcd

10. 安装CPU编码

1
2
3
4
# INTEL
pacman -S intel-ucode
# AMD
pacman -S amd-ucode

11. 设置主机名

1
2
3
cat >> /etc/hostname << EOF
archlinux
EOF

12. 设置hosts

1
2
3
4
5
cat >> /etc/hosts << EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 archlinux.localdomain archlinux
EOF

13. 创建initramfs

1
mkinitcpio -P

14. 安装grub

1
pacman -S grub efibootmgr

15. 配置启动项

1
2
grub-install --recheck --efi-directory=/boot /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

16. 配置中文社区仓库

1
nano /etc/pacman.conf

把multilib和它下面一行的 # 去掉

在文件里添加 archlinuxcn 源,著能添加一个

1
2
3
4
5
6
7
8
9
[archlinuxcn]
# 官方源
Server = http://repo.archlinuxcn.org/$arch
# 163源
Server = http://mirrors.163.com/archlinux-cn/$arch
# 清华大学
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
# 北外
Server = https://mirrors.bfsu.edu.cn/archlinuxcn/$arch

如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[community]
Include = /etc/pacman.d/mirrorlist

# If you want to run 32 bit applications on your x86_64 system,
# enable the multilib repositories as required here.

#[multilib-testing]
#Include = /etc/pacman.d/mirrorlist

[multilib]
Include = /etc/pacman.d/mirrorlist

# An example of a custom package repository. See the pacman manpage for
# tips on creating your own repositories.
#[custom]
#SigLevel = Optional TrustAll
#Server = file:///home/custompkgs

[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch

17. 更新系统

1
pacman -Syu

18. 安装密钥

1
pacman -S archlinuxcn-keyring

19. 安装xorg服务

1
pacman -S xorg xorg-server

20. 安装显卡

1
2
3
4
# intel
pacman -S xf86-video-intel
# amd
pacman -S xf86-video-ati
厂商 驱动名 OpenGL OpenGL (multilib)
Intel xf86-video-intel mesa lib32-mesa
AMD/ATI xf86-video-amdgpu,xf86-video-ati mesa lib32-mesa
NVIDIA nvidia nvidia-utils lib32-nvidia-utils

21. 安装输入设备

1
2
3
pacman -S xf86-input-libinput
# 触摸板驱动
pacman -S xf86-input-synaptics

22. 安装Aur助手

1
pacman -S yay

23. 安装字体

1
2
3
4
5
6
# 中文字体
pacman -S ttf-dejavu wqy-zenhei wqy-microhei
# 安装常用西文和符号字体
pacman -S ttf-dejavu
# 更新字体
fc-cache -fv

24. 添加用户

1
useradd -m -G wheel -s /bin/bash xiangyu

25. 设置密码

1
passwd xiangyu

26. 安装sudo

1
pacman -S sudo

为新用户添加管理员权限(可以使用sudo命令)

添加 xiangyu ALL(ALL:ALL) ALL 或者

将文件**/etc/sudoers中的wheel ALL=(ALL) ALL**那一行前面的注释去掉

1
nano /etc/sudoers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
##
## Runas alias specification
##

##
## User privilege specification
##
root ALL=(ALL:ALL) ALL

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL:ALL) ALL

## Same thing without a password
# %wheel ALL=(ALL:ALL) NOPASSWD: ALL

## Uncomment to allow members of group sudo to execute any command
# %sudo ALL=(ALL:ALL) ALL

安装输入法

如果安装了fcitx则先删除

1
pacman -Rsc fcitx

1. 安装

1
pacman -S fcitx5-im fcitx5-chinese-addons

2. 配置环境变量,编辑:~/.pam_environment

1
nano /etc/environment
1
2
3
4
5
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
SDL_IM_MODULE=fcitx
GLFW_IM_MODULE=ibus

安装桌面

Gnome

1
2
# 这里安装的gdm是gnone默认的登录管理器。
pacman -S gnome gnome-extra gdm

登录管理器(或显示管理器)是一个在启动最后显示的图形界面。通过启动登录管理器(或称显示管理器),即可进行图形界面登录。和窗口管理器一样,登录管理器有很多种。目前,Arch 提供了 GDM、SLiM、XDM、LXDM、LightDM 和 sddm 的 systemd 服务文件。如果使用 桌面环境,应该尽量使用对应的登录管理器。

如果是vm虚拟机需要安装如下依赖,否则不能自适应分辨率

1
2
3
pacman -S gtkmm net-tools open-vm-tools xf86-video-vmware xf86-input-vmmouse
# 设置开机启动
systemctl enable vmtoolsd

1. 设置开机启动

1
systemctl enable gdm.service

2. 安装声音相关工具

1
pacman -S alsa-utils pulseaudio pulseaudio-bluetooth

alsa-utils是开源声音工具包

3. 安装打印管理程序

1
pacman -S cups

4. 清楚缓存

1
pacman -Scc

5. 安装dash-to-dock

1
yay -S gnome-shell-extension-dash-to-dock

在扩展里找到Dash to Dock并打开

KDE

1. 安装登录管理器

1
pacman -S sddm sddm-kcm && systemctl enable sddm

2. 安装kde桌面

1
pacman -S plasma kde-applications

安装v2ray

1. 从官方源安装v2ray

1
curl -Ls https://mirrors.v2raya.org/go.sh | sudo bash

安装后可以关掉服务,因为 v2rayA 不依赖于该 systemd 服务

1
2
### Xray 需要替换服务为 xray
sudo systemctl disable v2ray --now

2. 安装v2raya

1
yay -S v2raya

3. 启动服务

1
sudo systemctl start v2raya

4. 设置开机启动(如果有必要)

1
sudo systemctl enable v2raya

5. 访问管理页面

http://127.0.0.1:2017,如果不能访问请检查服务是否已经启动。

6. 创建账号

7. 导入节点

问题

1. discover未找到应用程序后端解决办法

1
sudo pacman -S archlinux-appstream-data  packagekit-qt5  flatpak fwupd

2. surface pro触摸驱动

首先,您需要导入用于签名包的密钥。[链接](Installation and Setup · linux-surface/linux-surface Wiki (github.com))

1
2
curl -s https://raw.githubusercontent.com/linux-surface/linux-surface/master/pkg/keys/surface.asc \
| sudo pacman-key --add -

先检查验证密钥的指纹,再进行本地签名。

1
sudo pacman-key --finger 56C464BAAC421453
1
sudo pacman-key --lsign-key 56C464BAAC421453

您可以通过在/etc/pacman.conf末尾添加以下内容来添加存储库

1
2
[linux-surface]
Server = https://pkg.surfacelinux.com/arch/

完成此操作后,您需要刷新存储库元数据,然后可以安装linux-surface内核及其依赖项。您还应该启用iptsd服务以支持触摸屏。

libwcomm -surface是通过AUR打包的,因此您需要从那里安装它。

1
sudo pacman -Syu
1
sudo pacman -S linux-surface linux-surface-headers iptsd
1
sudo systemctl enable iptsd