安装Arch Linux简化整理

相比一些linux发行版的安装过程, Arch Linux的有些不同. 尽管整个过程难度并不大, 但通过安装Arch Linux, 可以学到不少东西, 至少可以加深对Linux系统的浅层理解. 正好前段时间重新安装了一次系统, 顺便做一下记录和整理.

总体来说, 这是一项"会读文档即可完成"的任务, 官方文档也有非常完整的 Installation guide. 所以这一篇算是我个人对其的整理, 精简最少部署操作, 和一些可能会出现或我遇到的问题.

简化流程

Arch Linux Downloads, 系统安装启动盘的下载和使用, 作为基础, 可自行完成这一步.

可以用网线连接到网络, 或wifi-menu连接无线, 启动sshd, 然后便可用其他机子登陆. 记得passwd设置下密码, 不然可能登陆会有问题.

检查主板是否为UEFI启动

root@archiso ~ # ls /sys/firmware/efi
config_table efivars esrt fw_platform_size fw_vendor runtime runtime-map systab

硬盘分区

查看细节信息fdisk -l, 计划分区结果

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 931.5G  0 disk 
└─sda1        8:1    0 931.5G  0 part /data
nvme0n1     259:0    0 476.9G  0 disk 
├─nvme0n1p1 259:1    0   512M  0 part /boot
├─nvme0n1p2 259:2    0    16G  0 part [SWAP]
└─nvme0n1p3 259:3    0 460.4G  0 part /

root@archiso ~ # fdisk /dev/nvme0n1

Command (m for help): m
Help:

  GPT
   M   enter protective/hybrid MBR

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


# 硬盘标记为GPT
Command (m for help): g
Created a new GPT disklabel (GUID: A7D28295-2F5D-C240-B933-2D0B0C30676B).
The old dos signature will be removed by a write command.


# 分区
Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-1000215182, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1000215182, default 1000215182): +512M

Created a new partition 1 of type 'Linux filesystem' and of size 512 MiB.

Command (m for help): n
Partition number (2-128, default 2): 
First sector (1050624-1000215182, default 1050624): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-1000215182, default 1000215182): +16G

Created a new partition 2 of type 'Linux filesystem' and of size 16 GiB.

Command (m for help): n
Partition number (3-128, default 3): 
First sector (34605056-1000215182, default 34605056): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (34605056-1000215182, default 1000215182): 

Created a new partition 3 of type 'Linux filesystem' and of size 460.4 GiB.


# 修改分区类型
Command (m for help): t
Partition number (1-3, default 3): 1
Partition type (type L to list all types): 1

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

Command (m for help): t
Partition number (1-3, default 3): 2
Partition type (type L to list all types): 19

Changed type of partition 'Linux filesystem' to 'Linux swap'.


Command (m for help): p
Disk /dev/nvme0n1: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: INTEL SSDPEKKW512G7                     
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: A41541EE-ED19-BF4C-A4F5-23912AD802BC

Device            Start        End   Sectors   Size Type
/dev/nvme0n1p1     2048    1050623   1048576   512M EFI System
/dev/nvme0n1p2  1050624   34605055  33554432    16G Linux swap
/dev/nvme0n1p3 34605056 1000215182 965610127 460.4G Linux filesystem

# 最后, 保存修改并退出

格式化硬盘分区

root@archiso ~ # mkfs.vfat /dev/nvme0n1p1
mkfs.fat 4.1 (2017-01-24)

root@archiso ~ # mkswap /dev/nvme0n1p2 
Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
no label, UUID=62d861f8-e16f-4962-8676-275486da9055

root@archiso ~ # mkfs.ext4 /dev/nvme0n1p3 
mke2fs 1.45.4 (23-Sep-2019)
Discarding device blocks: done                            
Creating filesystem with 120701265 4k blocks and 30179328 inodes
Filesystem UUID: 1283f1cb-dfe1-41fd-8a15-72a0441e3e28
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

安装系统

挂挂载区, 安装系统文件, 并切换root到系统. 建议先修改镜像配置vim /etc/pacman.d/mirrorlist, 将优先镜像地址放到文件前方.

root@archiso ~ # mount /dev/nvme0n1p3 /mnt
root@archiso ~ # mkdir /mnt/boot 
root@archiso ~ # mount /dev/nvme0n1p1 /mnt/boot 
root@archiso ~ # swapon /dev/nvme0n1p2 

# 配置fstab保存
# genfstab -U /mnt >> /mnt/etc/fstab

root@archiso ~ # pacstrap /mnt 
root@archiso ~ # pacstrap /mnt base linux linux-firmware linux-headers vim

root@archiso ~ # arch-chroot /mnt

安装boot loader, 此处使用systemd-boot.

[root@archiso /]# bootctl install
Created "/boot/EFI".
Created "/boot/EFI/systemd".
Created "/boot/EFI/BOOT".
Created "/boot/loader".
Created "/boot/loader/entries".
Created "/boot/EFI/Linux".
Copied "/usr/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/systemd/systemd-bootx64.efi".
Copied "/usr/lib/systemd/boot/efi/systemd-bootx64.efi" to "/boot/EFI/BOOT/BOOTX64.EFI".
Created "/boot/a6a052d31d234969836d386dc3ce427b".
Random seed file /boot/loader/random-seed successfully written (512 bytes).
Successfully initialized system token in EFI variable with 512 bytes.
Created EFI boot entry "Linux Boot Manager".

修改boot配置

[root@archiso ~]# vim /boot/loader/loader.conf 
timeout 4
#console-mode keep
default arch
[root@archiso ~]# vim /boot/loader/entries/arch.conf
title   Arch Linux
linux   /vmlinuz-linux
initrd  /initramfs-linux.img
options root=PARTUUID=83dde363-9c00-4d4c-9d90-d8a92d0597ee rw
BTW, :r !blkid in vim, options root=PARTUUID=*** nvidia-drm.modeset=1 isolcpus=2 nohz_full=2 rw for kernel parameter.

完成

不过在退出重启之前, 建议先安装一些软件包, 很多为arch缺省不带, 例如网络管理, ssh等. pacman -Sy networkmanager openssh.

另外, 此列表软件不为高优先级, 仅推荐, 可后续按需安装, 不全 sudo base-devel man net-tools usbutils bash-completion tree
pulseaudio-bluetooth bluez-utils wqy-microhei noto-fonts-emoji

Post-installation

当然, 仅此可能还远未达到舒适系统环境, 其他配置和更多可参考 General recommendations.

显卡驱动, NVIDIA. nvidia-xconfig生成Xorg server配置文件, 启用N卡渲染. 添加nvidia-drm.modeset=1内核启动项, 启动DRM.