From 58bfe12d2175339f32af5f829351e1e78fef6ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yao=20Wei=20=28=E9=AD=8F=E9=8A=98=E5=BB=B7=29?= Date: Mon, 18 Dec 2023 11:17:23 +0100 Subject: [PATCH 1/2] reset_partition accepts fixed size --- subiquity/common/types.py | 1 + subiquity/server/controllers/filesystem.py | 23 +++++++++++++++++-- .../controllers/tests/test_filesystem.py | 20 ++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/subiquity/common/types.py b/subiquity/common/types.py index 712f2699..08d909b9 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -531,6 +531,7 @@ class GuidedChoiceV2: sizing_policy: Optional[SizingPolicy] = SizingPolicy.SCALED reset_partition: bool = False + reset_partition_size: Optional[int] = None @attr.s(auto_attribs=True) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index fe87487e..31ef2a7f 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -29,6 +29,7 @@ import pyudev from curtin import swap from curtin.commands.extract import AbstractSourceHandler from curtin.storage_config import ptable_part_type_to_flag +from curtin.util import human2bytes from subiquity.common.apidef import API from subiquity.common.errorreport import ErrorReportKind @@ -707,7 +708,10 @@ class FilesystemController(SubiquityController, FilesystemManipulator): raise Exception("failed to locate gap after adding boot") if choice.reset_partition: - if self.app.opts.dry_run: + if choice.reset_partition_size is not None: + part_align = disk.alignment_data().part_align + reset_size = align_up(choice.reset_partition_size, part_align) + elif self.app.opts.dry_run: reset_size = DRY_RUN_RESET_SIZE else: cp = await arun_command(["du", "-sb", "/cdrom"]) @@ -1410,6 +1414,20 @@ class FilesystemController(SubiquityController, FilesystemManipulator): disk_id=gap.device.id, gap=gap, allowed=[] ) + reset_partition = False + reset_partition_size = None + rp_input = layout.get("reset-partition", None) + if rp_input: + reset_partition = True + if isinstance(rp_input, (str, int)): + reset_partition_size = int(human2bytes(rp_input)) + log.info( + "autoinstall: will install reset partition " + f"of size {reset_partition_size}" + ) + else: + log.info("autoinstall: will install reset partition") + log.info( f"autoinstall: running guided {capability} install in " f"mode {mode} using {target}" @@ -1421,7 +1439,8 @@ class FilesystemController(SubiquityController, FilesystemManipulator): password=password, recovery_key=guided_recovery_key, sizing_policy=sizing_policy, - reset_partition=layout.get("reset-partition", False), + reset_partition=reset_partition, + reset_partition_size=reset_partition_size, ), reset_partition_only=layout.get("reset-partition-only", False), ) diff --git a/subiquity/server/controllers/tests/test_filesystem.py b/subiquity/server/controllers/tests/test_filesystem.py index 4321601d..f841cf39 100644 --- a/subiquity/server/controllers/tests/test_filesystem.py +++ b/subiquity/server/controllers/tests/test_filesystem.py @@ -459,6 +459,26 @@ class TestGuided(IsolatedAsyncioTestCase): self.assertEqual(DRY_RUN_RESET_SIZE, d1p2.size) self.assertEqual("/", d1p3.mount) + async def test_fixed_reset_partition(self): + await self._guided_setup(Bootloader.UEFI, "gpt") + target = GuidedStorageTargetReformat( + disk_id=self.d1.id, allowed=default_capabilities + ) + fixed_reset_size = 12 << 30 + await self.controller.guided( + GuidedChoiceV2( + target=target, + capability=GuidedCapability.DIRECT, + reset_partition=True, + reset_partition_size=fixed_reset_size, + ) + ) + [d1p1, d1p2, d1p3] = self.d1.partitions() + self.assertEqual("/boot/efi", d1p1.mount) + self.assertIsNone(d1p2.mount) + self.assertEqual(fixed_reset_size, d1p2.size) + self.assertEqual("/", d1p3.mount) + async def test_guided_reset_partition_only(self): await self._guided_setup(Bootloader.UEFI, "gpt") target = GuidedStorageTargetReformat( From 61d748d549fd081e2055d4a845e98d30554effad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yao=20Wei=20=28=E9=AD=8F=E9=8A=98=E5=BB=B7=29?= Date: Mon, 12 Feb 2024 16:47:17 +0800 Subject: [PATCH 2/2] doc: add Reset Partition to `autoinstall-reference.rst` --- doc/reference/autoinstall-reference.rst | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/reference/autoinstall-reference.rst b/doc/reference/autoinstall-reference.rst index 66f05db3..ca07c0d6 100644 --- a/doc/reference/autoinstall-reference.rst +++ b/doc/reference/autoinstall-reference.rst @@ -423,6 +423,41 @@ Example with no size scaling and a passphrase: sizing-policy: all password: LUKS_PASSPHRASE +Reset Partition +^^^^^^^^^^^^^^^ + +``reset-partition`` is used for creating a Reset Partition, which is a FAT32 file system containing the entire content of the installer image, so that the user can start the installer from GRUB or EFI without using the installation media. This option is useful for OEM system provisioning. + +By default, the size of a Reset Partition is roughly 1.1x the used file system size of the installation media. + +An example to enable Reset Partition: + +.. code-block:: yaml + + storage: + layout: + name: direct + reset-partition: true + +The size of the reset partition can also be fixed to a specified size. This is an example to fix Reset Partition to 12 GiB: + +.. code-block:: yaml + + storage: + layout: + name: direct + reset-partition: 12G + +The installer can also install Reset Partition without installing the system. To do this, set ``reset-partition-only`` to ``true``: + +.. code-block:: yaml + + storage: + layout: + name: direct + reset-partition: true + reset-partition-only: true + Action-based configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^