My experience using archlinux
最近安装了一个 archlinux 玩玩, 发现真的挺麻烦的。我反复安装过几次,在这里记录一下我安装和配置基本系统的经历。
关于安装 arch 的一些建议
arch 有非常完善,非常强大的 wiki 文档以及社区,在其中可以找到很多很多的帮助:
arch 的 wiki
系统的安装
安装一个系统,首先要制作一个安装介质,比如 USB 驱动器。
制作 USB flash drive
制作 archlinux 安装介质(USB 驱动器)的步骤:
- 准备一个大小至少 2GB 的U盘,并备份好U盘中的数据(操作过程会将U盘格式化,清空其中的数据)
- 在 arch 下载页面 下载 arch 的可引导 ISO 文件。
- 下载并安装 rufus ,按照提示将 arch 的可引导 IOS 文件刻录到 USB 安装媒介。
配置 live 环境
在计算机加电自检时快速按下某个热键,进入引导加载程序菜单,选择 Arch Linux install medium 进入安装环境,安装环境默认的 Shell 是 Zsh。
第一步是连接互联网,可以直接使用有线网络,连接网线之后会自动联网,也可以使用 iwctl 认证无线网络。:
进入 iwctl 的交互式提示符:
1
iwctl
连接网络:
1
2
3
4
5
6
7device list # 列出所有 WiFi 设备
device <name> set-property Powered on # 如果设备 <name> 或相应的适配器 <adapter> 已关闭,将其打开
device <adapter> set property Powered on
station <name> scan # scan networks
station <name> get-networks # list all available networks
station <name> connect <SSID> # connect to a network (Use the SSID of the network listed above)
exit # exit the interactive prompt of iwctl检查网络连接:
1
ping www.baidu.com
创建硬盘分区:
查看硬盘分区:
1
lsblk
修改分区表:
1
cfdisk /dev/<disk_name>
格式化分区:
1
2
3mkfs.ext4 /dev/root_partition
mkfs.fat -F 32 /dev/efi_system_partition # If you created a new EFI partition
mkswap /dev/swap_partitoin # If you created a partition for swap
挂载硬盘分区
1
2
3
4mount /dev/root_partition /mnt
mount --mkdir /dev/efi_partition /mnt/boot
swapon /dev/swap_partition # If you created a partition for swap
lsblk # Check if the partitions are mounted
安装基本系统
在配置好了 live 环境之后就可以进行基本系统的安装了:
选择镜像源。(在这一步创建的镜像源列表会直接传入新系统中)
此处可以直接使用 reflector 自动选择,也可以手动编辑镜像源列表。使用 reflector:
首先编辑 /etc/xdg/reflector/reflector.conf 文件,加入下面这一行:text 1
--country China
1
2systemctl start reflector.service # Start the reflector.service
cat /etc/pacman.d/mirrorlist # Check the mirrorlist.手动添加:
访问官方镜像源列表,并将其中最快的镜像源写入文件 /etc/pacman.d/mirrorlist
安装基本系统以及必需软件包:
1
pacstrap -K /mnt base linux linux-firmware vim networkmanager sudo
配置新系统
安装好基本系统之后便可以进行一些基本的配置:
创建文件系统表 Fstab:
1
genfstab -U /mnt >> /mnt/etc/fstab
Chroot into 新系统:
1
arch-chroot /mnt
设置时区和地区:
首先编辑文件 /etc/locale.gen,取消对以下两行的注释text 1
2en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-81
2
3
4
5locale-gen # Generate the locales.
echo LANG=en_US.UTF-8 > /etc/locale.conf # Set the LANG variable accordingly.
timedatectl set-timezone Asia/Shanghai # Set the timezone.
timedatectl set-ntp true # Enable the NTP(Network Time Protocal)
timedatectl # Check the time.设置主机名:
1
echo <yourhostname> > /etc/hostname
设置 root 密码:
1
passwd
安装 grub:
1
2
3pacman -S grub efibootmgr os-prober
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=<Grub_entry_name>
grub-mkconfig -o /boot/grub/grub.cfg # Generate the main configure file.如果想要添加其它系统的引导项,进行下面的配置:
编辑文件 /etc/default/grub,取消下面这一行的注释:text 1
GRUB_DISABLE_OS_PROBER=false
然后再次生成 grub 主配置文件:
1
grub-mkconfig -o /boot/grub/grub.cfg
重启系统,拔掉U盘,进入 UEFI 启动引导项菜单,选择进入新安装的 arch 系统