Skip to content

Commit 69a9715

Browse files
committed
ArchLinux安装
1 parent cde4428 commit 69a9715

1 file changed

Lines changed: 282 additions & 0 deletions

File tree

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
---
2+
layout: post
3+
title: ArchLinux安装
4+
date: 2025-09-21 22:38:38
5+
categories:
6+
- 编程记录
7+
tags:
8+
- Arch Linux
9+
---
10+
11+
## 前言
12+
13+
Ubuntu、Deepin之类的玩腻了,尝试下新鲜玩意。
14+
最开始在旧电脑上尝试直接安装,但是失败了,很多报错,现在看来是镜像源的问题。
15+
然后尝试在 Hyper-V 虚拟机中安装,过程很顺利,基本没有问题。
16+
最后再次尝试在旧电脑物理机上安装,有了虚拟机的经验,安装也比较顺利。
17+
**唯一失败的就是:分区时没注意磁盘,将分区信息写到了系统u盘,导致u盘数据丢失。惨痛的教训 `lsblk` 或者 `fdisk -l` 很重要!**
18+
19+
## 安装 Arch Linux 系统
20+
21+
首先进入 Arch Live 环境(archiso),是官方 ISO 引导后的安装环境。
22+
23+
~~~
24+
Arch Linux 6.15.8-arch1-2 (tty1)
25+
26+
archiso login:root (automatic login)
27+
28+
To install Arch Linux follow the installation guide:
29+
https://wiki.archlinux.org/title/Installation_guide
30+
31+
For Wi-Fi,authenticate to the wireless network using the iwctl utility.
32+
For mobile broadband (WWAN) modems,comnect with the mmcli utility.
33+
Ethernet,WLAN and WWAN interfaces using DHCP should work automatically.
34+
35+
After comnecting to the internet,the installation guide can be accessed
36+
via the convenience script Installation_guide.
37+
38+
root@archiso ~ #
39+
~~~
40+
41+
### 配置网络
42+
43+
`ping archlinux.org -c 3` 确认是否有网络
44+
45+
如果是有线网络,通常自动就有网络。如果是 WIFI ,使用 `iwctl` 命令:
46+
47+
~~~bash
48+
iwctl
49+
# 交互模式下(示例)
50+
device list
51+
station wlan0 scan
52+
station wlan0 get-networks
53+
station wlan0 connect YOUR_SSID
54+
station list # 用于查看连接状态
55+
# exit 返回
56+
~~~
57+
58+
### 启动模式
59+
60+
`ls /sys/firmware/efi/efivars` 用于输出 **EFI 变量**,区分启动模式是 BIOS 还是 UEFI。
61+
62+
* BIOS 启动:内核只会得到传统的硬件初始化信息,不会加载 EFI 相关功能。
63+
* UEFI 启动:内核会通过 UEFI 固件接口(EFI Runtime Services)获得一系列 EFI 变量(比如引导顺序、启动项、安全启动开关等)。Linux 内核会把这些变量暴露在文件系统里,就是 `/sys/firmware/efi/efivars`
64+
65+
所以 UEFI 启动必须有一个 **EFI 分区 (ESP)**,格式化为 FAT32,挂载到 `/boot``/boot/efi`
66+
67+
#### BIOS 与 UEFI
68+
69+
BIOS:
70+
71+
* 历史悠久:BIOS(Basic Input/Output System)是上世纪 80 年代就有的固件。
72+
* 分区表限制:BIOS 通常和 **MBR 分区表**搭配使用。MBR 最大只支持 **2TB 硬盘容量**,最多 4 个主分区。
73+
* 启动方式:BIOS 启动时,会从磁盘开头的 **MBR (Master Boot Record)** 读取引导代码,然后加载操作系统。
74+
* 兼容性好:老机器几乎都是 BIOS,新机器大多支持兼容模式(CSM),可以让 BIOS 模式继续使用。
75+
76+
UEFI:
77+
78+
* 现代标准:UEFI(Unified Extensible Firmware Interface)是 BIOS 的替代品,大多数 2015 年以后的电脑默认用 UEFI。
79+
* 分区表支持:UEFI 通常和 **GPT 分区表**搭配。GPT 支持 **>2TB 的硬盘**,分区数量几乎无限制。
80+
* 启动方式:UEFI 会读取硬盘上的 **EFI 系统分区 (ESP)**,里面存放引导程序(例如 `grubx64.efi``systemd-boot`)。
81+
* 功能更强:支持图形界面、鼠标操作、安全启动(Secure Boot)、多系统管理更方便。
82+
83+
### 分区设置
84+
85+
**一定注意分区设置的位置!**
86+
**事先使用 `lsblk` 或者 `fdisk -l` 命令查看磁盘信息,确定分区位置。**
87+
88+
#### 创建分区
89+
90+
~~~bash
91+
fdisk /dev/sda
92+
~~~
93+
94+
然后依次输入:
95+
96+
~~~
97+
g # 创建 GPT 分区表
98+
99+
n # 新建分区 1
100+
<回车> # 分区号,直接回车(默认 1)
101+
<回车> # 起始扇区,直接回车(默认)
102+
+512M # 结束扇区,输入大小 → +512M
103+
t # 改类型
104+
1 # 选择分区 1
105+
1 # 设置为 EFI System
106+
107+
n # 新建分区 2
108+
<回车> # 分区号,直接回车(默认 2)
109+
<回车> # 起始扇区,直接回车
110+
+2G # 结束扇区,输入大小 → +2G
111+
t # 改类型
112+
2 # 选择分区 2
113+
19 # 设置为 Linux swap
114+
115+
n # 新建分区 3
116+
<回车> # 分区号,直接回车(默认 3)
117+
<回车> # 起始扇区,直接回车
118+
<回车> # 结束扇区,直接回车(用完剩余空间)
119+
120+
w # 保存并退出
121+
~~~
122+
123+
#### 格式化分区
124+
125+
~~~bash
126+
# EFI 分区
127+
mkfs.fat -F32 /dev/sda1
128+
129+
# swap 分区
130+
mkswap /dev/sda2
131+
swapon /dev/sda2
132+
133+
# 根分区
134+
mkfs.ext4 /dev/sda3
135+
~~~
136+
137+
#### 挂载分区
138+
139+
~~~bash
140+
mount /dev/sda3 /mnt
141+
mkdir -p /mnt/boot
142+
mount /dev/sda1 /mnt/boot
143+
~~~
144+
145+
### 配置镜像源(可选)
146+
147+
1. 临时使用国内镜像
148+
在 live 环境里,修改 pacman 的镜像源列表:
149+
~~~bash
150+
# 先备份原来的
151+
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
152+
153+
# 编辑镜像列表
154+
nano /etc/pacman.d/mirrorlist
155+
~~~
156+
把国内源放到前面,例如:
157+
~~~
158+
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
159+
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
160+
Server = https://mirrors.aliyun.com/archlinux/$repo/os/$arch
161+
~~~
162+
> 注意:把想用的镜像放在 **最上面**,pacman 会优先使用。
163+
保存退出后,运行:
164+
~~~bash
165+
pacman -Syyu
166+
~~~
167+
2. 选择最快的镜像
168+
Arch 自带 `reflector` 工具(Live ISO 可能没有,需要先安装):
169+
~~~bash
170+
pacman -Sy reflector --noconfirm
171+
reflector --country China --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
172+
~~~
173+
会自动选择最近最快的中国镜像。
174+
175+
### 安装基础系统
176+
177+
~~~bash
178+
pacstrap /mnt base linux linux-firmware vim nano networkmanager
179+
~~~
180+
181+
安装完成后生成 fstab:
182+
183+
~~~bash
184+
genfstab -U /mnt >> /mnt/etc/fstab
185+
~~~
186+
187+
然后进入新系统环境:
188+
189+
~~~bash
190+
arch-chroot /mnt
191+
~~~
192+
193+
## 安装并配置 bootloader(**UEFI 推荐 GRUB 或 systemd-boot**
194+
195+
#### 使用 GRUB(UEFI)
196+
197+
~~~bash
198+
pacman -S --noconfirm grub efibootmgr dosfstools os-prober mtools
199+
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
200+
grub-mkconfig -o /boot/grub/grub.cfg
201+
~~~
202+
203+
#### 使用 GRUB(BIOS)
204+
205+
~~~bash
206+
pacman -S --noconfirm grub
207+
grub-install --target=i386-pc /dev/sda # 注意写在磁盘(如 /dev/sda),不是分区
208+
grub-mkconfig -o /boot/grub/grub.cfg
209+
~~~
210+
211+
### 系统其余配置
212+
213+
1. 时区:
214+
~~~bash
215+
ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
216+
hwclock --systohc
217+
~~~
218+
2. 本地化(示例同时启用 zh\_CN.UTF-8 与 en\_US.UTF-8):
219+
~~~bash
220+
sed -i 's/^#zh_CN.UTF-8/zh_CN.UTF-8/' /etc/locale.gen
221+
sed -i 's/^#en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
222+
locale-gen
223+
echo LANG=zh_CN.UTF-8 > /etc/locale.conf
224+
echo KEYMAP=us > /etc/vconsole.conf # 如需中文控制台可改为 zh_CN
225+
~~~
226+
3. 主机名与 hosts:
227+
~~~bash
228+
echo arch > /etc/hostname
229+
cat >> /etc/hosts <<EOF
230+
127.0.0.1 localhost
231+
::1 localhost
232+
EOF
233+
~~~
234+
4. root 密码:
235+
~~~bash
236+
passwd
237+
~~~
238+
239+
### 安装 ssh 服务
240+
241+
`sudo pacman -S --noconfirm openssh`
242+
`sudo systemctl enable sshd`
243+
`sudo systemctl start sshd`
244+
245+
记得编辑`/etc/ssh/sshd_config`:
246+
247+
~~~
248+
PasswordAuthentication yes # 允许密码登录
249+
PermitRootLogin yes # 如果你用 root 登录(可选)
250+
UsePAM yes # 必须启用 PAM
251+
~~~
252+
253+
`sudo systemctl restart sshd`
254+
255+
## 安装 KDE 桌面环境
256+
257+
`sudo pacman -Syu` 更新系统
258+
`sudo pacman -S --noconfirm xorg` 安装 Xorg(显示服务器)
259+
260+
安装 KDE Plasma 桌面和常用应用:
261+
262+
* `sudo pacman -S --noconfirm plasma kde-system-meta kde-utilities-meta` 最小化安装,比较轻量
263+
* `sudo pacman -S --noconfirm plasma kde-applications` 完整安装(含所有 KDE 应用,比如浏览器、相册、邮件客户端等)
264+
265+
安装登录管理器(推荐 SDDM):
266+
267+
~~~bash
268+
sudo pacman -S --noconfirm sddm
269+
sudo systemctl enable sddm
270+
~~~
271+
272+
`sudo pacman -S noto-fonts noto-fonts-cjk noto-fonts-emoji adobe-source-han-sans-cn-fonts adobe-source-han-serif-cn-fonts` 安装 KDE 常用中文字体
273+
274+
手动指定QT环境变量,在 `~/.xprofile``~/.bashrc` 里加上:
275+
276+
~~~bash
277+
export LANG=zh_CN.UTF-8
278+
export LC_ALL=zh_CN.UTF-8
279+
export QT_QPA_PLATFORMTHEME=kde
280+
~~~
281+
282+

0 commit comments

Comments
 (0)