Skip to content

Commit a69befb

Browse files
Maurice Zhougmelikov
authored andcommitted
Update Alpine, Arch, Fedora and RHEL root on ZFS guides
Signed-off-by: Maurice Zhou <[email protected]>
1 parent a0c149a commit a69befb

File tree

16 files changed

+631
-394
lines changed

16 files changed

+631
-394
lines changed

docs/Getting Started/Alpine Linux/Root on ZFS/1-preparation.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ Preparation
66
.. contents:: Table of Contents
77
:local:
88

9-
#. Disable Secure Boot. ZFS modules can not be loaded if Secure Boot is enabled.
10-
#. Download latest extended variant of `Alpine Linux live image
11-
<https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/>`__ and boot from it.
9+
#. Disable Secure Boot. ZFS modules can not be loaded if
10+
Secure Boot is enabled.
11+
#. Download latest extended variant of `Alpine Linux
12+
live image
13+
<https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/>`__
14+
and boot from it.
1215
#. Login as root user. There is no password.
1316
#. Configure Internet::
1417

@@ -44,25 +47,25 @@ Preparation
4447
and add it to package manager configuration::
4548

4649
tee -a /etc/apk/repositories <<EOF
47-
https://dl-5.alpinelinux.org/alpine/latest-stable/community/
48-
https://dl-5.alpinelinux.org/alpine/latest-stable/main/
50+
https://dl-cdn.alpinelinux.org/alpine/latest-stable/community/
51+
https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/
4952
EOF
5053

5154
#. Throughout this guide, we use predictable disk names generated by udev::
5255

5356
apk update
5457
apk add eudev
55-
setup-udev
58+
setup-devd udev
5659

5760
It can be removed after reboot with ``setup-devd mdev && apk del eudev``.
5861

5962
#. Target disk
6063

6164
List available disks with::
6265

63-
ls /dev/disk/by-id/*
66+
find /dev/disk/by-id/
6467

65-
If using virtio as disk bus, use ``/dev/disk/by-path/*``.
68+
If using virtio as disk bus, use ``/dev/disk/by-path/``.
6669

6770
Declare disk array::
6871

@@ -72,12 +75,24 @@ Preparation
7275

7376
DISK='/dev/disk/by-id/disk1'
7477

78+
#. Set partition size:
79+
80+
Set swap size, set to 1 if you don't want swap to
81+
take up too much space::
82+
83+
INST_PARTSIZE_SWAP=4
84+
85+
Root pool size, use all remaining disk space if not set::
86+
87+
INST_PARTSIZE_RPOOL=
88+
7589
#. Install ZFS support and partition tool::
7690

77-
apk add zfs zfs-lts sgdisk e2fsprogs
91+
apk add zfs zfs-lts sgdisk e2fsprogs cryptsetup util-linux
7892
modprobe zfs
7993

80-
Many errors about firmware will appear. They are safe to ignore.
94+
Many errors about firmware will appear. They are
95+
safe to be ignored.
8196

8297
#. Install bootloader for both legacy boot and UEFI::
8398

docs/Getting Started/Alpine Linux/Root on ZFS/2-system-installation.rst

Lines changed: 94 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ System Installation
1010

1111
for i in ${DISK}; do
1212

13+
# wipe flash-based storage device to improve
14+
# performance.
15+
# ALL DATA WILL BE LOST
16+
# blkdiscard -f $i
17+
1318
sgdisk --zap-all $i
1419

1520
sgdisk -n1:1M:+1G -t1:EF00 $i
1621

1722
sgdisk -n2:0:+4G -t2:BE00 $i
1823

19-
test -z $INST_PARTSIZE_SWAP || sgdisk -n4:0:+${INST_PARTSIZE_SWAP}G -t4:8200 $i
24+
sgdisk -n4:0:+${INST_PARTSIZE_SWAP}G -t4:8200 $i
2025

2126
if test -z $INST_PARTSIZE_RPOOL; then
2227
sgdisk -n3:0:0 -t3:BF00 $i
@@ -25,17 +30,15 @@ System Installation
2530
fi
2631

2732
sgdisk -a1 -n5:24K:+1000K -t5:EF02 $i
28-
done
2933

30-
#. Probe new partitions::
34+
sync && udevadm settle && sleep 3
3135

32-
for i in ${DISK}; do
33-
partprobe $i
34-
done
35-
udevadm settle
36-
sync
36+
cryptsetup open --type plain --key-file /dev/random $i-part4 ${i##*/}-part4
37+
mkswap /dev/mapper/${i##*/}-part4
38+
swapon /dev/mapper/${i##*/}-part4
39+
done
3740

38-
#. Create boot partition::
41+
#. Create boot pool::
3942

4043
tee -a /root/grub2 <<EOF
4144
# Features which are supported by GRUB2
@@ -52,27 +55,39 @@ System Installation
5255
spacemap_histogram
5356
EOF
5457

55-
zpool create \
56-
-o compatibility=/root/grub2 \
57-
-o ashift=12 \
58-
-o autotrim=on \
59-
-O acltype=posixacl \
60-
-O canmount=off \
61-
-O compression=lz4 \
62-
-O devices=off \
63-
-O normalization=formD \
64-
-O relatime=on \
65-
-O xattr=sa \
66-
-O mountpoint=/boot \
67-
-R /mnt \
68-
bpool \
69-
mirror \
70-
$(for i in ${DISK}; do
71-
printf "$i-part2 ";
72-
done)
73-
58+
zpool create \
59+
-o compatibility=/root/grub2 \
60+
-o ashift=12 \
61+
-o autotrim=on \
62+
-O acltype=posixacl \
63+
-O canmount=off \
64+
-O compression=lz4 \
65+
-O devices=off \
66+
-O normalization=formD \
67+
-O relatime=on \
68+
-O xattr=sa \
69+
-O mountpoint=/boot \
70+
-R /mnt \
71+
bpool \
72+
mirror \
73+
$(for i in ${DISK}; do
74+
printf "$i-part2 ";
75+
done)
76+
7477
If not using a multi-disk setup, remove ``mirror``.
7578

79+
You should not need to customize any of the options for the boot pool.
80+
81+
GRUB does not support all of the zpool features. See ``spa_feature_names``
82+
in `grub-core/fs/zfs/zfs.c
83+
<http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/fs/zfs/zfs.c#n276>`__.
84+
This step creates a separate boot pool for ``/boot`` with the features
85+
limited to only those that GRUB supports, allowing the root pool to use
86+
any/all features.
87+
88+
Features enabled with ``-o compatibility=grub2`` can be seen
89+
`here <https://github.com/openzfs/zfs/blob/master/cmd/zpool/compatibility.d/grub2>`__.
90+
7691
#. Create root pool::
7792

