From 91e422e3333af12bcff3f3f1ef06d4e2fedfab20 Mon Sep 17 00:00:00 2001 From: Tyler Smith <74526874+tylertms@users.noreply.github.com> Date: Wed, 11 Nov 2026 03:52:20 -0500 Subject: [PATCH] fix(setup): put macOS on a USB of 32 GB or more also when --usb names one of its mounted volumes, and keep a recovery-only IPSW a network installer --- crates/stela-cli/src/setup/create.rs | 43 ++++++++++++++++++++++++++-- crates/stela-cli/src/setup/tests.rs | 17 +++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/crates/stela-cli/src/setup/create.rs b/crates/stela-cli/src/setup/create.rs index 7e0fd84c90..f76e0243e4 100644 --- a/crates/stela-cli/src/setup/create.rs +++ b/crates/stela-cli/src/setup/create.rs @@ -927,10 +927,19 @@ pub(super) fn setup(environment: &Environment<'_>, mut command: Request) -> Resu confirm_erase(host, &found)?; } // A new setup puts macOS on a USB large enough for it. - command - .install_image - .get_or_insert(super::default_install_image(found.bytes)); + if command.install_image.is_none() { + command.install_image = Some(default_image(found.bytes, command.ipsw.as_deref())?); + } erase = Some((disk, found.name, found.bytes, identity)); + } else if command.install_image.is_none() && command.target.is_none() { + // A USB named by one of its mounted volumes is set up as the same + // USB erased by setup would be: macOS goes on it when it is large + // enough. An interrupted setup it holds keeps its own choice. + let esp = super::locate_esp(host, &command.usb)?; + if !esp.join(RECORD).exists() { + let capacity = usb_capacity(host, &command.usb)?; + command.install_image = Some(default_image(capacity, command.ipsw.as_deref())?); + } } // Downloaded boot archives are kept in one place until setup finishes, // so a setup run again after a stop reuses them, and removed once it @@ -1075,6 +1084,34 @@ pub(super) fn setup(environment: &Environment<'_>, mut command: Request) -> Resu Ok(report) } +/// A new setup's installer for a USB of `capacity` bytes: macOS goes on a +/// large enough USB (`super::default_install_image`), unless the local IPSW +/// holds only the recovery members, which prepare the boot files alone. +fn default_image(capacity: u64, ipsw: Option<&Path>) -> Result { + let image = super::default_install_image(capacity); + match ipsw { + Some(ipsw) + if image == InstallImage::Full && !restore::payload::holds_system_image(ipsw)? => + { + Ok(InstallImage::Network) + } + _ => Ok(image), + } +} + +/// The bytes of the whole disk holding the mounted volume `usb`, as the +/// host lists it; 0 when the host names no such disk. +fn usb_capacity(host: &dyn Host, usb: &Path) -> Result { + let Some(disk) = host.volume(usb)?.disk else { + return Ok(0); + }; + Ok(host + .disks()? + .into_iter() + .find(|listed| listed.identifier == disk) + .map_or(0, |listed| listed.bytes)) +} + /// Ask before erasing `disk` at a terminal: a mistyped disk name would /// erase another removable disk. fn confirm_erase(host: &dyn Host, disk: &host::Disk) -> Result<()> { diff --git a/crates/stela-cli/src/setup/tests.rs b/crates/stela-cli/src/setup/tests.rs index eb87dd2302..a334c21cce 100644 --- a/crates/stela-cli/src/setup/tests.rs +++ b/crates/stela-cli/src/setup/tests.rs @@ -4314,3 +4314,20 @@ fn a_new_setup_puts_macos_on_a_usb_of_32_gb_or_more() { assert_eq!(default_install_image(31_000_000_000), InstallImage::Full); assert_eq!(default_install_image(64 * GIB), InstallImage::Full); } + +#[test] +fn a_usb_named_by_its_mounted_volume_gets_the_installer_its_size_allows() { + for (bytes, full) in [(16_000_000_000, false), (32_000_000_000, true)] { + let mut f = fixture(64 * GIB, false); + add_stela(&mut f); + for disk in f.host.disks.iter_mut().filter(|d| d.identifier == "disk5") { + disk.bytes = bytes; + } + let volume = stela_volume(&f); + let mut dry = command(&f, &volume); + dry.install_image = None; + dry.dry_run = true; + let plan = setup(&environment(&f.host), dry).unwrap(); + assert_eq!(!plan.contains("file list only"), full, "{bytes}: {plan}"); + } +}