From b527b1b2eea9a9ed11a11dcb8c50fb0a28d36120 Mon Sep 17 00:00:00 2001 From: Magnus Sandin Date: Mon, 30 Jan 2023 14:32:53 +0100 Subject: setup-disk: Add support for booting zfs (in grub) --- setup-disk.in | 19 +++++++++++++++++++ tests/bin/zpool | 18 ++++++++++++++++++ tests/setup_disk_test | 25 ++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) mode change 100644 => 100755 setup-disk.in create mode 100755 tests/bin/zpool diff --git a/setup-disk.in b/setup-disk.in old mode 100644 new mode 100755 index 9258df2..20be60c --- a/setup-disk.in +++ b/setup-disk.in @@ -238,6 +238,9 @@ find_mount_dev() { supported_boot_fs() { local supported="ext2 ext3 ext4 btrfs xfs vfat" + if [ "$BOOTLOADER" = "grub" ]; then + local supported="$supported zfs" + fi local fs= if is_rpi; then supported=vfat @@ -352,6 +355,10 @@ setup_grub() { GRUB_DISABLE_RECOVERY=true GRUB_CMDLINE_LINUX_DEFAULT="modules=$modules $kernel_opts" EOF + + case "$initfs_features" in + *zfs*) echo "GRUB_FS=zfs" >> "$mnt"/etc/default/grub;; + esac } # setup syslinux bootloader @@ -544,6 +551,18 @@ install_mounted_root() { echo "Continuing at your own risk." fi + # if root fileystem is zfs, check if we need to load + # nvme feature when creating initramfs + if [ "$root_fs" = "zfs" ]; then + for dev in $(zpool list -v ${rootdev%%/*} | sed '/^\S.*/d;s/^\s*\(\S*\)\s.*/\1/g'); do + case $dev in + nvme*) + initfs_features="${initfs_features% nvme} nvme" + ;; + esac + done + fi + # check if our root is on raid so we can feed mkinitfs and # bootloader conf with the proper kernel module params for dev in $rootdev $pvs $cryptdev; do diff --git a/tests/bin/zpool b/tests/bin/zpool new file mode 100755 index 0000000..be65e56 --- /dev/null +++ b/tests/bin/zpool @@ -0,0 +1,18 @@ +#!/bin/sh + + +case "$1" in + list) + cat << EOF +NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT +bpool 2.75G 54.4M 2.70G - - 0% 1% 1.00x ONLINE - + nvme0n1p2 3G 54.4M 2.70G - - 0% 1.93% - ONLINE +rpool 3.62T 419M 3.62T - - 0% 0% 1.00x ONLINE - + nvme0n1p3 3.64T 419M 3.62T - - 0% 0.01% - ONLINE +EOF + ;; + *) + echo "usage: zpool command args ..." >&2 + ;; +esac + diff --git a/tests/setup_disk_test b/tests/setup_disk_test index 7418c89..028d28e 100755 --- a/tests/setup_disk_test +++ b/tests/setup_disk_test @@ -13,7 +13,8 @@ init_tests \ setup_disk_non_existing_block_dev \ setup_disk_install_mounted_root_nvme \ setup_disk_install_mounted_root_efi_boot \ - setup_disk_install_mounted_root_bootloader_none + setup_disk_install_mounted_root_bootloader_none \ + setup_disk_install_mounted_root_zfs setup_disk_usage_body() { test_usage setup-disk @@ -302,3 +303,25 @@ setup_disk_install_mounted_root_bootloader_none_body() { atf_fail "etc/default/grub should not exist" fi } + +setup_disk_install_mounted_root_zfs_body() { + init_env + mkdir -p target/boot \ + sys/firmware/efi + + fake_mount "rpool/root-a $PWD/target zfs rw,noatime,data=ordered 0 0" + + atf_check -s exit:0 \ + -o match:"grub" \ + -e not-match:"zfs is not supported" \ + setup-disk -v target + atf_check \ + -o match:"GRUB_CMDLINE_LINUX_DEFAULT=.*zfs" \ + -o match:"GRUB_FS=zfs" \ + cat target/etc/default/grub + atf_check \ + -o match:'features=.*nvme' \ + -o match:'features=.*zfs' \ + cat target/etc/mkinitfs/mkinitfs.conf +} + -- cgit v1.2.3