From a50ffa74e177f515c67e92aa3720ee725773c429 Mon Sep 17 00:00:00 2001 From: dalto Date: Sun, 26 Dec 2021 16:03:48 -0600 Subject: [PATCH] [mount,fstab] Fix bugs in moving mount options to the mount module --- src/modules/fstab/main.py | 16 +++++++++++++--- src/modules/mount/main.py | 29 ++++++++++++++++++++++------- src/modules/mount/mount.conf | 4 ++-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/modules/fstab/main.py b/src/modules/fstab/main.py index 8c768b5dd..33dcd5ecc 100644 --- a/src/modules/fstab/main.py +++ b/src/modules/fstab/main.py @@ -234,7 +234,7 @@ class FstabGenerator(object): libcalamares.utils.debug("Ignoring foreign swap {!s} {!s}".format(disk_name, partition.get("uuid", None))) return None - options = self.get_mount_options(filesystem, mount_point) + options = self.get_mount_options(mount_point) if mount_point == "/" and filesystem != "btrfs": check = 1 @@ -276,8 +276,18 @@ class FstabGenerator(object): if partition["mountPoint"]: mkdir_p(self.root_mount_point + partition["mountPoint"]) - def get_mount_options(self, filesystem, mountpoint): - return next((x for x in self.mount_options_list if x["mountpoint"] == mountpoint), "defaults") + def get_mount_options(self, mountpoint): + """ + Returns the mount options for a given mountpoint + + :param mountpoint: A string containing the mountpoint for the fstab entry + :return: A string containing the mount options for the entry or "defaults" if nothing is found + """ + mount_options_item = next((x for x in self.mount_options_list if x.get("mountpoint") == mountpoint), None) + if mount_options_item: + return mount_options_item.get("option_string", "defaults") + else: + return "defaults" def create_swapfile(root_mount_point, root_btrfs): diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 90609cb56..9a2e92e69 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -77,12 +77,18 @@ def is_ssd_disk(partition): def get_mount_options(filesystem, mount_options, partition): """ + Returns the mount options for the partition object and filesystem - :param filesystem: - :param mount_options: - :param partition: - :return: + :param filesystem: A string containing the filesystem + :param mount_options: A list of dicts that descripes the mount options for each mountpoint + :param partition: A dict containing information about the partition + :return: A comma seperated string containing the mount options suitable for passing to mount """ + + # Extra mounts can optionally have "options" set, in this case, they override other all other settings + if "options" in partition: + return ",".join(partition["options"]) + # If there are no mount options defined then we use the defaults if mount_options is None: return "defaults" @@ -97,7 +103,9 @@ def get_mount_options(filesystem, mount_options, partition): if options is None: return "defaults" - option_items = options.get("options", []) + option_items = options.get("options", []).copy() + + # Append the appropriate options for ssd or hdd if set if is_ssd_disk(partition): option_items.extend(options.get("ssdOptions", [])) else: @@ -210,6 +218,13 @@ def mount_zfs(root_mount_point, partition): def mount_partition(root_mount_point, partition, partitions, mount_options, mount_options_list): """ Do a single mount of @p partition inside @p root_mount_point. + + :param root_mount_point: A string containing the root of the install + :param partition: A dict containing information about the partition + :param partitions: The full list of partitions used to filter out btrfs subvols which have duplicate mountpoints + :param mount_options: The mount options from the config file + :param mount_options_list: A list of options for each mountpoint to be placed in global storage for future modules + :return: """ # Create mount point with `+` rather than `os.path.join()` because # `partition["mountPoint"]` starts with a '/'. @@ -251,7 +266,7 @@ def mount_partition(root_mount_point, partition, partitions, mount_options, moun fstype, mount_options_string) != 0: libcalamares.utils.warning("Cannot mount {}".format(device)) - mount_options_list.append({"mountpoint": mount_point, "option_string": mount_options_string}) + mount_options_list.append({"mountpoint": raw_mount_point, "option_string": mount_options_string}) # Special handling for btrfs subvolumes. Create the subvolumes listed in mount.conf if fstype == "btrfs" and partition["mountPoint"] == '/': @@ -286,7 +301,7 @@ def mount_partition(root_mount_point, partition, partitions, mount_options, moun else: mount_option += "," + get_mount_options(fstype, mount_options, partition) subvolume_mountpoint = mount_point[:-1] + s['mountPoint'] - mount_options_list.append({"mountpoint": subvolume_mountpoint, "option_string": mount_option}) + mount_options_list.append({"mountpoint": s['mountPoint'], "option_string": mount_option}) if libcalamares.utils.mount(device, subvolume_mountpoint, fstype, diff --git a/src/modules/mount/mount.conf b/src/modules/mount/mount.conf index 56313b188..cff222b2d 100644 --- a/src/modules/mount/mount.conf +++ b/src/modules/mount/mount.conf @@ -28,13 +28,13 @@ extraMounts: mountPoint: /sys - device: /dev mountPoint: /dev - options: bind + options: [ bind ] - device: tmpfs fs: tmpfs mountPoint: /run - device: /run/udev mountPoint: /run/udev - options: bind + options: [ bind ] - device: efivarfs fs: efivarfs mountPoint: /sys/firmware/efi/efivars