Arch Linux 系统安装

前言

我安装一直参考的是《Arch Linux 安装使用教程 - ArchTutorial - Arch Linux Studio》的教程。这里做一些精简,同时为了防止因为墙太厚访问不到教程。

在通过 PE 进入到 Arch Linux 的命令行界面后安装正式开始。

禁用 Reflector

systemctl stop reflector

连接网络

#执行iwctl命令,进入交互式命令行
iwctl

#列出设备名,比如无线网卡看到叫 wlan0
device list
#扫描网络
station wlan0 scan
#列出网络 比如想连接YOUR-WIRELESS-NAME这个无线
station wlan0 get-networks
#进行连接 输入密码即可
station wlan0 connect WIRELESS-NAME
# 退出
exit

更新系统时钟

#将系统时间与网络时间进行同步
timedatectl set-ntp true

分区

分三个区(一定要把 root 和 home 分开,下次再装系统的时候只用格式化 root, home 下的配置文件全部保留):

  • EFI: /efi, 800M
  • root: /, 100 - 150G
  • home: /home, 剩余空间

磁盘类型转换

#显示分区情况
lsblk

#进入交互式命令行,进行磁盘类型变更
parted /dev/sdx

#输入mktable
>> mktable
#输入gpt 将磁盘类型转换为gpt 如磁盘有数据会警告,输入yes即可
>> New disk label type? gpt
# 退出
>> quit

分区操作

# 使用 cfdisk 执行分区操作,分配各个分区大小、类型
cfdisk /dev/sdx
#分区结束后,复查磁盘情况
fdisk -l
  • EFI 设为第一分区
  • EFI 格式为 EFI System, 其余为 Linux filesystem

格式化

mkfs.ext4  /dev/sdax            #格式化根目录和home目录的两个分区
mkfs.vfat  /dev/sdax            #格式化efi分区

挂载

mount /dev/sdax  /mnt
mkdir /mnt/efi     #创建efi目录
mount /dev/sdax /mnt/efi
mkdir /mnt/home    #创建home目录
mount /dev/sdax /mnt/home

安装系统

更新镜像源

# /etc/pacman.d/mirrorlist

# 分别是中科大和清华的源
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch

# 有魔法后可以用下面这几个
Server = https://mirror.archlinux.tw/ArchLinux/$repo/os/$arch
Server = https://mirror.0xem.ma/arch/$repo/os/$arch
Server = https://mirror.aktkn.sg/archlinux/$repo/os/$arch
Server = https://archlinux.uk.mirror.allworldit.com/archlinux/$repo/os/$arch
Server = https://mirrors.cat.net/archlinux/$repo/os/$arch

安装必需包

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

安装功能性包

pacstrap /mnt dhcpcd iwd vim bash-completion

生成磁盘 fstab 文件

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

系统基本设置

# 切换环境到新系统下
arch-chroot /mnt

时区设置

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc

本地化设置

编辑 /etc/locale.gen, 去掉 en_US.UTF-8 所在行以及 zh_CN.UTF-8 所在行的注释。然后:

locale-gen
echo 'LANG=en_US.UTF-8'  > /etc/locale.conf

设置主机名

# write HOST-NAME to /etc/hostname

# /etc/hosts
127.0.0.1   localhost
::1         localhost
127.0.1.1   HOSTNAME

# set root's password
passwd root

安装微码

pacman -S intel-ucode   #Intel
pacman -S amd-ucode     #AMD

安装引导程序

pacman -S grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB

编辑 /etc/default/grub, 将 GRUB_CMDLINE_LINUX_DEFAULT 置为 loglevel=5 nowatchdog.

# 生成 GRUB 配置文件
grub-mkconfig -o /boot/grub/grub.cfg

基础安装完成

# 退回安装环境
exit
# 卸载新分区
umount -R  /mnt
# 重启
reboot

# 重启之后开启网络
systemctl start dhcpcd
# if needed
systemctl start iwd

系统基础设置

先升级一遍系统包

pacman -Syyu

新建非 root 用户

useradd -m -G wheel -s /bin/bash USER
passwd USER

# 需要以 root 用户运行 visudo 命令
EDITOR=vim visudo
# 取消这行的注释
# %wheel ALL=(ALL) ALL

设置交换文件 swap

# 创建4G的交换空间 大小根据需要自定
dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
# 设置正确的权限
chmod 600 /swapfile
# 格式化swap文件
mkswap /swapfile
# 启用swap文件k
swapon /swapfile
# 追加以下到 /etc/fstab
/swapfile none swap defaults 0 0

安装 yay

Original Source

pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay-bin.git
cd yay-bin
makepkg -si

Arch Linux Studio Source

wget https://raw.githubusercontent.com/ArchLinuxStudio/ArchLinuxTutorial/master/docs/res/yay-bin-11.1.2-1-x86_64.pkg.tar.zst
sudo pacman -U yay-bin-11.1.2-1-x86_64.pkg.tar.zst

基础性工具

# 声音固件
yay -S sof-firmware alsa-firmware alsa-ucm-conf
# 识别 NTFS 格式的硬盘
yay -S ntfs-3g
# 思源字体
yay -S adobe-source-han-serif-cn-fonts adobe-source-han-sans-cn-fonts
# 文泉驿, 霞鹜文楷
yay -S wqy-zenhei
# 安装谷歌开源字体及表情
yay -S noto-fonts-cjk noto-fonts-emoji noto-fonts-extra
# 等宽字体
yay -S ttf-fantasque-nerd ttf-maple
# 好看的英文字体
yay -S ttf-spectral
# 一些工具
yay -S git wget networkmanager

DNS 配置

# /etc/resolv.conf
nameserver 8.8.8.8
nameserver 2001:4860:4860::8888
nameserver 8.8.4.4
nameserver 2001:4860:4860::8844
# 设置文件不可变
chattr +i /etc/resolv.conf

开启 32 位库支持

vim /etc/pacman.conf
# 去掉[multilib]一节中两行的注释
yay -Syyu

以非 root 用户登录

至此, Arch Linux 的安装基本完成,后续便是以非 root 用户启动,安装应用程序,配置 Hyprland.

reboot
Powered by Org Mode.