跳过正文
Install Arch

Install Arch

··
目录

注意:本文仅针对我本人使用的真实机器,如果参考本文请谨慎。

注意:命令行中带有 ! 的地方可能表示变量,可能需要将值更改为实际情况。

安装前
#

准备安装介质 & 启动实时环境
#

官方安装映像不支持安全启动,需要禁用安全启动才能启动安装介质。

我们使用ISO,启动后选择 Arch Linux install medium 并按 Enter 进入安装环境。

设置控制台字体
#

控制台字体位于 /usr/share/kbd/consolefonts/ 中,可以使用 setfont 进行字体设置:

# setfont ter-132b

验证启动模式
#

# cat /sys/firmware/efi/fw_platform_size

如果系统以 UEFI 模式启动,并具有64位 UEFI ,命令返回64。

连接到互联网
#

对于 Wi-Fi ,使用 iwctl 进行连接:

$ iwctl
[iwd]# device list
[iwd]# station !name scan
[iwd]# station !name get-networks
[iwd]# station !name connect SSID
[iwd]# quit

使用 ping 验证连接:

# ping hearthesea.one

更新系统时钟
#

在实时环境中,一旦建立互联网连接,时间将自动同步。

使用 timedatectl 确保系统时钟同步:

# timedatectl

对磁盘分区 & 格式化 & 加密( LUKS 上的 LVM 方案)
#

注意:本文默认使用 encrypt 钩子,因而此示例不允许将逻辑卷跨越多个磁盘。对于要将逻辑卷跨越多个磁盘,请使用 sd-encrypt 钩子。

磁盘布局为:

+-----------------------------------------------------------------------+ +----------------+
| Logical volume 1      | Logical volume 2      | Logical volume 3      | | Boot partition |
|                       |                       |                       | |                |
| [SWAP]                | /                     | /home                 | | /boot          |
|                       |                       |                       | |                |
| /dev/MyVolGroup/swap  | /dev/MyVolGroup/root  | /dev/MyVolGroup/home  | |                |
|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _| | (may be on     |
|                                                                       | | other device)  |
|                         LUKS encrypted partition                      | |                |
|                           /dev/sda1                                   | | /dev/sdb1      |
+-----------------------------------------------------------------------+ +----------------+

识别磁盘设备:

# fdisk -l

romloopairootfs 结尾的可以忽略。 mmcblk* 设备以 rpbmboot0boot1 结尾的可以忽略。

准备驱动器
#

分区之前,请检查驱动器是否使用最佳逻辑扇区大小:

要检查 NVMe 驱动器的逻辑块地址大小,可以使用 nvme-cli 程序:

# nvme id-ns -H /dev/!nvme0n1 | grep "Relative Performance"
-----------------------------------------------------------
LBA Format  0 : Metadata Size: 0   bytes - Data Size: 512 bytes - Relative Performance: 0x2 Good (in use)
LBA Format  1 : Metadata Size: 0   bytes - Data Size: 4096 bytes - Relative Performance: 0x1 Better

Metadata Size 最好选择值为 0 的格式( linux 不支持此功能)。

要更改逻辑块大小,使用 nvme format 并带有 --lbaf 参数以指定首选值:

# nvme format --lbaf=1 /dev/!nvme0n1
-----------------------------------------------------------
You are about to format nvme0n1, namespace 0x1.
WARNING: Format may irrevocably delete this device's data.
You have 10 seconds to press Ctrl-C to cancel this operation.

Use the force [--force] option to suppress this warning.
Sending format operation ... 
Success formatting namespace:1

使用 blkdiscard 擦除卷:

# blkdiscard --secure /dev/device

如果不支持安全擦除,使用 -z--zeroout 选项用 0 填充设备。

接下来准备驱动器:

首先,在要加密的分区(使用形式 sdXY )或完整设备(使用形式 sdX)上创建一个临时加密容器:

# cryptsetup open --type plain --key-file /dev/urandom --sector-size 4096 /dev/block-device to_be_wiped

您可以验证是否存在:

# lsblk
---------------------------------------------------
NAME          MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda             8:0    0  1.8T  0 disk
└─to_be_wiped 252:0    0  1.8T  0 crypt

用 0 擦除容器:

# dd if=/dev/zero of=/dev/mapper/to_be_wiped status=progress bs=1M
--------------------------------------------------------------------
dd: writing to ‘/dev/mapper/to_be_wiped’: No space left on device

最后关闭临时容器:

# cryptsetup close to_be_wiped

