原创文章,转载请注明出处
https://qiedd.com/

参考Wiki:Install Arch Linux on ZFS

启动到ArchISO

将系统重装为 Debian 10,然后安装 grub-imageboot

# 安装 grub-imageboot
apt update -y && apt install grub-imageboot -y

# 新建文件夹用于存放ArchISO
mkdir /boot/images

# 进入文件夹
cd /boot/images

# 下载镜像
wget http://mirrors.tencentyun.com/archlinux/iso/2021.12.01/archlinux-2021.12.01-x86_64.iso

# 可选镜像
wget https://mirrors.ustc.edu.cn/archlinux/iso/2021.12.01/archlinux-2021.12.01-x86_64.iso
wget http://mirror.rackspace.com/archlinux/iso/2021.12.01/archlinux-2021.12.01-x86_64.iso

配置grub

# 更新grub
update-grub2

# 按照上面的提示,选择默认启动项,我这里是ArchISO是第三项
vim /etc/default/grub

# 从0开始,所以这里是2
GRUB_DEFAULT=2

# 更新grub
udpate-grub2

# 重启等待即可,登录到VNC
reboot

安装Arch

安装前配置

https://github.com/eoli3n/archiso-zfs

# 安装迁配置,开启ntp
timedatectl set-ntp true

# 设置密码,用于ssh连接
passwd

# 启动sshd
systemctl start sshd

# 安装ZFS模块
curl -s https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init | bash

# 查看硬盘
fdisk -l

# 对硬盘进行分区
fdisk /dev/vda
硬盘分区实例

2G作为启动分区,剩余为根分区

root@VM-20-14-debian ~ # fdisk /dev/vda

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): o
Created a new DOS disklabel with disk identifier 0x5b2e861f.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-167772159, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-167772159, default 167772159): +2G

Created a new partition 1 of type 'Linux' and of size 2 GiB.
Partition #1 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (2-4, default 2): 
First sector (4196352-167772159, default 4196352): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-167772159, default 167772159): 

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

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Disk /dev/vda: 80 GiB, 85899345920 bytes, 167772160 sectors
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: dos
Disk identifier: 0x5b2e861f

Device     Boot   Start       End   Sectors Size Id Type
/dev/vda1          2048   4196351   4194304   2G 83 Linux
/dev/vda2       4196352 167772159 163575808  78G 83 Linux
ZFS配置
# 创建zpool
zpool create -f -o ashift=12           \
             -O acltype=posixacl       \
             -O relatime=on            \
             -O xattr=sa               \
             -O dnodesize=legacy       \
             -O normalization=formD    \
             -O mountpoint=none        \
             -O canmount=off           \
             -O devices=off            \
             -O compression=lz4        \
             -R /mnt                   \
             zroot /dev/vda2                  
             
# 创建datasets
zfs create -o mountpoint=none zroot/data
zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/default
zfs create -o mountpoint=/home zroot/data/home
zfs create -o mountpoint=/www zroot/data/www

# 测试zpool是否能够导入导出
zpool export zroot
zpool import zroot -R /mnt

# 挂载zpool
zfs mount zroot/ROOT/default
zfs mount -a

# 设置启动分区
zpool set bootfs=zroot/ROOT/default zroot

# 设置zpool缓存
cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache

# 如果提示:cp: cannot create regular file '/mnt/etc/zfs/zpool.cache': No such file or directory
zpool set cachefile=/etc/zfs/zpool.cache zroot

# 查看是否有挂载上
df -h
zroot/ROOT/default   37G  128K   37G   1% /mnt

# 如果配置出错,需要重新配置
# umount -R /mnt
# zpool destroy zroot
将Arch装进硬盘中
# 格式化boot分区
mkfs.ext4 /dev/vda1

# 创建/boot
mkdir /mnt/boot

# 挂载/boot
mount /dev/vda1 /mnt/boot

# 设置镜像(腾讯云内网专用)
vim /etc/pacman.d/mirrorlist
Server = http://mirrors.tencentyun.com/archlinux/$repo/os/$arch

# 其他镜像(可选)
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
Server = https://mirrors.cloud.tencent.com/archlinux/$repo/os/$arch

# 安装系统
# AMD CPU
pacstrap /mnt base linux linux-firmware linux-headers base-devel vim os-prober amd-ucode openssh wget networkmanager zfs-dkms grub

# INTEL CPU
pacstrap /mnt base linux linux-firmware linux-headers base-devel vim os-prober intel-ucode openssh wget networkmanager zfs-dkms grub

# 设置挂载
genfstab -U /mnt >> /mnt/etc/fstab
cat /mnt/etc/fstab

# chroot进Arch
arch-chroot /mnt

# 设置时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc
date

# 安装语言支持,放在最前面即可
vim /etc/locale.gen
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
zh_TW.UTF-8 UTF-8

# 应用配置
locale-gen

# 默认语言
vim /etc/locale.conf
LANG=en_US.UTF-8

# 配置内核钩子,加入zfs支持
vim /etc/mkinitcpio.conf
HOOKS=(base udev autodetect modconf block zfs filesystems keyboard fsck)

# 加载zfs
mkinitcpio -P

# 配置grub
grub-install /dev/vda
grub-mkconfig -o /boot/grub/grub.cfg

# 设置zpool缓存
zpool set cachefile=/etc/zfs/zpool.cache zroot

# 让zfs服务在开机时自启动
systemctl enable zfs.target
systemctl enable zfs-import-cache
systemctl enable zfs-mount
systemctl enable zfs-import.target
systemctl enable sshd
systemctl enable NetworkManager

# 设置root密码
passwd

# 允许SSH root登录
vim /etc/ssh/sshd_config
*** 示例 ***
PermitRootLogin yes

# 退出chroot
exit

# 取消挂载
umount -R /mnt
zfs umount -a
zpool export zroot

# 同步并重启
sync
reboot

重启后配置

# 添加archlinuxcn源和archzfs源
vim /etc/pacman.conf 

[archlinuxcn]
Server = http://mirrors.tencentyun.com/archlinuxcn/$arch

[archzfs]
Server = http://mirror.sum7.eu/archlinux/archzfs/$repo/x86_64

# 可选镜像源
# archlinuxcn
# Server = https://mirrors.cloud.tencent.com/archlinuxcn/$arch
# Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
# Server = https://repo.archlinuxcn.org/$arch

# archzfs
# Origin Server - France
# Server = http://archzfs.com/$repo/x86_64
# Mirror - Germany
# Server = http://mirror.sum7.eu/archlinux/archzfs/$repo/x86_64
# Mirror - Germany
# Server = https://mirror.biocrafting.net/archlinux/archzfs/$repo/x86_64
# Mirror - India
# Server = https://mirror.in.themindsmaze.com/archzfs/$repo/x86_64
# Mirror - US
# Server = https://zxcvfdsa.com/archzfs/$repo/$arch

# 安装key
pacman-key -r DDF7DB817396A49B2A2723F7403BD972F75D9D76
pacman-key --lsign-key DDF7DB817396A49B2A2723F7403BD972F75D9D76
pacman -Syu archlinuxcn-keyring

# 保险起见,装个ArchISO进去防止滚炸
sudo pacman -S yay
yay -S grub-imageboot
mkdir /boot/images
cd /boot/images
wget http://mirrors.tencentyun.com/archlinux/iso/2021.12.01/archlinux-2021.12.01-x86_64.iso
grub-mkconfig -o /boot/grub/grub.cfg
分类: Linux

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据