原创文章,转载请注明出处
https://qiedd.com/

一、 准备工作

0. 材料

ArchISO 镜像站:中科大 清华 腾讯云 阿里云
U盘一个
电脑一台(需要联网)

将 ArchISO 写入U盘, 推荐使用Rufus,轻巧简便
请使用DD方式写入!
启动方式选择UEFI

1. 启动到 ArchISO

启动到 ArchISO 后,我们需要连接网络,有些连接直接插网线就能通过 DHCP 获取到 IP
若为无线连接,则需要手动连接到 WiFi
ArchWiki 给我们提供了方法 https://wiki.archlinux.org/title/Iwd

# 使用iwctl连接WiFi
iwctl

# 查看设备
[iwd]# device list

# 如果知道的SSID和密码,可以直接连接到WIFI,我的设备为wlan0
[iwd]# station wlan0 connect 你的SSID

# 如果不知道SSID,则需要扫描WiFi
[iwd]# station wlan0 scan

# 获取扫描到的WiFi信息,然后再连接到WiFi
[iwd]# station wlan0 get-networks

# 连接到后推出即可
[iwd]# exit

# 然后查看获取到的IP
ip a

# 这是我的网卡
device list
NetworkConfigurationEnabled: disabled
StateDirectory: /var/lib/iwd
Version: 1.20
[iwd]# device list
                                    Devices                                   *
--------------------------------------------------------------------------------
  Name                Address             Powered   Adapter   Mode      
--------------------------------------------------------------------------------
  wlan0               ff:ff:ff:ff:ff:ff   on        phy0      station   

(可选)由于远程操操作命令一个个打很麻烦,我选择使用 SSH 连接后复制命令,因此我们需要设置密码和启动 sshd

# 启动sshd
systemctl start sshd  

# 设置密码
passwd

# 可以用windows自带的SSH功能,使用CMD即可
ssh root@你的ip

二、开始安装

0. 硬盘分区

在安装之前,我们需要硬盘分区,这里我使用的是 Windows11 + Arch 双系统,Windows11 和 Arch 都在一个盘上

# 查看硬盘分区
fdisk -l

# 这是我需要安装的硬盘
Disk /dev/nvme0n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: SAMSUNG MZVLB1T0HBLR-00000              
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: 88050E2B-CEC0-4FFE-9216-0C148782F384

Device             Start       End   Sectors   Size Type
/dev/nvme0n1p1      2048    206847    204800   100M EFI System
/dev/nvme0n1p2    206848    239615     32768    16M Microsoft reserved
/dev/nvme0n1p3    239616 837517311 837277696 399.2G Microsoft basic data
/dev/nvme0n1p4 837517312 838860799   1343488   656M Windows recovery environment

这里我的分区选择是
1G的EFI分区,剩下的空间都作为 Arch Linux 的根分区

如果你在一块全新的硬盘上安装
在创建分区时,请先使用 ’g‘ 来创建一个 GPT硬盘
或者使用 ’o‘ 来创建一个 MBR 硬盘

# 对/dev/nvme0n1进行硬盘分区
fdisk /dev/nvme0n1

# 分区步骤,默认回车
root@archiso ~ # fdisk /dev/nvme0n1

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

# 创建一个1G的分区 
Command (m for help): n
Partition number (5-128, default 5): 
First sector (838860800-2000409230, default 838860800): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (838860800-2000409230, default 2000409230): +1G

Created a new partition 5 of type 'Linux filesystem' and of size 1 GiB.

# 将剩下空间都给/分区
Command (m for help): n
Partition number (6-128, default 6): 
First sector (840957952-2000409230, default 840957952): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (840957952-2000409230, default 2000409230): 

Created a new partition 6 of type 'Linux filesystem' and of size 552.9 GiB.

# 更改分区/dev/nvme0n1p5的分区类型
Command (m for help): t
Partition number (1-6, default 6): 5
Partition type or alias (type L to list all): 1

Changed type of partition 'Linux filesystem' to 'EFI System'.

# 写入,保存设置
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

现在我们再看一下这块硬盘的分区

# 查看硬盘/dev/nvme0n1的分区
fdisk -l /dev/nvme0n1

Disk /dev/nvme0n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: SAMSUNG MZVLB1T0HBLR-00000              
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: 88050E2B-CEC0-4FFE-9216-0C148782F384

Device             Start        End    Sectors   Size Type
/dev/nvme0n1p1      2048     206847     204800   100M EFI System
/dev/nvme0n1p2    206848     239615      32768    16M Microsoft reserved
/dev/nvme0n1p3    239616  837517311  837277696 399.2G Microsoft basic data
/dev/nvme0n1p4 837517312  838860799    1343488   656M Windows recovery environment
/dev/nvme0n1p5 838860800  840957951    2097152     1G EFI System
/dev/nvme0n1p6 840957952 2000409230 1159451279 552.9G Linux filesystem

