From f585505069ada644450dc892a1713b04fdc1ad06 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 21 Mar 2023 16:55:43 +1300 Subject: [PATCH] do not let size: largest in storage autoinstall config match the install media --- documentation/autoinstall-reference.md | 2 ++ subiquity/models/filesystem.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/documentation/autoinstall-reference.md b/documentation/autoinstall-reference.md index ea2b4076..6c66326b 100644 --- a/documentation/autoinstall-reference.md +++ b/documentation/autoinstall-reference.md @@ -345,6 +345,8 @@ A match spec supports the following keys: * `ssd: yes|no`: matches a disk that is or is not an SSD (vs a rotating drive) * `size: largest|smallest`: take the largest or smallest disk rather than an arbitrary one if there are multiple matches (support for `smallest` added in version 20.06.1) +A special sort of key is `install-media: yes`, which will take the disk the installer was loaded from (the `ssd` and `size` selectors will never return this disk). If installing to the install media, care obviously needs to be take to not overwrite the installer itself! + So for example, to match an arbitrary disk it is simply: - type: disk diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index b22854c4..74a434f4 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -1185,6 +1185,12 @@ class FilesystemModel(object): is_ssd = disk.info_for_display()['rotational'] == 'false' return is_ssd == match['ssd'] + def match_install_media(disk): + return disk in self._exclusions + + if match.get('install-media', False): + matchers.append(match_install_media) + if 'serial' in match: matchers.append(match_serial) if 'model' in match: @@ -1209,6 +1215,8 @@ class FilesystemModel(object): break else: candidates.append(candidate) + if 'size' in match or 'ssd' in match: + candidates = [c for c in candidates if c not in self._exclusions] if match.get('size') == 'smallest': candidates.sort(key=lambda d: d.size) if match.get('size') == 'largest':