[partition] zfs changes from review feedback

This commit is contained in:
dalto 2021-11-15 17:59:33 -06:00
parent 3ebe695a23
commit 3a90382699

View File

@ -108,16 +108,34 @@ def get_zfs_root():
# Find the root dataset # Find the root dataset
for dataset in zfs: for dataset in zfs:
try: try:
if dataset['mountpoint'] == '/': if dataset["mountpoint"] == "/":
return dataset["zpool"] + "/" + dataset["dsname"] return dataset["zpool"] + "/" + dataset["dsname"]
except KeyError: except KeyError:
# This should be impossible # This should be impossible
libcalamares.utils.error("Internal error handling zfs dataset") libcalamares.utils.warning("Internal error handling zfs dataset")
raise raise
return None return None
def is_btrfs_root(partition):
""" Returns True if the partition object refers to a btrfs root filesystem
:param partition: A partition map from global storage
:return: True if btrfs and root, False otherwise
"""
return partition["mountPoint"] == "/" and partition["fs"] == "btrfs"
def is_zfs_root(partition):
""" Returns True if the partition object refers to a zfs root filesystem
:param partition: A partition map from global storage
:return: True if zfs and root, False otherwise
"""
return partition["mountPoint"] == "/" and partition["fs"] == "zfs"
def create_systemd_boot_conf(install_path, efi_dir, uuid, entry, entry_name, kernel_type): def create_systemd_boot_conf(install_path, efi_dir, uuid, entry, entry_name, kernel_type):
""" """
Creates systemd-boot configuration files based on given parameters. Creates systemd-boot configuration files based on given parameters.
@ -162,17 +180,18 @@ def create_systemd_boot_conf(install_path, efi_dir, uuid, entry, entry_name, ker
for partition in partitions: for partition in partitions:
# systemd-boot with a BTRFS root filesystem needs to be told # systemd-boot with a BTRFS root filesystem needs to be told
# about the root subvolume. # about the root subvolume.
if partition["mountPoint"] == "/" and partition["fs"] == "btrfs": if is_btrfs_root(partition):
kernel_params.append("rootflags=subvol=@") kernel_params.append("rootflags=subvol=@")
# zfs needs to be told the location of the root dataset # zfs needs to be told the location of the root dataset
if partition["mountPoint"] == "/" and partition["fs"] == "zfs": if is_zfs_root(partition):
zfs_root = get_zfs_root zfs_root_path = get_zfs_root()
if zfs_root is not None: if zfs_root_path is not None:
kernel_params.append("root=ZFS=" + zfs_root) kernel_params.append("root=ZFS=" + zfs_root_path)
else: else:
# Something is really broken if we get to this point # Something is really broken if we get to this point
libcalamares.utils.error("Internal error handling zfs dataset") libcalamares.utils.warning("Internal error handling zfs dataset")
raise Exception("Internal zfs data missing, please contact your distribution")
if cryptdevice_params: if cryptdevice_params:
kernel_params.extend(cryptdevice_params) kernel_params.extend(cryptdevice_params)
@ -363,14 +382,8 @@ def run_grub_mkconfig(output_file):
libcalamares.utils.error("Failed to run grub-mkconfig, no partitions defined in global storage") libcalamares.utils.error("Failed to run grub-mkconfig, no partitions defined in global storage")
return return
# check for zfs
is_zfs = False
for partition in partitions:
if partition["mountPoint"] == "/" and partition["fs"] == "zfs":
is_zfs = True
# zfs needs an environment variable set for grub-mkconfig # zfs needs an environment variable set for grub-mkconfig
if is_zfs: if any([is_zfs_root(partition) for partition in partitions]):
check_target_env_call(["sh", "-c", "echo ZPOOL_VDEV_NAME_PATH=1 >> /etc/environment"]) check_target_env_call(["sh", "-c", "echo ZPOOL_VDEV_NAME_PATH=1 >> /etc/environment"])
check_target_env_call(["sh", "-c", "ZPOOL_VDEV_NAME_PATH=1 " + check_target_env_call(["sh", "-c", "ZPOOL_VDEV_NAME_PATH=1 " +
libcalamares.job.configuration["grubMkconfig"] + " -o " + output_file]) libcalamares.job.configuration["grubMkconfig"] + " -o " + output_file])