7893
zpool create \
@@ -95,36 +110,59 @@ System Installation
95110

96111
If not using a multi-disk setup, remove ``mirror``.
97112

98-
#. This section implements dataset layout as described in `overview <1-preparation.html>`__.
99-
100-
Create root system container:
113+
#. Create root system container:
101114

102115
- Unencrypted::
103116

104117
zfs create \
105118
-o canmount=off \
106119
-o mountpoint=none \
107-
rpool/alpine
120+
rpool/alpinelinux
121+
122+
- Encrypted:
108123

109-
- Encrypted::
124+
Pick a strong password. Once compromised, changing password will not keep your
125+
data safe. See ``zfs-change-key(8)`` for more info::
110126

111127
zfs create \
112128
-o canmount=off \
113129
-o mountpoint=none \
114130
-o encryption=on \
115131
-o keylocation=prompt \
116132
-o keyformat=passphrase \
117-
rpool/alpine
118-
119-
#. Create datasets::
120-
121-
zfs create -o canmount=on -o mountpoint=/ rpool/alpine/root
122-
zfs create -o canmount=on -o mountpoint=/home rpool/alpine/home
123-
zfs create -o canmount=off -o mountpoint=/var rpool/alpine/var
124-
zfs create -o canmount=on rpool/alpine/var/lib
125-
zfs create -o canmount=on rpool/alpine/var/log
126-
zfs create -o canmount=off -o mountpoint=none bpool/alpine
127-
zfs create -o canmount=on -o mountpoint=/boot bpool/alpine/root
133+
rpool/alpinelinux
134+
135+
You can automate this step (insecure) with: ``echo POOLPASS | zfs create ...``.
136+
137+
Create system datasets, let Alpinelinux declaratively
138+
manage mountpoints with ``mountpoint=legacy``::
139+
140+
zfs create -o mountpoint=legacy rpool/alpinelinux/root
141+
mount -t zfs rpool/alpinelinux/root /mnt/
142+
zfs create -o mountpoint=legacy rpool/alpinelinux/home
143+
mkdir /mnt/home
144+
mount -t zfs rpool/alpinelinux/home /mnt/home
145+
mkdir -p /mnt/var/lib
146+
mkdir -p /mnt/var/log
147+
zfs create -o mountpoint=legacy rpool/alpinelinux/var
148+
zfs create -o mountpoint=legacy rpool/alpinelinux/var/lib
149+
zfs create -o mountpoint=legacy rpool/alpinelinux/var/log
150+
zfs create -o mountpoint=none bpool/alpinelinux
151+
zfs create -o mountpoint=legacy bpool/alpinelinux/root
152+
mkdir /mnt/boot
153+
mount -t zfs bpool/alpinelinux/root /mnt/boot
154+
155+
#. mkinitfs requires root dataset to have a mountpoint
156+
other than legacy::
157+
158+
umount -Rl /mnt
159+
zfs set canmount=noauto rpool/alpinelinux/root
160+
zfs set mountpoint=/ rpool/alpinelinux/root
161+
mount -t zfs -o zfsutil rpool/alpinelinux/root /mnt
162+
mount -t zfs rpool/alpinelinux/home /mnt/home
163+
mount -t zfs bpool/alpinelinux/root /mnt/boot
164+
mount -t zfs rpool/alpinelinux/var/lib /mnt/var/lib
165+
mount -t zfs rpool/alpinelinux/var/log /mnt/var/log
128166

