Contents

Archlinux 小记-001 基础安装

一、安装准备


1. 物理机

  1. 确认网络连接通畅
  2. 下载安装镜像
  3. 刻录安装 U 盘

2. 虚拟机

请参考:虚拟机安装前的准备

二、基础安装


1. 禁用 reflector 服务

1
systemctl stop reflector.service

2. 确认 UEFI 模式

1
ls /sys/firmware/efi/efivars/

3. 连接网络

1
2
3
4
5
6
7
8
rfkill unblock wifi
iwctl
device list
station wlan0 scan
station wlan0 get-networks
station wlan0 connect wifi-name
exit
ping www.bilibili.com #测试网络

4. 更新系统时钟

1
2
timedatectl set-ntp true # 将系统时间与网络时间进行同步
timedatectl status # 检查服务状态

5. 换源

编辑源文件

1
vim /etc/pacman.d/mirrorlist

推荐源如下,择其一添加即可

1
2
3
4
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch # 中国科学技术大学开源镜像站
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch # 清华大学开源软件镜像站
Server = https://repo.huaweicloud.com/archlinux/$repo/os/$arch # 华为开源镜像站
Server = http://mirror.lzu.edu.cn/archlinux/$repo/os/$arch # 兰州大学开源镜像站

6. 分区与格式化


6-1. win10、Arch 双系统 Btrfs 文件系统分区

  • / + /home 根目录+主目录:>= 128GB
  • /boot EFI 分区:512MB
  • Swap 分区:>= 60%运存

SATA 协议硬盘中,x为字母abc等;NVME 协议硬盘中,x为数字123

1
2
cfdisk /dev/nvmexn1 #按需求分配内存
fdisk -l #完成后,复查分区情况

6-2. 格式化并创建 Btrfs 子卷

1
2
3
4
5
6
7
8
mkfs.fat -F32 /dev/nvmexn1pn #格式化 EFI 分区
mkfs.btrfs -L myArch /dev/nvmexn1pn #格式化 Btrfs 分区

mount -t btrfs -o compress=zstd /dev/nvmexn1pn /mnt #挂载 Btrfs 分区于 /mnt 下
btrfs subvolume create /mnt/@ #创建 / 目录子卷
btrfs subvolume create /mnt/@home #创建 /home 目录子卷

umount /mnt #卸载 /mnt 以挂载子卷

7. 挂载


1
2
3
4
5
6
7
# 按顺序挂载
mount -t btrfs -o subvol=/@,compress=zstd /dev/nvmexn1pn /mnt #挂载 / 目录
mkdir /mnt/home #创建 /home 目录
mount -t btrfs -o subvol=/@home,compress=zstd /dev/nvmexn1pn /mnt/home #挂载 /home 目录
mkdir -p /mnt/boot #创建 /boot 目录
mount /dev/nvmexn1pn /mnt/boot #挂载 /boot 目录
swapon /dev/nvmexn1pn #挂载交换分区

8.安装系统


  1. 若镜像非最新,可能出现 GPG 证书错误,更新archlinux-keyring以解决
1
pacman -S archlinux-keyring
  1. 安装必要软件
1
pacstrap /mnt dhcpcd networkmanager neovim sudo zsh zsh-completions

9. 生成 fstab 文件


  1. 生成并写入 fstab 文件:
1
genfstab -U /mnt > /mnt/etc/fstab
  1. 复查/mnt/etc/fstab
1
cat /mnt/etc/fstab

10. change root


1
arch-chroot /mnt #切换系统环境至新系统

11. 收尾配置


  1. 设置主机名
1
nvim /etc/hostname
  1. 配置/etc/hosts
1
nvim /etc/hosts

加入以下内容

1
2
3
127.0.0.1   localhost
::1         localhost
127.0.1.1   myarch.localdomain myarch
  1. 设置时间
1
2
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #设置时区
hwclock --systohc #同步硬件时间
  1. Locale 本地化
1
2
3
4
5
6
7
nvim /etc/locale.gen #编辑 /etc/locale.gen
    en_US.UTF-8 UTF-8 #取消注释
    zh_CN.UTF-8 UTF-8 #取消注释

locale-gen #生成 locale

echo 'LANG=en_US.UTF-8'  > /etc/locale.conf
  1. 为 root 用户设置密码
1
passwd root
  1. 安装微码
1
2
pacman -S intel-ucode # Intel
pacman -S amd-ucode # AMD
  1. 安装引导程序
1
2
3
4
5
pacman -S grub efibootmgr os-prober #安装对应包
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Arch #安装 GRUB 到 EFI 分区
echo 'GRUB_DISABLE_OS_PROBER=false' > /etc/default/grub #引导 win10

grub-mkconfig -o /boot/grub/grub.cfg #生成 GRUB 配置文件
  1. 禁用蜂鸣器
1
2
touch /etc/modprobe.d/nobeep.conf
echo 'blacklist pcspkr' > /etc/modprobe.d/nobeep.conf

12. 完成安装


1
2
3
exit #退回安装环境
umount -R /mnt #卸载新分区
reboot #重启
参考链接

  1. ArchWiki Installation guide
  2. Archlinux 简明指南