在安装之前,我们还需要对分区进行格式化
这里的 Bootloader 我们选择了 System-boot https://wiki.archlinux.org/title/Arch_boot_process#Feature_comparison
在 Wiki 上我们知道使用 System-boot 仅支持 UEFI 启动方式
并且 EFI 分区需要为 FAT 格式

# 格式化EFI分区
mkfs.vfat -F 32 /dev/nvme0n1p5

# 格式化根分区为ext4
mkfs.ext4 /dev/nvme0n1p6 

接下来我们需要将系统安装进分区中
但在之前我们需要先挂载硬盘,才能进行读写

# 挂载根分区到/mnt
mount /dev/nvme0n1p6 /mnt

# 创建/boot分区
mkdir /mnt/boot

# 挂载/boot分区
mount /dev/nvme0n1p5 /mnt/boot
1. 安装系统

然后我们就需要将系统安装进去了
在此之前,我们需要选择一个镜像源来下载
自带的都是国外源,慢的要死
我个人推荐使用中科大的源,清华的v4有时候会断流

# 编辑镜像源
vim /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://mirrors.cloud.tencent.com/archlinux/$repo/os/$arch
Server = https://mirrors.aliyun.com/archlinux/$repo/os/$arch

接下来就是安装系统了
需要根据你的CPU来安装支持

# AMD
pacstrap /mnt base linux linux-firmware base-devel vim os-prober amd-ucode openssh wget networkmanager

# INTEL
pacstrap /mnt base linux linux-firmware base-devel vim os-prober intel-ucode openssh wget networkmanager
2. 配置系统

为了让内核知道该硬盘该如何挂载
我们需要 /etc/fstab 来告知它

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

# 查看配置是否正确
cat /mnt/etc/fstab

我们还需要去配置我们刚刚安装的系统,因此需要chroot

# 挂载的分区在/mnt中,因此chroot到这个地方
arch-chroot /mnt

# 配置时间分区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc
date

# 语言支持
vim /etc/locale.gen

# 将需要的语言放在最前面保存即可
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8

# 安装
locale-gen

# 配置默认语言
vim /etc/locale.conf

# 添加到文件中,保存
LANG=en_US.UTF-8

# 设置Hostname
hostnamectl set-hostname 你的Hostname

# 设置hosts
vim /etc/hosts

# 添加到文件中
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

为了保证系统能够启动,我们还需要将 System-boot 安装进 /boot 分区中

# 在此之前,我们需要先获取到根分区的UUID,我的是/dev/nvme0n1p6,你需要自行查看自己的
lsblk -f

# 安装System-boot
bootctl --path=/boot$esp install

# 启动配置
vim /boot/loader/loader.conf 

# 留下这些配置即可
default  arch.conf
timeout  4
console-mode auto
editor   no

# 启动项
vim /boot/loader/entries/arch.conf

title   Arch Linux
linux   /vmlinuz-linux
initrd  /intel-ucode.img
initrd  /initramfs-linux.img
options root=UUID=你的分区的UUID rw 

# AMD
title   Arch Linux
linux   /vmlinuz-linux
initrd  /amd-ucode.img
initrd  /initramfs-linux.img
options root=UUID=你的分区的UUID rw 

在安装的最后,我们还需要配置一些第三方源
ArchLinuxCN源

# 编辑配置文件
vim /etc/pacman.conf

# 将此项加到最后面,保存退出
[archlinuxcn]
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch

# 安装ArchLinuxCN-keyring
pacman -Sy archlinuxcn-keyring

最后的最后,还需要设置密码
和让一些服务自启动

# 设置root密码
passwd

# 等下启动还要继续配置,先把ssh的允许root登录开了
vim /etc/ssh/sshd_config

# 找到PermitRootLogin prohibit-password改成yes
PermitRootLogin yes

# 网络管理自启动,不启动连不上网
systemctl enable NetworkManager

# 推出chroot
exit

# 取消挂载
umount -R /mnt

# 重启
reboot

三、启动后配置

1. 配置系统
# 如果需要WiFi联网
nmtui

# 启动sshd
systemctl start sshd

# 查看IP
ip a

# 开启ntp时间同步
timedatectl set-ntp true

# 双系统需要,不然时间会差8小时
timedatectl set-local-rtc 1
2. SHELL的选择

默认是 Bash,Bash确实很优秀,但还有许多优秀的 Shell,比如说 zsh,fish
这里我使用了FISH

# 安装fish
pacman -S fish

# 查看所有的Shell
chsh -l

# 选择默认Shell
chsh -s /bin/fish

# 创建一个用户
useradd -m -g users -s /bin/fish username

# 给这个用户设置密码
passwd username

# 配置sudo权限
vim /etc/sudoers

# 在root下方添加,我们这里配置了免密码
root ALL=(ALL) ALL
username ALL=(ALL) NOPASSWD:ALL
分类: Linux

2 条评论

koali · 2023年10月25日 下午11:51

1G的EFI分区?这个分区为什么要给这么大啊?

    Lordpenguindd · 2023年10月26日 上午12:38

    这个分区随便给,我放那么大只是因为可以塞个 Archiso,出问题可以直接 grub imageboot

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据