129167
#. Format and mount ESP::
130168

@@ -152,6 +190,10 @@ System Installation
152190

153191
GRUB installation will fail and will be reinstalled later.
154192

193+
#. Allow EFI system partition to fail at boot::
194+
195+
sed -i "s|vfat.*rw|vfat rw,nofail|" /mnt/etc/fstab
196+
155197
#. Chroot::
156198

157199
m='/dev /proc /sys'
@@ -161,36 +203,12 @@ System Installation
161203

162204
#. Rebuild initrd::
163205

164-
mkdir -p /etc/zfs
165-
rm -f /etc/zfs/zpool.cache
166-
touch /etc/zfs/zpool.cache
167-
chmod a-w /etc/zfs/zpool.cache
168-
chattr +i /etc/zfs/zpool.cache
169-
170206
sed -i 's|zfs|nvme zfs|' /etc/mkinitfs/mkinitfs.conf
171207
for directory in /lib/modules/*; do
172208
kernel_version=$(basename $directory)
173209
mkinitfs $kernel_version
174210
done
175211

176-
#. Enable dataset mounting at boot::
177-
178-
rc-update add zfs-mount sysinit
179-
180-
#. Replace predictable disk path with traditional disk path:
181-
182-
For SATA drives::
183-
184-
sed -i 's|/dev/disk/by-id/ata-.*-part|/dev/sda|' /etc/fstab
185-
186-
For NVMe drives::
187-
188-
sed -i 's|/dev/disk/by-id/nvme-.*-part|/dev/nvme0n1p|' /etc/fstab
189-
190-
#. Mount datasets with zfsutil option::
191-
192-
sed -i 's|,posixacl|,zfsutil,posixacl|' /etc/fstab
193-
194212
#. Apply GRUB workaround::
195213

196214
echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
@@ -210,7 +228,6 @@ System Installation
210228

211229
#. Install GRUB::
212230

213-
export ZPOOL_VDEV_NAME_PATH=YES
214231
mkdir -p /boot/efi/alpine/grub-bootdir/i386-pc/
215232
mkdir -p /boot/efi/alpine/grub-bootdir/x86_64-efi/
216233
for i in ${DISK}; do
@@ -243,15 +260,15 @@ System Installation
243260

244261
#. Reboot::
245262

246-
poweroff
263+
reboot
247264

248-
Disconnect the live media and other non-boot storage devices.
249-
Due to missing support of predictable device names in initrd,
250-
Alpine Linux will mount whichever disk appears to be /dev/sda or /dev/nvme0
251-
at /boot/efi at boot.
265+
Post installaion
266+
~~~~~~~~~~~~~~~~
252267

253-
Root filesystem at / and /boot are ZFS and imported via pool name thus not affected by the above restriction.
268+
#. Setup graphical desktop::
254269

255-
#. Post-install:
270+
setup-desktop
256271

257-
#. Setup swap.
272+
#. You can create a snapshot of the newly installed
273+
system for later rollback,
274+
see `this page <https://openzfs.github.io/openzfs-docs/Getting%20Started/Arch%20Linux/Root%20on%20ZFS/6-create-boot-environment.html>`__.

docs/Getting Started/Arch Linux/Root on ZFS/1-preparation.rst

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Preparation
2626

2727
List available disks with::
2828

29-
ls /dev/disk/by-id/*
29+
find /dev/disk/by-id/
3030

31-
If using virtio as disk bus, use ``/dev/disk/by-path/*``.
31+
If using virtio as disk bus, use ``/dev/disk/by-path/``.
3232

3333
Declare disk array::
3434

@@ -40,11 +40,10 @@ Preparation
4040

4141
#. Set partition size:
4242

43-
Set swap size. It's `recommended <https://chrisdown.name/2018/01/02/in-defence-of-swap.html>`__
44-
to setup a swap partition. If you intend to use hibernation,
45-
the minimum should be no less than RAM size. Skip if swap is not needed::
43+
Set swap size, set to 1 if you don't want swap to
44+
take up too much space::
4645

47-
INST_PARTSIZE_SWAP=8
46+
INST_PARTSIZE_SWAP=4
4847

4948
Root pool size, use all remaining disk space if not set::
5049

@@ -54,7 +53,7 @@ Preparation
5453

5554
curl -L https://archzfs.com/archzfs.gpg | pacman-key -a -
5655
pacman-key --lsign-key $(curl -L https://git.io/JsfVS)
57-
curl -L https://git.io/Jsfw2 > /etc/pacman.d/mirrorlist-archzfs
56+
curl -L https://raw.githubusercontent.com/openzfs/openzfs-docs/master/docs/Getting%20Started/Arch%20Linux/archzfs-repo/mirrorlist-archzfs > /etc/pacman.d/mirrorlist-archzfs
5857

5958
tee -a /etc/pacman.conf <<- 'EOF'
6059

@@ -77,12 +76,26 @@ Preparation
7776
* https://archzfs.com/archive_archzfs/
7877
* https://archzfs.com/archzfs/x86_64/
7978

79+
::
80+
curl -L https://archzfs.com/archive_archzfs/ \
81+
| grep zfs-linux-[0-9] \
82+
| grep -v src.tar \
83+
| grep "5.18.7"
84+
# ...<a href="zfs-linux-2.1.5_5.18.7.arch1.1-1-x86_64.pkg.tar.zst">...
85+
8086
Result: https/.../archive_archzfs/zfs-linux-2.1.5_5.18.7.arch1.1-1-x86_64.pkg.tar.zst
8187

8288
#. Find compatible zfs-utils package:
8389

8490
Search ZFS version string (e.g. 2.1.5) in both pages above.
8591

92+
::
93+
curl -L https://archzfs.com/archzfs/x86_64/ \
94+
| grep zfs-utils-2.1.5 \
95+
| grep -v src.tar
96+
# ...<a href="zfs-utils-2.1.5-1-x86_64.pkg.tar.zst">...
97+
98+
8699
Result: https/.../archzfs/x86_64/zfs-utils-2.1.5-2-x86_64.pkg.tar.zst
87100

88101
#. Download both then install::

0 commit comments

Comments
 (0)