安装 Arch Linux

制作启动盘

  1. 下载 Live ISO:

    wget https://mirrors.tuna.tsinghua.edu.cn/archlinux/iso/latest/archlinux-x86_64.iso
    
  2. 写入 Live ISO 到 U 盘:

    参见:macOS 烧录启动盘

  3. 从 U 盘启动。

    MSI: DEL: Setup Menu, F11: Boot Menu

    你将以 root 身份登录 Live 系统控制台。

分区与格式化

  1. 列出磁盘列表:

    lsblk -d | grep disk
    
  2. 编辑磁盘分区:

    parted /dev/sdX -s mklabel gpt                      # 创建 GPT 分区表
    parted /dev/sdX -s mkpart ESP fat32 1MiB 301MiB     # 创建 300MiB ESP 分区(使用分区对齐)
    parted /dev/sdX -s set 1 esp on                     # 设置 ESP 分区标志
    parted /dev/sdX -s mkpart primary ext4 301MiB 100%  # 创建主分区
    
  3. 格式化分区:

    mkfs.fat -F 32 /dev/sdX1  # 格式化 ESP 分区
    mkfs.ext4 /dev/sdX2       # 格式化主分区
    
  4. 挂载文件系统:

    mount /dev/sdX2 /mnt                               # 挂载根卷
    mount -m -o fmask=0077,dmask=0077 /dev/sdX1 /boot  # 挂载 ESP 分区
    
  5. 生成 fstab 文件:

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

安装系统

  1. 连接因特网。

    • 如果使用有线网,插入网线即可。

    • 如果使用无线网,使用下面的命令连接 Wi-Fi:

      iwctl station wlan0 connect <SSID>
      

      参见:iwctl

  2. 安装软件包:

    # 设置镜像源(可选)
    echo 'Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch' > /etc/pacman.d/mirrorlist
    
    # 安装软件包
    pacstrap -K /mnt base linux linux-firmware     # 基本组件、内核及常见固件
    pacstrap -K /mnt sudo vim openssh systemd iwd  # 功能性软件包
    
    • iwd:Intel 开发的现代化无线网络管理守护进程
  3. 切换根目录为系统安装目录:

    arch-chroot /mnt
    
  4. 设置时区:

    timedatectl set-timezone Asia/Shanghai                  # 设置时区
    ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime  # 创建时区文件
    hwclock -w                                              # 从系统时钟设置硬件时钟
    
  5. 设置语言:

    sed -i 's/#en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
    locale-gen
    echo 'LANG=en_US.UTF-8' > /etc/locale.conf
    
  6. 设置主机名:

    echo 'archlinux' > /etc/hostname
    
  7. 创建普通用户:

    useradd -mG wheel -s /usr/bin/bash jdoe
    passwd jdoe
    

    编辑 sudo 配置文件:

    EDITOR=vim visudo
    
    -# %wheel ALL=(ALL:ALL) ALL
    +%wheel ALL=(ALL:ALL) ALL
    

安装引导程序

GRUB

pacman -S grub efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB  # 安装 GRUB
grub-mkconfig -o /boot/grub/grub.cfg                                         # 生成配置文件

需要禁用 UEFI 的 Secure Boot 功能

systemd-boot

  1. 安装 systemd-boot

    bootctl install
    

    systemd-boot 默认支持 Secure Boot

  2. 编辑启动文件:

    vim /boot/loader/entries/arch.conf
    
    title   Arch Linux
    linux   /vmlinuz-linux
    initrd  /initramfs-linux.img
    options root=UUID=your-root-partition-uuid rw
    

    使用命令 blkid /dev/sdX2 查询分区 UUID

  3. 配置默认启动项:

    vim /boot/loader/loader.conf
    
    default arch
    timeout 5
    

最后,拔掉启动 U 盘,然后重启系统:

exit
umount -R /mnt
reboot

后续设置

  1. 设置网络:

    sudoedit /etc/systemd/network/20-wired.network
    
    [Match]
    Name=enp*
    
    [Network]
    DHCP=yes
    DNS=8.8.8.8 1.1.1.1
    Domains=local
    
    [DHCPv4]
    UseDNS=yes
    UseRoutes=yes
    
    # 启动网络后端
    sudo systemctl enable systemd-networkd
    sudo systemctl start systemd-networkd
    
    # 启动 DNS 后端
    sudo systemctl enable systemd-resolved
    sudo systemctl start systemd-resolved
    

    若使用无线网络,还需启动 iwd

    sudo systemctl enable iwd
    sudo systemctl start iwd
    iwd station wlan0 connect <SSID>
    
  2. 设置镜像源:

    wget -O /etc/pacman.d/mirrorlist "https://archlinux.org/mirrorlist/?country=CN&protocol=http&ip_version=4&use_mirror_status=on"
    sudo sed -i "s/#Server/Server/" /etc/pacman.d/mirrorlist
    

    参见:Pacman Mirrorlist Generator

  3. 安装 yay 或 paru:

    yayparu 都是 AUR 的包管理工具。yay 最先推出,使用 Go 编写。后来 yay 的维护者之一创建了 paru,使用 Rust 编写。

    # 安装 yay
    sudo pacman -S --needed git base-devel
    git clone https://aur.archlinux.org/yay-bin.git && cd yay-bin
    makepkg -si
    cd .. && rm -rf yay-bin
    
    # 安装 paru
    sudo pacman -S --needed base-devel rustup
    rustup default stable
    git clone https://aur.archlinux.org/paru.git && cd paru
    makepkg -si
    cd .. && rm -rf paru
    

    你可以同时安装 yay 和 paru

  4. 启动 SSH:

    sudo systemctl start sshd
    sudo systemctl enable sshd
    
  5. 安装 CPU 微码

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

    虚拟机不需要安装 CPU 微码

参考:

PS:WSL 安装 Arch Linux

wsl --install archlinux

Troubleshooting

无法找到 GRUB 引导程序

一些主板(如微星)只会寻找 esp/EFI/BOOT/BOOTX64.EFI 作为引导程序。需要使用 --removable 选项以将引导程序安装到该位置:

grub-install --target=x86_64-efi --efi-directory=/boot --removable
grub-mkconfig -o /boot/grub/grub.cfg

prohibited by secure boot policy

启动时出现如下错误:

error: prohibited by secure boot policy.

解决方法:在 UEFI 中禁用 Secure Boot,或者使用 sbctl 对 GRUB 和内核签名。

启动后卡在 UEFI Interactive Shell

问题原因:UEFI 没有找到引导项。

解决方法:手动加载引导程序,启动系统后重新添加引导项。

  1. 加载引导程序:

    FS0:\EFI\GRUB\grubx64.efi
    
  2. 系统启动后,重新添加引导项:

    sudo efibootmgr -c -d /dev/sdX -p 1 -L "GRUB" -l '\EFI\GRUB\grubx64.efi'
    

参考:Stuck in UEFI Shell | Reddit

posted @ 2025-05-22 00:22  Undefined443  阅读(70)  评论(0)    收藏  举报