共计 4281 个字符,预计需要花费 11 分钟才能阅读完成。
准备分区
我的磁盘分区是这样的
- /dev/nvme0n1p1 EFI 分区
- /dev/nvme0n1p3 btrfs 分区,用来安装新的系统
EFI 分区已经有数据,不再格式化。
格式化
mkfs.btrfs -m single -L btrfs-arch /dev/nvme0n1p3
挂载
mount -o compress=lzo /dev/nvme0n1p3 /mnt
创建 subvolume
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@logs
btrfs subvolume create /mnt/@tmp
btrfs subvolume create /mnt/@docker
btrfs subvolume create /mnt/@pkgs
btrfs subvolume create /mnt/@snapshots
btrfs subvolume create /mnt/@build
subvolume @ 用来做新系统的根 (/)
layout
ID 256 gen 405 parent 5 top level 5 path @
ID 257 gen 409 parent 5 top level 5 path @home
ID 258 gen 409 parent 5 top level 5 path @logs
ID 259 gen 404 parent 5 top level 5 path @tmp
ID 260 gen 257 parent 5 top level 5 path @docker
ID 261 gen 310 parent 5 top level 5 path @pkgs
ID 262 gen 288 parent 5 top level 5 path @snapshots
ID 263 gen 20 parent 5 top level 5 path @build
挂载 subvolume
umount /mnt
mount -o noatime,nodiratime,compress=lzo,subvol=@ /dev/nvme0n1p3 /mnt
mkdir -p /mnt/{btrfs-root,boot/efi,home,var/{log,lib/{docker,build},cache/pacman},tmp,.snapshots}
mount -o noatime,nodiratime,compress=lzo,subvol=@home /dev/nvme0n1p3 /mnt/home
mount -o noatime,nodiratime,compress=lzo,subvol=@logs /dev/nvme0n1p3 /mnt/var/log
mount -o noatime,nodiratime,compress=lzo,subvol=@tmp /dev/nvme0n1p3 /mnt/tmp
mount -o noatime,nodiratime,compress=lzo,subvol=@docker /dev/nvme0n1p3 /mnt/var/lib/docker
mount -o noatime,nodiratime,compress=lzo,subvol=@pkgs /dev/nvme0n1p3 /mnt/var/cache/pacman
mount -o noatime,nodiratime,compress=lzo,subvol=@snapshots /dev/nvme0n1p3 /mnt/.snapshots
mount -o noatime,nodiratime,compress=lzo,subvol=@build /dev/nvme0n1p3 /mnt/var/lib/build
mount -o noatime,nodiratime,compress=lzo,subvol=/ /dev/nvme0n1p3 /mnt/btrfs-root
此时不要忘记将 efi 分区挂载上
mount /dev/nvme0n1p1 /mnt/boot/efi
安装 base system
首先修改 /etc/pacman.d/mirrorlist 将 TUNA 源放到最前面
pacstrap -i /mnt base base-devel vim snapper
配置基本项
genfstab -U /mnt >> /mnt/etc/fstab
arch-chroot /mnt
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime #替换 Region/City 为你所在区域
hwclock --systohc
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
pacman -S networkmanager
systemctl enable NetworkManager.service
hostnamectl set-hostname YOUR-HOSTNAME
配置 initramfs 参数
vim /etc/mkinitcpio.conf
添加 btrfs 到 MODULES=(...) 行
找到 HOOKS=(...) 行,更换 fsck 为 btrfs
最终你看到的 /etc/mkinitcpio.conf 文件格式为
...
MODULES=(btrfs)
HOOKS=(base udev autodetect modconf block filesystems keyboard btrfs)
...
生成 initramfs
mkinitcpio -p linux
用户,密码,引导项,DM, WM
passwd root
useradd -m -u UID -G wheel -s /bin/bash USERNAME
passwd USERNAME
pacman -S grub os-prober efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch --recheck
grub-mkconfig -o /boot/grub/grub.cfg
pacman -S i3-wm i3status i3blocks i3lock rxvt-unicode dmenu py3status sddm
systemctl enable sddm.service
pacman -S wpa_supplicant dialog
重启
exit #退出 chroot
umount /mnt/boot/efi
umount /mnt/home
umount /mnt
reboot
application
自己配置,我一般根据备份的软件列表安装
AUR, archlinuxcn
vim /etc/pacman.conf
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
snapshot
btrfs 有 snapshot 功能,snapper 可以自动帮你自动做 snapshot
pacman -S snapper
snapper -c root create-config /
snapper -c home create-config /home
# 根据自己的 subvolume 实际情况创建 snapshot 策略
snapper list-configs
systemctl enable --now snapper-timeline.timer
systemctl enable --now snapper-cleanup.timer
如果你要删除 subvolume
进入 live 环境
mount /dev/nvme0n1p4 /mnt
cd /mnt
ls
btrfs subvolume delete @home
# 删除 subvolume 之后记得修改对应的 /etc/fstab
最终 mount 效果
/dev/nvme0n1p3 on / type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=256,subvol=/@) [btrfs-arch]
/dev/nvme0n1p3 on /tmp type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=259,subvol=/@tmp) [btrfs-arch]
/dev/nvme0n1p3 on /var/lib/build type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=263,subvol=/@build) [btrfs-arch]
/dev/nvme0n1p3 on /var/lib/docker type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=260,subvol=/@docker) [btrfs-arch]
/dev/nvme0n1p3 on /home type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=257,subvol=/@home) [btrfs-arch]
/dev/nvme0n1p3 on /.snapshots type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=262,subvol=/@snapshots) [btrfs-arch]
/dev/nvme0n1p3 on /var/log type btrfs (rw,noatime,compress=lzo,ssd,space_cache,subvolid=258,subvol=/@logs) [btrfs-arch]
/dev/nvme0n1p3 on /var/cache/pacman type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=261,subvol=/@pkgs) [btrfs-arch]
/dev/nvme0n1p3 on /btrfs-root type btrfs (rw,noatime,nodiratime,compress=lzo,ssd,space_cache,subvolid=5,subvol=/) [btrfs-arch]
正文完