最近安装了一个 archlinux 玩玩, 发现真的挺麻烦的。我反复安装过几次,在这里记录一下我安装和配置基本系统的经历。

关于安装 arch 的一些建议

arch 有非常完善,非常强大的 wiki 文档以及社区,在其中可以找到很多很多的帮助:
arch 的 wiki

系统的安装

安装一个系统,首先要制作一个安装介质,比如 USB 驱动器。

制作 USB flash drive

制作 archlinux 安装介质(USB 驱动器)的步骤:

  1. 准备一个大小至少 2GB 的U盘,并备份好U盘中的数据(操作过程会将U盘格式化,清空其中的数据)
  2. 在 arch 下载页面 下载 arch 的可引导 ISO 文件。
  3. 下载并安装 rufus ,按照提示将 arch 的可引导 IOS 文件刻录到 USB 安装媒介。

配置 live 环境

  1. 在计算机加电自检时快速按下某个热键,进入引导加载程序菜单,选择 Arch Linux install medium 进入安装环境,安装环境默认的 Shell 是 Zsh。

  2. 第一步是连接互联网,可以直接使用有线网络,连接网线之后会自动联网,也可以使用 iwctl 认证无线网络。:

    1. 进入 iwctl 的交互式提示符:

      1
      [arch]# iwctl
    2. 连接网络:

      1
      2
      3
      4
      5
      6
      7
      [iwd]# device list  # 列出所有 WiFi 设备
      [iwd]# device <name> set-property Powered on # 如果设备 <name> 或相应的适配器 <adapter> 已关闭,将其打开
      [iwd]# device <adapter> set property Powered on
      [iwd]# station <name> scan # scan networks
      [iwd]# station <name> get-networks # list all available networks
      [iwd]# station <name> connect <SSID> # connect to a network (Use the SSID of the network listed above)
      [iwd]# exit # exit the interactive prompt of iwctl
    3. 检查网络连接:

      1
      [arch]# ping www.baidu.com 
  3. 创建硬盘分区:

    1. 查看硬盘分区:

      1
      [arch]# lsblk 
    2. 修改分区表:

      1
      [arch]# cfdisk /dev/<disk_name>
    3. 格式化分区:

      1
      2
      3
      [arch]# mkfs.ext4 /dev/root_partition
      [arch]# mkfs.fat -F 32 /dev/efi_system_partition # If you created a new EFI partition
      [arch]# mkswap /dev/swap_partitoin # If you created a partition for swap
  4. 挂载硬盘分区

    1
    2
    3
    4
    [arch]# mount /dev/root_partition /mnt
    [arch]# mount --mkdir /dev/efi_partition /mnt/boot
    [arch]# swapon /dev/swap_partition # If you created a partition for swap
    [arch]# lsblk # Check if the partitions are mounted

安装基本系统

在配置好了 live 环境之后就可以进行基本系统的安装了:

  1. 选择镜像源。(在这一步创建的镜像源列表会直接传入新系统中)
    此处可以直接使用 reflector 自动选择,也可以手动编辑镜像源列表。

    1. 使用 reflector:
      首先编辑 /etc/xdg/reflector/reflector.conf 文件,加入下面这一行:

      text
      1
      --country China
      1
      2
      [arch]# systemctl start reflector.service # Start the reflector.service
      [arch]# cat /etc/pacman.d/mirrorlist # Check the mirrorlist.
    2. 手动添加:
      访问官方镜像源列表,并将其中最快的镜像源写入文件 /etc/pacman.d/mirrorlist

  2. 安装基本系统以及必需软件包:

    1
    [arch]# pacstrap -K /mnt base linux linux-firmware vim networkmanager sudo

配置新系统

安装好基本系统之后便可以进行一些基本的配置:

  1. 创建文件系统表 Fstab:

    1
    [arch]# genfstab -U /mnt >> /mnt/etc/fstab
  2. Chroot into 新系统:

    1
    [arch]# arch-chroot /mnt
  3. 设置时区和地区:
    首先编辑文件 /etc/locale.gen,取消对以下两行的注释

    text
    1
    2
    en_US.UTF-8 UTF-8
    zh_CN.UTF-8 UTF-8
    1
    2
    3
    4
    5
    [arch]# locale-gen # Generate the locales.
    [arch]# echo LANG=en_US.UTF-8 > /etc/locale.conf # Set the LANG variable accordingly.
    [arch]# timedatectl set-timezone Asia/Shanghai # Set the timezone.
    [arch]# timedatectl set-ntp true # Enable the NTP(Network Time Protocal)
    [arch]# timedatectl # Check the time.
  4. 设置主机名:

    1
    [arch]# echo <yourhostname> > /etc/hostname
  5. 设置 root 密码:

    1
    [arch]# passwd
  6. 安装 grub:

    1
    2
    3
    [arch]# pacman -S grub efibootmgr os-prober
    [arch]# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=<Grub_entry_name>
    [arch]# grub-mkconfig -o /boot/grub/grub.cfg # Generate the main configure file.

    如果想要添加其它系统的引导项,进行下面的配置:
    编辑文件 /etc/default/grub,取消下面这一行的注释:

    text
    1
    GRUB_DISABLE_OS_PROBER=false

    然后再次生成 grub 主配置文件:

    1
    [arch]# grub-mkconfig -o /boot/grub/grub.cfg
  7. 重启系统,拔掉U盘,进入 UEFI 启动引导项菜单,选择进入新安装的 arch 系统