From ea4fe8ad4bf8b7d84165bb45f3aba595ef1523c0 Mon Sep 17 00:00:00 2001 From: Pragyan Poudyal Date: Tue, 6 Oct 2026 11:32:54 +0530 Subject: [PATCH] to-disk: Add `run-repart` option With this we'll only run the systemd-repart definitions if we find them in the image and `--run-repart` is passed in Signed-off-by: Pragyan Poudyal --- crates/lib/src/install.rs | 8 +++++- crates/lib/src/install/baseline.rs | 5 +++- docs/src/man/bootc-install-to-disk.8.md | 4 +++ tmt/tests/booted/test-install-repart.nu | 38 +++++++++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/crates/lib/src/install.rs b/crates/lib/src/install.rs index 8f9f80fc47..f20ad36015 100644 --- a/crates/lib/src/install.rs +++ b/crates/lib/src/install.rs @@ -467,6 +467,12 @@ pub(crate) struct InstallToDiskOpts { #[clap(flatten)] #[serde(flatten)] pub(crate) composefs_opts: InstallComposefsOpts, + + /// Whether to use systemd-repart for partitioning. + /// This requires the image to have repart.d definitions + #[clap(long)] + #[serde(default)] + pub(crate) run_repart: bool, } #[derive(ValueEnum, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -2340,7 +2346,7 @@ pub(crate) async fn install_to_disk(mut opts: InstallToDiskOpts) -> Result<()> { let state = state.clone(); let rootfs = tokio::task::spawn_blocking(move || { - baseline::install_create_rootfs(&state, block_opts) + baseline::install_create_rootfs(&state, block_opts, opts.run_repart) }) .await??; (rootfs, loopback_dev) diff --git a/crates/lib/src/install/baseline.rs b/crates/lib/src/install/baseline.rs index f4d07c96ac..d45688a596 100644 --- a/crates/lib/src/install/baseline.rs +++ b/crates/lib/src/install/baseline.rs @@ -66,6 +66,8 @@ fn use_discoverable_partitions(state: &State) -> bool { // This ensures we end up under 512 to be small-sized. pub(crate) const BOOTPN_SIZE_MB: u32 = 510; +// NOTE: If you change this or [`CFS_EFIPN_SIZE_MB`] below, +// make sure to update the test test-install-reaprt.nu pub(crate) const EFIPN_SIZE_MB: u32 = 512; /// EFI Partition size for composefs installations /// We need more space than ostree as we have UKIs and UKI addons @@ -625,6 +627,7 @@ fn sfdisk( pub(crate) fn install_create_rootfs( state: &State, opts: InstallBlockDeviceOpts, + run_repart: bool, ) -> Result { let install_config = state.install_config.as_ref(); let luks_name = "root"; @@ -660,7 +663,7 @@ pub(crate) fn install_create_rootfs( std::fs::remove_dir_all(&mntdir)?; } - let use_systemd_repart = can_use_systemd_repart(); + let use_systemd_repart = run_repart && can_use_systemd_repart(); // Use the install configuration to find the block setup, if we have one let block_setup = if let Some(config) = install_config { diff --git a/docs/src/man/bootc-install-to-disk.8.md b/docs/src/man/bootc-install-to-disk.8.md index 776c01ab11..a68ece0078 100644 --- a/docs/src/man/bootc-install-to-disk.8.md +++ b/docs/src/man/bootc-install-to-disk.8.md @@ -190,6 +190,10 @@ set `discoverable-partitions = true` in their install configuration Name of the UKI addons to install without the ".efi.addon" suffix. This option can be provided multiple times if multiple addons are to be installed (composefs backend only) +**--run-repart** + + Whether to use systemd-repart for partitioning. This requires the image to have repart.d definitions + # EXAMPLES diff --git a/tmt/tests/booted/test-install-repart.nu b/tmt/tests/booted/test-install-repart.nu index 0d806d8f5c..8d1c7f673d 100644 --- a/tmt/tests/booted/test-install-repart.nu +++ b/tmt/tests/booted/test-install-repart.nu @@ -86,6 +86,40 @@ EOF run_install_to_disk localhost/bootc-repart [] + # since `--no-repart` wasn't passed in, sfdisk should've been used + let loop = (losetup -f --show /var/disk.img | str trim) + try { + partx -u $loop + udevadm settle + let parts = (lsblk -J -b -o name,parttype,partuuid,size $loop | from json) + let children = ($parts.blockdevices.0.children) + let part_types = ($children | get parttype) + + # ESP GUID + let esp_guid = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" + assert ($part_types | any {|t| ($t | str downcase) == $esp_guid }) "ESP partition not found" + + let esp_mb = if (tap is_composefs) { 2048 } else { 512 } + # Verify ESP size + let esp_part = ($children | where {|t| ($t.parttype | str downcase) == $esp_guid } | first) + let esp_size_bytes = ($esp_part.size | into int) + let esp_expected = ($esp_mb * 1024 * 1024) + + assert ($esp_size_bytes == $esp_expected) $"ESP should be ($esp_mb)M from sfdisk, got ($esp_size_bytes) bytes" + + print "PASS: sfdisk created BIOS + ESP + root partitions" + } catch { |e| + losetup -d $loop + error make { msg: $"No-repart verification failed: ($e.msg)" } + } + + losetup -d $loop + + rm -rvf /var/disk.img + truncate -s 10G /var/disk.img + + run_install_to_disk localhost/bootc-repart ["--run-repart"] + # Verify partition layout let loop = (losetup -f --show /var/disk.img | str trim) try { @@ -184,13 +218,13 @@ EOF truncate -s 10G /var/disk.img setenforce 0 - run_install_to_disk localhost/bootc-repart-noroot ["--filesystem" "ext4" "--root-size" "7G"] + run_install_to_disk localhost/bootc-repart-noroot ["--run-repart" "--filesystem" "ext4" "--root-size" "7G"] # Verify partition layout verify_part_layout_second_boot # Install again without passing in root-size make sure it works - run_install_to_disk localhost/bootc-repart-noroot ["--filesystem" "ext4"] + run_install_to_disk localhost/bootc-repart-noroot ["--run-repart" "--filesystem" "ext4"] # Verify partition layout (again) verify_part_layout_second_boot