分区
#

所选设备需要以下分区:

  • 一个分区用于根目录 /
  • 为了以 UEFI 模式启动: EFI 系统分区

使用 fdisk 修改分区表, 例如:

# fdisk /dev/!the_disk_to_be_partitioned

首先用 fdisk 创建一个挂载到 /boot 的分区,大小为 1GB 或更大。然后使用剩余空间创建包含加密容器的分区。

接下来创建加密容器:

# cryptsetup luksFormat /dev/sda1

打开容器:

# cryptsetup open /dev/sda1 cryptlvm

解密的容器在 /dev/mapper/cryptlvm 上有效。

在打开的 LUKS 容器上创建一个物理卷

# pvcreate /dev/mapper/cryptlvm

创建一个卷组(在本例中为 MyVolGroup ,可以是任何您想要的名字),并将之前创建的物理卷添加到其中。

# vgcreate MyVolGroup /dev/mapper/cryptlvm

在卷组上创建逻辑卷:

注意:如果要使用 ext4 格式化逻辑卷,请在卷组中至少留出 256MiB 的可用空间,在使用 -l 100%FREE 创建最后一个卷后,使用 lvreduce -L -256M MyVolGroup/home 来减少大小。

# lvcreate -L 4G -n swap MyVolGroup
# lvcreate -L 32G -n root MyVolGroup
# lvcreate -l 100%FREE -n home MyVolGroup
# lvreduce -L -256M MyVolGroup/home # for ext4 format

格式化逻辑卷上的文件系统,这里我们选择使用 ext4 :

# mkfs.ext4 /dev/MyVolGroup/root
# mkfs.ext4 /dev/MyVolGroup/home
# mkswap /dev/MyVolGroup/swap

挂载文件系统:

# mount /dev/MyVolGroup/root /mnt
# mount --mkdir /dev/MyVolGroup/home /mnt/home
# swapon /dev/MyVolGroup/swap

准备启动分区
#

之前已经创建了启动分区,现在将其格式化:

# mkfs.fat -F 32 /dev/sdb1

警告:仅当您在分区步骤中创建了 EFI 系统分区时才需要对其进行格式化。如果磁盘上之前已经存在 EFI 系统分区,重新格式化该分区可能会破坏其他已安装操作系统的引导加载程序。

将分区挂载到 /mnt/boot :

# mount --mkdir /dev/sdb1 /mnt/boot

安装
#

选择镜像
#

我们使用 reflector 获取镜像,根据自己喜好编辑 /etc/xdg/reflector/reflector.conf ,然后运行:

# systemd start reflector

要想查看获取的镜像源:

# cat /etc/pacman.d/mirrorlist

安装必要的软件包
#

# pacstrap -K /mnt base linux linux-firmware lvm2 vi vim intel-ucode networkmanager base-devel reflector bash-completion zsh less

配置系统
#

Fatab
#

生成 fstab 文件:

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

检查生成的 /mnt/etc/fstab 文件。

Chroot
#

# arch-chroot /mnt

时间
#

设置时区:

# ln -sf /usr/share/zoneinfo/!Region/!City /etc/localtime
# hwclock --systohc

启用/启动 systemd-timesyncd.service

本土化
#

编辑 /etc/locale.gen 并取消注释 en_US.UTF-8 UTF-8 以及其他所需的 UTF-8 语言环境。运行以下命令生成语言环境:

# locale-gen

创建 locale.conf 文件,并相应地设置 LANG 变量:

/etc/locale.conf
-----------------
LANG=en_US.UTF-8

网络配置
#

创建主机名文件:

/etc/hostname
----------------
!yourhostname

Initramfs
#

keyboard, encryptlvm2 钩子添加到 /etc/mkinitcpio.conf (注意钩子间顺序和位置,如下):

HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems fsck)

重新生成 initramfs :

# mkinitcpio -P

root密码
#

设置 root 密码:

# passwd

引导加载程序
#

我们使用 GRUB 。

首先,安装 grub 和 efibootmgr 软件包:

# pacman -S grub efibootmgr

执行以下命令将 GRUB EFI 应用程序 grubx64.efi 安装到 esp/EFI/GRUB/ 并将其模块安装到 /boot/grub/x86_64-efi/

# grub-install --target=x86_64-efi --efi-directory=!esp --bootloader-id=GRUB

esp 为你的 EFI 分区挂载点。

对于加密分区,还要添加以下内核参数:

cryptdevice=UUID=!device-UUID:cryptlvm root=/dev/MyVolGroup/root

