Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions docs/Getting Started/Alpine Linux/Root on ZFS/1-preparation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,21 @@ Preparation

ssh root@192.168.1.19

#. Configure NTP client for time synchronization::

setup-ntp chrony

#. Pick a mirror from `Alpine Mirrors <https://mirrors.alpinelinux.org/>`__
and add it to package manager configuration::

tee -a /etc/apk/repositories <<EOF
https://dl-5.alpinelinux.org/alpine/latest-stable/community/
https://dl-5.alpinelinux.org/alpine/latest-stable/main/
EOF

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

apk update
apk add eudev
setup-udev

Expand All @@ -59,21 +72,8 @@ Preparation

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

#. Configure NTP client for time synchronization::

setup-ntp chrony

#. Pick a mirror from `Alpine Mirrors <https://mirrors.alpinelinux.org/>`__
and add it to package manager configuration::

tee -a /etc/apk/repositories <<EOF
https://dl-5.alpinelinux.org/alpine/latest-stable/community/
https://dl-5.alpinelinux.org/alpine/latest-stable/main/
EOF

#. Install ZFS support and partition tool::

apk update
apk add zfs zfs-lts sgdisk e2fsprogs
modprobe zfs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,41 @@ System Installation

#. Create boot partition::

for i in ${DISK}; do
mkfs.ext4 -F $i-part2
done
tee -a /root/grub2 <<EOF
# Features which are supported by GRUB2
async_destroy
bookmarks
embedded_data
empty_bpobj
enabled_txg
extensible_dataset
filesystem_limits
hole_birth
large_blocks
lz4_compress
spacemap_histogram
EOF

zpool create \
-o compatibility=/root/grub2 \
-o ashift=12 \
-o autotrim=on \
-O acltype=posixacl \
-O canmount=off \
-O compression=lz4 \
-O devices=off \
-O normalization=formD \
-O relatime=on \
-O xattr=sa \
-O mountpoint=/boot \
-R /mnt \
bpool \
mirror \
$(for i in ${DISK}; do
printf "$i-part2 ";
done)

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

#. Create root pool::

Expand Down Expand Up @@ -91,14 +123,17 @@ System Installation
zfs create -o canmount=off -o mountpoint=/var rpool/alpine/var
zfs create -o canmount=on rpool/alpine/var/lib
zfs create -o canmount=on rpool/alpine/var/log

#. Mount /boot::

mkdir -p /mnt/boot
mount -t ext4 $(echo $DISK | cut -f1 -d\ )-part2 /mnt/boot/
zfs create -o canmount=off -o mountpoint=none bpool/alpine
zfs create -o canmount=on -o mountpoint=/boot bpool/alpine/root

#. Format and mount ESP::