device-UUID 在本例中指的是 /dev/sda1 (即加密分区)的 UUID ,使用 lsblk -f >> uuid.txt 命令在 uuid.txt 中查看并复制。

要在 GRUB 上添加内核参数,编辑 /etc/default/grub 并将内核参数附加到 GRUB_CMDLINE_LINUX_DEFAULT 行的引号之间。

使用以下命令生成主配置文件:

# grub-mkconfig -o /boot/grub/grub.cfg

重启
#

# exit
# umount -R /mnt
# reboot

移除安装介质,然后使用 root 账户登陆新系统。

安装后
#

连接网络
#

启用并启动 NetworkManager.service

使用 nmcli 连接 Wi-Fi 网络:

$ nmcli device wifi list
$ nmcli device wifi connect !SSID_or_BSSID password !password

添加用户
#

# useradd -m !archie
# passwd !archie

安全
#

使用 sudo
#

# visudo

拒绝 root SSH 登录
#

/etc/ssh/sshd_config.d/20-deny_root.conf
-----------------------------------------
PermitRootLogin no

防火墙
#

安装 firewalld 包。

# pacman -S firewalld

启用并启动 firewalld.service

锁定 BIOS
#

在 BIOS 中添加密码。

系统维护
#

# pacman -S rebuild-detector archlinux-contrib

pacdiff , checkrebuild , checkupdates , checkservices

另外还可以配置 reflector

图形界面
#

显示驱动程序
#

# pacman -S mesa vulkan-intel

SDDM
#

安装 sddm 包,启用 sddm.service,这应该可以直接启用。

安装 weston 以启用 wayland 支持,在 /etc/sddm.conf.d/ 下创建一个配置文件,给它起一个有意义的名字并添加以下内容:

/etc/sddm.conf.d/wayland.conf
----------------------------------
[General]
DisplayServer=wayland

桌面环境
#

我目前并没有使用完整的桌面环境,如果考虑使用完整的桌面环境,可以考虑 gnome, kde, xfce4 等。

dotfiles
#

由于之前我使用的一个用户的点文件仓库已经不再使用 Hyprland ,因此我自己私下创建了一个仓库,通过修改1amSimp1e/dots这个仓库的配置文件以适应最新的 Hyprland 版本,目前我不再依赖其他人的点文件。

其他的图形软件
#
  • 浏览器:firefox firefox-i18n-zh-cn chromium
  • 文件管理器:thunar gvfs file-roller thunar-archive-plugin thunar-media-tags-plugin thunar-volman tumbler ffmpegthumbnailer
  • 密码管理器:keepassxc
  • 备份:rclone restic
  • gnome 系列:gnome-firmware gnome-disk-utility gnome-system-monitor eog baobab
  • 音乐:spotify-launcher
  • 输入法:fcitx5-im fcitx5-chinese-addons fcitx5-pinyin-zhwiki fcitx5-nord
  • 录屏:obs-studio
  • email: thunderbird thunderbird-i18n-zh-cn
  • 通讯:telegram-desktop
  • 播放器:vlc vlc-plugins-all
  • 图片编辑:drawing
  • 其他工具:yt-dlp hugo go clang meson git qbittorrent
fcitx5
#

主要描述一些环境变量的设置(wayland)。

有以下环境变量(全局):

QT_IM_MODULE=fcitx
QT_IM_MODULES="wayland;fcitx;ibus"
XMODIFIERS=@im=fcitx

对于 GTK2,将以下内容添加到 ~/.gtkrc-2.0 :

gtk-im-module="fcitx"

对于 GTK3,将以下内容添加到 ~/.config/gtk-3.0/settings.ini

[Settings]
gtk-im-module=fcitx

对于 GTK4,将以下内容添加到 ~/.config/gtk-4.0/settings.ini

[Settings]
gtk-im-module=fcitx

电源管理
#

tlp
#

安装 tlp 包。

启用/启动 tlp.service

还应该屏蔽 (mask) 服务 systemd-rfkill.service 和套接字 systemd-rfkill.socket

CPU 调频
#

安装 cpupower 包。

cpupower 的配置文件位于 /etc/default/cpupower ,请根据设备情况进行编辑。

启用/启动 cpupower.service

存档和压缩
#

安装 7zip 和 unzip 包。

蓝牙
#

如果系统没有完整的桌面环境(例如 GNOME ),可以:

安装 blueman 包。

启用/启动 bluetooth.service

作者
Ask Me Why