for i in ${DISK}; do
mkfs.vfat -n EFI ${i}-part1
mkdir -p /mnt/boot/efis/${i##*/}-part1
mount -t vfat ${i}-part1 /mnt/boot/efis/${i##*/}-part1
done

mkdir -p /mnt/boot/efi
mount -t vfat $(echo $DISK | cut -f1 -d\ )-part1 /mnt/boot/efi

Expand All @@ -124,22 +159,6 @@ System Installation

chroot /mnt /usr/bin/env DISK=$DISK sh

#. Apply GRUB workaround::

echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
source /etc/profile.d/zpool_vdev_name_path.sh

sed -i "s|rpool=.*|rpool=rpool|" /etc/grub.d/10_linux

sed -i 's|stat -f -c %T /|echo zfs|' /usr/sbin/grub-mkconfig

This workaround needs to be applied for every GRUB update, as the
update will overwrite the changes.

#. Generate GRUB menu::

grub-mkconfig -o /boot/grub/grub.cfg

#. Rebuild initrd::

mkdir -p /etc/zfs
Expand Down Expand Up @@ -171,15 +190,51 @@ System Installation
#. Mount datasets with zfsutil option::

sed -i 's|,posixacl|,zfsutil,posixacl|' /etc/fstab


#. Apply GRUB workaround::

echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
source /etc/profile.d/zpool_vdev_name_path.sh

# GRUB fails to detect rpool name, hard code as "rpool"
sed -i "s|rpool=.*|rpool=rpool|" /etc/grub.d/10_linux

# BusyBox stat does not recognize zfs, replace fs detection with ZFS
sed -i 's|stat -f -c %T /|echo zfs|' /usr/sbin/grub-mkconfig

# grub-probe fails to identify fs mounted at /boot
sed -i "s|GRUB_DEVICE_BOOT=.*|GRUB_DEVICE_BOOT=$(echo $DISK | cut -f1 -d\ )-part2|" /usr/sbin/grub-mkconfig

This workaround needs to be applied for every GRUB update, as the
update will overwrite the changes.

#. Install GRUB::

export ZPOOL_VDEV_NAME_PATH=YES
mkdir -p /boot/efi/alpine/grub-bootdir/i386-pc/
mkdir -p /boot/efi/alpine/grub-bootdir/x86_64-efi/
for i in ${DISK}; do
grub-install --target=i386-pc $i
grub-install --target=i386-pc --boot-directory \
/boot/efi/alpine/grub-bootdir/i386-pc/ $i
done
grub-install --target x86_64-efi --bootloader-id alpine --removable

grub-install --target x86_64-efi --boot-directory \
/boot/efi/alpine/grub-bootdir/x86_64-efi/ --efi-directory \
/boot/efi --bootloader-id alpine --removable

#. Generate GRUB menu::

grub-mkconfig -o /boot/efi/alpine/grub-bootdir/x86_64-efi/grub/grub.cfg
grub-mkconfig -o /boot/efi/alpine/grub-bootdir/i386-pc/grub/grub.cfg

#. For both legacy and EFI booting: mirror ESP content::

ESP_MIRROR=$(mktemp -d)
cp -r /boot/efi/EFI $ESP_MIRROR
for i in /boot/efis/*; do
cp -r $ESP_MIRROR/EFI $i
done
rm -rf $ESP_MIRROR

#. Unmount filesystems::

exit
Expand All @@ -193,11 +248,10 @@ System Installation
Disconnect the live media and other non-boot storage devices.
Due to missing support of predictable device names in initrd,
Alpine Linux will mount whichever disk appears to be /dev/sda or /dev/nvme0
at /boot and /boot/efi at boot.
at /boot/efi at boot.

Root filesystem at / is ZFS and imported via pool name thus not affected by the above restriction.
Root filesystem at / and /boot are ZFS and imported via pool name thus not affected by the above restriction.

#. Post-install:

#. Setup mirroring of /boot partition and /boot/efi via dd.
#. Setup swap.
10 changes: 5 additions & 5 deletions docs/Getting Started/Arch Linux/Root on ZFS/1-preparation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ Preparation

INST_PARTSIZE_RPOOL=

#. Check kernel version::

uname -r
#5.18.7-arch1-1

#. Add ZFS repo::

curl -L https://archzfs.com/archzfs.gpg | pacman-key -a -
Expand All @@ -70,6 +65,11 @@ Preparation
Include = /etc/pacman.d/mirrorlist-archzfs
EOF

#. Check kernel version::

uname -r
#5.18.7-arch1-1

#. Find a ZFS package compatible with the kernel:

Search kernel version string (e.g. 5.18.7) in both pages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ System Installation

Create boot dataset::

zfs create -o canmount=on -o mountpoint=/boot bpool/archlinux
zfs create -o canmount=off -o mountpoint=none bpool/archlinux
zfs create -o canmount=on -o mountpoint=/boot bpool/archlinux/root

#. Format and mount ESP::

Expand Down
75 changes: 24 additions & 51 deletions docs/Getting Started/Arch Linux/Root on ZFS/5-bootloader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,6 @@ Bootloader
.. contents:: Table of Contents
:local:

Apply workarounds
~~~~~~~~~~~~~~~~~~~~
Currently GRUB has multiple compatibility problems with ZFS,
especially with regards to newer ZFS features.
Workarounds have to be applied.

#. grub-probe fails to get canonical path

When persistent device names ``/dev/disk/by-id/*`` are used
with ZFS, GRUB will fail to resolve the path of the boot pool
device. Error::

# /usr/bin/grub-probe: error: failed to get canonical path of `/dev/virtio-pci-0000:06:00.0-part3'.

Solution::

echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
source /etc/profile.d/zpool_vdev_name_path.sh

#. Pool name missing

See `this bug report <https://savannah.gnu.org/bugs/?59614>`__.
Root pool name is missing from ``root=ZFS=rpool_$INST_UUID/ROOT/default``
kernel cmdline in generated ``grub.cfg`` file.

A workaround is to replace the pool name detection with ``zdb``
command::

sed -i "s|rpool=.*|rpool=\`zdb -l \${GRUB_DEVICE} \| grep -E '[[:blank:]]name' \| cut -d\\\' -f 2\`|" /etc/grub.d/10_linux

Caution: this fix must be applied after every GRUB update and before generating the menu.

Install GRUB
~~~~~~~~~~~~~~~~~~~~
#. Create empty cache file and generate initrd::

rm -f /etc/zfs/zpool.cache
Expand All @@ -49,33 +15,40 @@ Install GRUB

mkinitcpio -P

#. If using legacy booting, install GRUB to every disk::
#. Apply GRUB workaround::

for i in ${DISK}; do
grub-install --target=i386-pc $i
done
echo 'export ZPOOL_VDEV_NAME_PATH=YES' >> /etc/profile.d/zpool_vdev_name_path.sh
source /etc/profile.d/zpool_vdev_name_path.sh

# GRUB fails to detect rpool name, hard code as "rpool"
sed -i "s|rpool=.*|rpool=rpool|" /etc/grub.d/10_linux

echo GRUB_CMDLINE_LINUX=\"zfs_import_dir=/dev/disk/by-id/\" >> /etc/default/grub

#. If using EFI::
This workaround needs to be applied for every GRUB update, as the
update will overwrite the changes.

grub-install --target x86_64-efi
grub-install --target x86_64-efi --removable
for i in ${DISK}; do
efibootmgr -cgp 1 -l "\EFI\arch\grubx64.efi" \
-L "arch-${i##*/}" -d ${i}
done
#. Install GRUB::

#. Generate GRUB Menu:
export ZPOOL_VDEV_NAME_PATH=YES
mkdir -p /boot/efi/arch/grub-bootdir/i386-pc/
mkdir -p /boot/efi/arch/grub-bootdir/x86_64-efi/
for i in ${DISK}; do
grub-install --target=i386-pc --boot-directory \
/boot/efi/arch/grub-bootdir/i386-pc/ $i
done
grub-install --target x86_64-efi --boot-directory \
/boot/efi/arch/grub-bootdir/x86_64-efi/ --efi-directory \
/boot/efi --bootloader-id arch --removable

Generate menu::
#. Generate GRUB menu::

echo GRUB_CMDLINE_LINUX=\"zfs_import_dir=/dev/disk/by-id/\" >> /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
cp /boot/grub/grub.cfg /boot/efi/EFI/arch/
grub-mkconfig -o /boot/efi/arch/grub-bootdir/x86_64-efi/grub/grub.cfg
grub-mkconfig -o /boot/efi/arch/grub-bootdir/i386-pc/grub/grub.cfg

#. For both legacy and EFI booting: mirror ESP content::

ESP_MIRROR=$(mktemp -d)
unalias -a
cp -r /boot/efi/EFI $ESP_MIRROR
for i in /boot/efis/*; do
cp -r $ESP_MIRROR/EFI $i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ System Installation

Create boot dataset::

zfs create -o canmount=on -o mountpoint=/boot bpool/redhat
zfs create -o canmount=off -o mountpoint=none bpool/redhat
zfs create -o canmount=on -o mountpoint=/boot bpool/redhat/root

#. Format and mount ESP::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ System Configuration

fixfiles -F onboot

#. Set root password::
#. Set root password, the password set earlier does not work due to SELinux::

passwd

Expand Down
Loading