Run a virtual iPhone on an Apple Silicon Mac.
Swift
Launchpad: iOS 18 machines, linked by a macOS builder over ssh
Maximilian Paßa1c978a7afb7
diff --git a/Documents/Guides/compatibility.md b/Documents/Guides/compatibility.mdindex db764e0b..c13fac0b 100644--- a/Documents/Guides/compatibility.md+++ b/Documents/Guides/compatibility.md@@ -27,7 +27,7 @@ The cloudOS 26.4 beta image (`26.4-23E5207q`) is the newest one that contains `vOn such a cloudOS the research board stands in (the Research Board patch set): `fw patch` turns its device tree and SEP into vphone600's and rebuilds its kernelcache with the vphone600 virtualisation kexts, from a recipe for that kernelcache. That needs an `ipsw` with `kernel extract --kdk` and root for the link (`vphone-cli fw kernelcache`; see [the recipes](../../VPhoneExecutable/VPhoneVirtualization/Resources/kernelcache_recipes/README.md)). `fw prepare` refuses a cloudOS no recipe covers. `fw catalog` lists each iOS release's own cloudOS beside the recommended one, and Launchpad offers it under Firmware.-iOS 18.1 to 18.7.2 run the same way on their own release's cloudOS, with the userland of the iPhone XS family's IPSWs (`vm create --device iPhone11,6`, the Minimal preset; `fw catalog --device iPhone11,6` lists them). Their kernels are kernel-first: from macOS 26.4 on, another Mac or a macOS VM running macOS 15 or 26.0 to 26.3 links the mix over ssh (`VPHONE_KMUTIL_SSH`, see [Creating and running](create-and-run.md)), which Launchpad does not, so it does not offer them. 18.1, 18.5 and 18.7.2 are checked on VMs; the other four recipes have not been booted yet.+iOS 18.1 to 18.7.2 run the same way on their own release's cloudOS, with the userland of the iPhone XS family's IPSWs (`vm create --device iPhone11,6`, the Minimal preset; `fw catalog --device iPhone11,6` lists them). Their kernels are kernel-first: from macOS 26.4 on, another Mac or a macOS VM running macOS 15 or 26.0 to 26.3 links the mix over ssh (`VPHONE_KMUTIL_SSH`, see [Creating and running](create-and-run.md)); Launchpad offers them as the iPhone XS Max, with that Mac as the macOS builder. 18.1, 18.5 and 18.7.2 are checked on VMs; the other four recipes have not been booted yet.| cloudOS | `vresearch101ap` | `vphone600ap` | kernelcache recipe || --- | --- | --- | --- |diff --git a/Documents/Guides/create-and-run.md b/Documents/Guides/create-and-run.mdindex 41d6b870..3b6b0d94 100644--- a/Documents/Guides/create-and-run.md+++ b/Documents/Guides/create-and-run.md@@ -141,6 +141,8 @@ Launchpad 2.9 creates machines from templates by default. New Machine opens on aUnder Firmware, a release that also runs on its own cloudOS (`fw catalog`'s third column) offers that cloudOS beside the recommended one, with the `ipsw` that stages the kernelcache mix. The creation then stages the mix as you and has the helper link it as root, which asks for authorization once.+The iPhone XS Max runs iOS 18.1 to 18.7.2, each on its own release's cloudOS, with the Minimal preset and no template. Its pairings always rebuild the kernelcache, so Firmware asks for the `ipsw`, and for the macOS builder: `user@host` of a Mac or macOS VM running macOS 15 or 26.0 to 26.3 with Remote Login on, and its password for ssh and sudo (empty with ssh keys and passwordless sudo). Launchpad keeps the builder like the `ipsw`, but not the password, which reaches `vphone-cli` only in its environment (`VPHONE_KMUTIL_SSH_PASSWORD`). The creation then stages and links the mix as you, over ssh; from macOS 26.4 on the builder is required, on an older Mac without one the helper links it as root.+The creation runs `vm template find` first. When a current template matches, it clones the machine (`vm create --template <id> --skip-first-boot`) and boots it. When none does, it builds the template in a temporary machine of the same library, named `template-` and eight hex digits, with its usual steps (restore, then `cfw install` through the helper), then `vm template trim`, the headless `vm template setup --strict` and `vm template adopt --iphone-source … --cloudos-source … --expect <id>`, and clones the machine from the result. The setup boot fails when an app it should remove stays, and the adopt fails when the build's key comes out other than the one `find` computed, so a build is never saved under an id later creations would not find. Each is a step of its own with its duration, and a failed one shows the reason `vphone-cli` gave.Per-patch overrides from New Machine's Patch Settings are split the way the template key splits them. Boot-chain overrides are part of the key: the template is built with them, and `find` looks for one with them. Guest patch overrides are not: the template is built without them, and after the clone the creation records them on the new machine with `fw set-patches` and writes them with `cfw update-environment` through the helper (the Apply guest patches step) before its first boot. A template therefore never hands one creation's guest patch choice to another. Once it has built a template, the creation offers to delete the two IPSWs it came from; nothing is deleted without confirming.diff --git a/Documents/Guides/launchpad-cli.md b/Documents/Guides/launchpad-cli.mdindex d6dcb580..ca761688 100644--- a/Documents/Guides/launchpad-cli.md+++ b/Documents/Guides/launchpad-cli.md@@ -113,7 +113,7 @@ version while a machine is bound to it; rebind or delete those machines first.| `vm list` | Machines in every library with run state, Core Bundle and log path. Only a VM process holding the disk (`vphone-vm`, or Virtualization's VM service) makes a machine `running`; any other process that has it open (`tail`, Spotlight, a backup tool) is listed in `diskOpenIn` (`12925 tail`) and leaves it `stopped` || `vm start <name> [--headless] [--wait]` / `vm stop <name>` | Launch with the machine's bundle, or stop; `--wait` waits for vphoned. Stop asks the guest to shut down (vphoned `system.shutdown`) and waits up to 30 s; when the guest cannot be asked or does not stop, it ends the virtual machine as before. Like `vphone-cli vm launch`, start is not refused by a process that only has the disk open; it prints a note naming it || `vm wait <name>` / `vm log <name> [--kind create\|dfu\|patch]` | Wait for vphoned; read a console log |-| `vm create <name> [--bundle <version>] [...] [--device <product-type>] [--preset <preset>] [--ipsw <path>] [--block <patch>]... [--allow <patch>]... [--no-template \| --slim on\|off --trim … --keep-languages … --service-profile … --remove-apps … --keep-apps … --accounts-off] [--from <step>]` | The New Machine pipeline, bound to `--bundle` or the default: cloned from a template, built first when missing (2.9), or restored on its own with `--no-template`; the slimming switches are `vphone-cli vm create`'s, except that Apple Account goes with the trimmed service profile as in New Machine (`--accounts-off` is accepted and changes nothing). `--block`/`--allow` (repeatable) turn one patch of the preset off or on, as New Machine's patch list and `vphone-cli fw set-patches` do (see below). `--device` makes an iPad guest, or with `AppleTV5,3` an Apple TV HD guest, which is always restored on its own without slimming and takes the `tvos` preset unless `--preset` names another, and with `AppleTV14,1` an Apple TV 4K guest, the same with the `tvos-4k` preset and its userland from the catalog's OTA; `--preset minimal` (Minimal: a stock boot chain, kernel and TXM, with the system customised before the restore) is also restored on its own without slimming, and its `fw patch` runs as root through the helper; `--ipsw` names the ipsw that stages the kernelcache mix of a machine on its release's own cloudOS, as New Machine's ipsw field (the helper links it as root); `--from` retries from a step (`findTemplate` … `firstBoot`) with the options the creation started with; the result names the template, whether this creation built it, and the patches it used |+| `vm create <name> [--bundle <version>] [...] [--device <product-type>] [--preset <preset>] [--ipsw <path>] [--kmutil-ssh <user@host>] [--block <patch>]... [--allow <patch>]... [--no-template \| --slim on\|off --trim … --keep-languages … --service-profile … --remove-apps … --keep-apps … --accounts-off] [--from <step>]` | The New Machine pipeline, bound to `--bundle` or the default: cloned from a template, built first when missing (2.9), or restored on its own with `--no-template`; the slimming switches are `vphone-cli vm create`'s, except that Apple Account goes with the trimmed service profile as in New Machine (`--accounts-off` is accepted and changes nothing). `--block`/`--allow` (repeatable) turn one patch of the preset off or on, as New Machine's patch list and `vphone-cli fw set-patches` do (see below). `--device` makes an iPad guest, or with `AppleTV5,3` an Apple TV HD guest, which is always restored on its own without slimming and takes the `tvos` preset unless `--preset` names another, and with `AppleTV14,1` an Apple TV 4K guest, the same with the `tvos-4k` preset and its userland from the catalog's OTA; `--preset minimal` (Minimal: a stock boot chain, kernel and TXM, with the system customised before the restore) is also restored on its own without slimming, and its `fw patch` runs as root through the helper; `--ipsw` names the ipsw that stages the kernelcache mix of a machine on its release's own cloudOS, as New Machine's ipsw field (the helper links it as root); `--kmutil-ssh` names the Mac that links an iOS 18 guest's (`--device iPhone11,6`) kernel-first mix over ssh, as New Machine's macOS builder field, and takes the password for ssh and sudo there from the client's `VPHONE_KMUTIL_SSH_PASSWORD`, never from an argument; `--from` retries from a step (`findTemplate` … `firstBoot`) with the options the creation started with; the result names the template, whether this creation built it, and the patches it used || `vm set-bundle <name> <version> [--update-environment]` | Bind a machine to another installed version. `--update-environment` also redeploys that version's guest environment and needs a stopped machine; a disk another process has open refuses it, naming that process, before the binding changes. If the update itself fails, the machine stays bound to the new version and `vm list` still shows the old `guestEnvironmentBundle`: run `cfw update-environment` to finish || `vm leases [--release]` | DHCP leases on the shared NAT network and the machine that owns each. `--release` frees the ones no machine in any library uses, through the helper (see [Networking](networking.md#addresses-held-by-old-macs)) || `cfw install <name>` | Install CFW into a stopped machine with its own bundle, through the helper. The helper puts temporary work files on the VM library's external volume when applicable. It and the two updates below refuse a disk another process has open, naming it (`12925 tail`). |diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swiftindex 71cab716..5f2b421b 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swift@@ -179,8 +179,7 @@ struct VPhoneFirmwareCatalogCommand: ParsableCommand {var device: String?func run() throws {- // Launchpad reads the JSON; the listing names the CLI-only devices too.- let report = json ? VPhoneFirmwareCatalog.report : VPhoneFirmwareCatalog.report(includingCLIOnly: true)+ let report = VPhoneFirmwareCatalog.reportif json {try print(String(decoding: JSONEncoder().encode(report), as: UTF8.self))returndiff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swiftindex ce3fc07c..835f60ea 100644--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift@@ -603,11 +603,6 @@ public enum VPhoneFirmwareCatalog {/// JSON-friendly projection of the catalog: each build with its recommended/// cloudOS, for the iPhone and then per guest device.public static var report: VPhoneFirmwareCatalogReport {- report(includingCLIOnly: false)- }-- /// The catalog, with the devices only the CLI creates when `includingCLIOnly`.- public static func report(includingCLIOnly: Bool) -> VPhoneFirmwareCatalogReport {func entries(_ pairings: [VPhoneFirmwarePairing]) -> [VPhoneFirmwareCatalogReport.Entry] {pairings.map {let ota = otaRelease(source: $0.iosURL)@@ -628,10 +623,6 @@ public enum VPhoneFirmwareCatalog {device: device,pairings: entries(pairings),devices: VPhoneGuestDevice.known.compactMap { guest in- // The iOS 18 research board releases link kernel-first, over ssh- // on an older Mac from macOS 26.4 on, which Launchpad's root link- // does not: `vphone-cli fw catalog --device` lists them.- guard includingCLIOnly || guest.notchedArtworkSubtype == nil else { return nil }let pairings = pairings(for: guest.productType)guard !pairings.isEmpty else { return nil }return .init(@@ -639,6 +630,9 @@ public enum VPhoneFirmwareCatalog {name: guest.productName,family: guest.family.rawValue,pairings: entries(pairings),+ // The iOS 18 research board kernels: from macOS 26.4 on, a+ // Mac running an older macOS links them over ssh.+ kernelcacheLayout: guest.notchedArtworkSubtype == nil ? nil : "kernel-first",)},)@@ -688,11 +682,16 @@ public struct VPhoneFirmwareCatalogReport: Codable, Equatable, Sendable {/// `iPhone`, `iPad` or `appleTV`.public let family: Stringpublic let pairings: [Entry]- public init(productType: String, name: String, family: String, pairings: [Entry]) {+ /// `kernel-first` for a device whose every pairing boots a kernelcache+ /// mix that only the kmutil of macOS 15 or 26.0 to 26.3 links+ /// (`VPHONE_KMUTIL_SSH` from 26.4 on); absent for every other device.+ public let kernelcacheLayout: String?+ public init(productType: String, name: String, family: String, pairings: [Entry], kernelcacheLayout: String? = nil) {self.productType = productTypeself.name = nameself.family = familyself.pairings = pairings+ self.kernelcacheLayout = kernelcacheLayout}}diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swiftindex 0cdd5de7..f2f1098b 100644--- a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift@@ -50,9 +50,7 @@ struct FirmwareCatalogReportTests {@Test func `lists every curated guest`() {let report = VPhoneFirmwareCatalog.report- // Launchpad's list leaves out the CLI-only iPhone XS Max.- #expect(report.devices.map(\.productType) == VPhoneGuestDevice.known.map(\.productType).filter { $0 != "iPhone11,6" })- #expect(VPhoneFirmwareCatalog.report(includingCLIOnly: true).devices.map(\.productType) == VPhoneGuestDevice.known.map(\.productType))+ #expect(report.devices.map(\.productType) == VPhoneGuestDevice.known.map(\.productType))#expect(report.devices.first?.pairings == report.pairings)for device in report.devices.dropFirst() {#expect(device.family == VPhoneGuestDevice.named(device.productType)?.family.rawValue)@@ -150,7 +148,7 @@ struct FirmwareCatalogReportTests {#expect(VPhoneFirmwareCatalog.pairings(for: "iPhone18,1") != VPhoneFirmwareCatalog.pairings)}- @Test func `an i phone XS max pairs each iOS 18 release with its own research board cloud OS, for the CLI only`() {+ @Test func `an i phone XS max pairs each iOS 18 release with its own research board cloud OS, linked kernel-first`() {let pairings = VPhoneFirmwareCatalog.pairings(for: "iPhone11,6")#expect(pairings.map(\.iosName) == ["iOS 18.1", "iOS 18.2.1", "iOS 18.3.1", "iOS 18.5", "iOS 18.6", "iOS 18.7", "iOS 18.7.2"])for p in pairings {@@ -161,8 +159,9 @@ struct FirmwareCatalogReportTests {#expect(p.cloudosURL.contains("/private-cloud-compute/"))}#expect(VPhoneFirmwareCatalog.pairings(for: "iPhone11,4") == pairings)- #expect(!VPhoneFirmwareCatalog.report.devices.contains { $0.productType == "iPhone11,6" })- #expect(VPhoneFirmwareCatalog.report(includingCLIOnly: true).devices.contains { $0.productType == "iPhone11,6" })+ let devices = VPhoneFirmwareCatalog.report.devices+ #expect(devices.first { $0.productType == "iPhone11,6" }?.kernelcacheLayout == "kernel-first")+ #expect(devices.filter { $0.kernelcacheLayout != nil }.map(\.productType) == ["iPhone11,6"])}@Test func `cellular i pad gets its wi fi model's pairings`() {diff --git a/VPhoneLaunchpad/Tests/ControlTests.swift b/VPhoneLaunchpad/Tests/ControlTests.swiftindex 37a29446..43f00158 100644--- a/VPhoneLaunchpad/Tests/ControlTests.swift+++ b/VPhoneLaunchpad/Tests/ControlTests.swift@@ -72,6 +72,15 @@ struct ControlTests {let usage = try require(VPhoneLaunchpadControlCommand.named("vm.create")).usageprecondition(usage.contains("[--block <value>]...") && usage.contains("[--allow <value>]..."), usage)++ // The ssh builder is named on the command line; its password never is.+ let (builder, _) = try parse(["vm", "create", "xs", "--ipsw", "/x/ipsw", "--kmutil-ssh", "[email protected]"])+ precondition(builder.option("kmutil-ssh") == "[email protected]", "Builder: \(builder)")+ precondition(+ failure(["vm", "create", "xs", "--\(VPhoneLaunchpadControlRequest.kmutilSSHPasswordOption)", "pw"])?.message+ == "unknown option --\(VPhoneLaunchpadControlRequest.kmutilSSHPasswordOption).",+ "No password option",+ )}/// A request from a CLI without repeated options still decodes, anddiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swiftindex 008df1d9..57941a1d 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadChildProcess.swift@@ -42,6 +42,8 @@ final nonisolated class VPhoneLaunchpadChildProcess: @unchecked Sendable {arguments: [String],currentDirectory: URL? = nil,logFile: URL? = nil,+ // Added to the environment of a child without `logFile`.+ environment extra: [String: String] = [:],onLine: @escaping @Sendable (String) -> Void,) throws {process.executableURL = executable@@ -85,6 +87,7 @@ final nonisolated class VPhoneLaunchpadChildProcess: @unchecked Sendable {// terminal bar, which the pipe would drop.var environment = ProcessInfo.processInfo.environmentenvironment["VPHONE_PROGRESS"] = "lines"+ environment.merge(extra) { _, given in given }process.environment = environmenttry process.run()let reader = pipe.fileHandleForReadingdiff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swiftindex 0d09beb2..9c73d6cc 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Command/VPhoneLaunchpadCommandLine.swift@@ -128,15 +128,17 @@ struct VPhoneLaunchpadCommandLine {/// Runs to completion. Cancelling the calling task sends SIGINT./// `onLine` and `onProgress` run on the reader thread, never on the main/// actor. Progress lines go only to `onProgress`, never to the output.+ /// `environment` is added to the child's; it never appears in the history.func run(_ arguments: [String],recordInHistory: Bool = true,+ environment: [String: String] = [:],onLine: (@Sendable (String) -> Void)? = nil,onProgress: (@Sendable (Double) -> Void)? = nil,) async throws -> VPhoneLaunchpadCommandResult {let entry = recordInHistory ? history.record(Self.display(arguments)) : nillet collector = VPhoneLaunchpadLineCollector()- let child = try VPhoneLaunchpadChildProcess(executable: executable, arguments: arguments) { line in+ let child = try VPhoneLaunchpadChildProcess(executable: executable, arguments: arguments, environment: environment) { line inif let fraction = Self.progress(in: line) {onProgress?(fraction)return@@ -159,10 +161,11 @@ struct VPhoneLaunchpadCommandLine {@discardableResultfunc runChecked(_ arguments: [String],+ environment: [String: String] = [:],onLine: (@Sendable (String) -> Void)? = nil,onProgress: (@Sendable (Double) -> Void)? = nil,) async throws -> VPhoneLaunchpadCommandResult {- let result = try await run(arguments, onLine: onLine, onProgress: onProgress)+ let result = try await run(arguments, environment: environment, onLine: onLine, onProgress: onProgress)try Task.checkCancellation()guard result.succeeded else {throw VPhoneLaunchpadError(diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swiftindex 6ee74eed..4a2603f3 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Control/VPhoneLaunchpadControlCommands.swift@@ -620,6 +620,20 @@ struct VPhoneLaunchpadControlCommands {if let kernelcacheIPSW, !FileManager.default.isExecutableFile(atPath: kernelcacheIPSW) {throw VPhoneLaunchpadError("--ipsw names \(kernelcacheIPSW), which is not an executable.")}+ // An iOS 18 guest's kernel-first mix is linked over ssh on the Mac+ // --kmutil-ssh names; vphone-launchpad-cli passes the password from its+ // own VPHONE_KMUTIL_SSH_PASSWORD, never as an argument.+ let kernelcacheBuilder = request.option("kmutil-ssh").map {+ VPhoneLaunchpadKernelcacheBuilder(destination: $0, password: request.option(VPhoneLaunchpadControlRequest.kmutilSSHPasswordOption))+ }+ if let kernelcacheBuilder {+ guard VPhoneLaunchpadKernelcacheBuilder.isValid(kernelcacheBuilder.destination) else {+ throw VPhoneLaunchpadError("--kmutil-ssh takes user@host, not \(kernelcacheBuilder.destination).")+ }+ guard kernelcacheIPSW != nil else {+ throw VPhoneLaunchpadError("--kmutil-ssh links the kernelcache mix that --ipsw stages; pass --ipsw too.")+ }+ }let options = try VPhoneLaunchpadCreationPipeline.Options(name: machine.name,libraryRoot: machine.libraryRoot,@@ -637,6 +651,7 @@ struct VPhoneLaunchpadControlCommands {usesTemplate: usesTemplate,slimming: slimming,kernelcacheIPSW: kernelcacheIPSW,+ kernelcacheBuilder: kernelcacheBuilder,)return library.create(options)}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swiftindex 160d595d..7374a6fe 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadCreationPipeline.swift@@ -2,6 +2,46 @@ import Darwinimport Foundationimport Observation+// MARK: - Kernelcache Builder++/// Another Mac, or a macOS VM, whose kmutil links an iOS 18 guest's+/// kernel-first kernelcache mix: kmutil takes the layout from the macOS it runs+/// on, and only macOS 15 and 26.0 to 26.3 link kernel-first. `fw kernelcache`+/// reaches it over ssh (`VPHONE_KMUTIL_SSH`) and links as root there, so the+/// helper links nothing. The password, for ssh and sudo, goes to `vphone-cli` in+/// its environment only: never into an argument, a log or a file.+nonisolated struct VPhoneLaunchpadKernelcacheBuilder: Sendable, Equatable {+ static let destinationVariable = "VPHONE_KMUTIL_SSH"+ static let passwordVariable = "VPHONE_KMUTIL_SSH_PASSWORD"++ /// `user@host`.+ var destination: String+ /// Nil or empty with ssh keys and passwordless sudo.+ var password: String?++ var environment: [String: String] {+ var environment = [Self.destinationVariable: destination]+ if let password, !password.isEmpty {+ environment[Self.passwordVariable] = password+ }+ return environment+ }++ /// Whether `destination` reads as `user@host`.+ static func isValid(_ destination: String) -> Bool {+ let parts = destination.split(separator: "@", omittingEmptySubsequences: false)+ return parts.count == 2 && parts.allSatisfy { !$0.isEmpty && !$0.contains(where: \.isWhitespace) }+ && !destination.hasPrefix("-")+ }++ /// Whether this Mac's kmutil links kernel-last (macOS 26.4 and later), so a+ /// kernel-first mix needs a builder.+ static var hostNeedsBuilder: Bool {+ let host = ProcessInfo.processInfo.operatingSystemVersion+ return host.majorVersion > 26 || host.majorVersion == 26 && host.minorVersion >= 4+ }+}+/// `vm create`, one command at a time.////// `vphone-cli vm create` runs the same stages in one process and asks for@@ -63,6 +103,9 @@ final class VPhoneLaunchpadCreationPipeline {/// release's own cloudOS (`fw kernelcache --ipsw`), whose link the helper/// runs as root. Nil for every other machine.var kernelcacheIPSW: String?+ /// The Mac that links a kernel-first mix over ssh, for an iOS 18 guest+ /// on a Mac whose kmutil links kernel-last; nil links here, as root.+ var kernelcacheBuilder: VPhoneLaunchpadKernelcacheBuilder?var machine: VPhoneLaunchpadMachinePath {VPhoneLaunchpadMachinePath(libraryRoot: libraryRoot, name: name)@@ -354,11 +397,14 @@ final class VPhoneLaunchpadCreationPipeline {func run(_ arguments: [String],+ builder: VPhoneLaunchpadKernelcacheBuilder? = nil,onLine: @escaping @Sendable (String) -> Void = output,onProgress: (@Sendable (Double) -> Void)? = nil,) async throws {- onLine("$ \(VPhoneLaunchpadCommandLine.display(arguments))")- try await commandLine.runChecked(arguments, onLine: onLine, onProgress: onProgress)+ // The builder's destination is shown, its password is not.+ let prefix = builder.map { "\(VPhoneLaunchpadKernelcacheBuilder.destinationVariable)=\($0.destination) " } ?? ""+ onLine("$ \(prefix)\(VPhoneLaunchpadCommandLine.display(arguments))")+ try await commandLine.runChecked(arguments, environment: builder?.environment ?? [:], onLine: onLine, onProgress: onProgress)}// For the template steps: a failure names the step and carries the@@ -448,7 +494,11 @@ final class VPhoneLaunchpadCreationPipeline {// On the release's own cloudOS the kernelcache is mixed first: staged// here, as the user, with the chosen ipsw, and linked by the helper as// root, which runs no ipsw. `fw patch` takes the mix from the cache.- if let ipsw = options.kernelcacheIPSW {+ // With an ssh builder, `fw kernelcache` links it on that Mac, and+ // nothing here needs root for it.+ if let ipsw = options.kernelcacheIPSW, let builder = options.kernelcacheBuilder {+ try await run(["fw", "kernelcache", name, "--ipsw", ipsw] + library, builder: builder, onLine: tee)+ } else if let ipsw = options.kernelcacheIPSW {try await run(["fw", "kernelcache", name, "--ipsw", ipsw] + library, onLine: tee)let status = try await helper.linkKernelcache(bundleVersion: version,diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swiftindex c21f84ef..f2890ed0 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachine.swift@@ -271,11 +271,21 @@ nonisolated struct VPhoneLaunchpadFirmwareCatalog: Decodable, Sendable {/// `iPhone`, `iPad`, `appleTV` or `watch`.let family: Stringlet pairings: [Pairing]+ /// `kernel-first` for a device whose kernelcache mix only the kmutil+ /// of macOS 15 or 26.0 to 26.3 links, from a bundle that has one.+ var kernelcacheLayout: String?var id: String {productType}+ /// The iOS 18 research board guest: every pairing rebuilds a+ /// kernel-first kernelcache, which from macOS 26.4 on another Mac links+ /// over ssh (`VPhoneLaunchpadKernelcacheBuilder`).+ var linksKernelFirst: Bool {+ kernelcacheLayout == "kernel-first"+ }+var isPad: Bool {family == "iPad"}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swiftindex 21612052..d857de07 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadNewMachineView.swift@@ -39,6 +39,12 @@ struct VPhoneLaunchpadNewMachineView: View {@State private var usesOwnCloudOS = false/// The ipsw that stages a mix; vphone-cli does not ship one.@AppStorage("KernelcacheIPSW") private var kernelcacheIPSW = ""+ /// The Mac that links an iOS 18 guest's kernel-first mix over ssh+ /// (`user@host`), kept like the ipsw.+ @AppStorage("KernelcacheBuilder") private var kernelcacheBuilderDestination = ""+ /// Its password, for ssh and sudo there. Kept only while the sheet is+ /// open, and by the creation that runs with it.+ @State private var kernelcacheBuilderPassword = ""@State private var cpu = Self.defaultCPU@State private var memoryMB = Self.defaultMemoryMB@State private var diskSizeGB = Self.defaultDiskSizeGB@@ -92,16 +98,47 @@ struct VPhoneLaunchpadNewMachineView: View {}/// Whether `fw patch` rebuilds the kernelcache, which needs the ipsw: on- /// the release's own cloudOS, and always for a watch, whose kexts no- /// cloudOS kernelcache has.+ /// the release's own cloudOS, always for a watch, whose kexts no cloudOS+ /// kernelcache has, and for an iOS 18 guest, which boots its own release's+ /// research board kernel.private var rebuildsKernelcache: Bool {- ownCloudOS != nil || !usesCustomSources && selectedGuest?.isWatch == true+ ownCloudOS != nil || !usesCustomSources && (selectedGuest?.isWatch == true || linksKernelFirst)}private var hasKernelcacheIPSW: Bool {FileManager.default.isExecutableFile(atPath: kernelcacheIPSW)}+ /// An iOS 18 guest from the catalog, whose kernelcache only the kmutil of+ /// macOS 15 or 26.0 to 26.3 links.+ private var linksKernelFirst: Bool {+ !usesCustomSources && selectedGuest?.linksKernelFirst == true+ }++ /// The ssh builder that links it, when one is named.+ private var kernelcacheBuilder: VPhoneLaunchpadKernelcacheBuilder? {+ let destination = kernelcacheBuilderDestination.trimmingCharacters(in: .whitespaces)+ guard linksKernelFirst, !destination.isEmpty else {+ return nil+ }+ return VPhoneLaunchpadKernelcacheBuilder(destination: destination, password: kernelcacheBuilderPassword)+ }++ /// Why the builder stops Create: none named where this Mac links+ /// kernel-last, or one that is not `user@host`.+ private var kernelcacheBuilderProblem: String? {+ guard linksKernelFirst else {+ return nil+ }+ if let kernelcacheBuilder {+ return VPhoneLaunchpadKernelcacheBuilder.isValid(kernelcacheBuilder.destination)+ ? nil : String(localized: "Name the macOS builder as user@host.")+ }+ return VPhoneLaunchpadKernelcacheBuilder.hostNeedsBuilder+ ? String(localized: "Name a Mac or macOS VM running macOS 15 or 26.0 to 26.3, with Remote Login on, as the macOS builder in Advanced Options: this Mac's kmutil cannot link iOS 18 kernels.")+ : nil+ }+private var effectiveName: String {name.trimmingCharacters(in: .whitespaces)}@@ -189,7 +226,7 @@ struct VPhoneLaunchpadNewMachineView: View {private var canCreate: Bool {nameProblem == nil && advancedProblem == nil && sources != nil && bundleVersion != nil- && (!rebuildsKernelcache || hasKernelcacheIPSW)+ && (!rebuildsKernelcache || hasKernelcacheIPSW) && kernelcacheBuilderProblem == nil}var body: some View {@@ -418,6 +455,15 @@ struct VPhoneLaunchpadNewMachineView: View {? "On its own cloudOS, \(own.name): the kernelcache is rebuilt, which asks for administrator access once.": "Choose an ipsw with `kernel extract --kdk` in Advanced Options to run on \(own.name).").foregroundStyle(hasKernelcacheIPSW ? Color.secondary : Color.red)+ } else if linksKernelFirst, let cloudOS = selectedPairing?.recommendedCloudOS.name {+ if !hasKernelcacheIPSW {+ Text("Choose an ipsw with `kernel extract --kdk` in Advanced Options: the release's own kernel is rebuilt with the vphone600 kexts.").foregroundStyle(.red)+ } else if let kernelcacheBuilderProblem {+ Text(kernelcacheBuilderProblem).foregroundStyle(.red)+ } else {+ Text("With \(cloudOS): the kernelcache is rebuilt and linked \(kernelcacheBuilder.map { "on \($0.destination)" } ?? "on this Mac"), and the restore image asks for administrator access once.")+ .foregroundStyle(.secondary)+ }} else if rebuildsKernelcache, let cloudOS = selectedPairing?.recommendedCloudOS.name {Text(hasKernelcacheIPSW? "With \(cloudOS): the kernelcache is rebuilt with the watch's kexts, which asks for administrator access once."@@ -609,6 +655,11 @@ struct VPhoneLaunchpadNewMachineView: View {if rebuildsKernelcache {sourceField("ipsw", $kernelcacheIPSW)}+ if linksKernelFirst {+ TextField("macOS builder", text: $kernelcacheBuilderDestination, prompt: Text("user@host"))+ SecureField("Password", text: $kernelcacheBuilderPassword, prompt: Text("None with ssh keys"))+ .disabled(kernelcacheBuilder == nil)+ }}} header: {Text("Firmware")@@ -617,6 +668,8 @@ struct VPhoneLaunchpadNewMachineView: View {? "These two files replace the device and version chosen on the basic page.": ownCloudOS != nil? "On its own cloudOS the release boots its own kernel, rebuilt with the vphone600 virtualisation kexts: the ipsw (with `kernel extract --kdk`) stages it as you, and the helper links it as root."+ : linksKernelFirst+ ? "iOS 18 boots its own release's kernel, rebuilt with the vphone600 kexts of cloudOS 26.1: the ipsw (with `kernel extract --kdk`) stages it as you. Only the kmutil of macOS 15 or 26.0 to 26.3 links it: from macOS 26.4 on, the macOS builder, a Mac or macOS VM with Remote Login on, links it over ssh as root there. The password is for ssh and sudo on it and is not saved; leave it empty with ssh keys and passwordless sudo.": rebuildsKernelcache? "A watch boots the cloudOS kernel rebuilt with its own kexts: the ipsw (with `kernel extract --kdk`) stages it as you, and the helper links it as root.": "The device and version are chosen on the basic page; cloudOS goes with them.")@@ -775,9 +828,10 @@ struct VPhoneLaunchpadNewMachineView: View {!usesCustomSources && selectedGuest?.isAppleTV == true}- /// An Apple TV or Apple Watch from the catalog: each has a preset of its own.+ /// An Apple TV, Apple Watch or iOS 18 guest from the catalog: each has a+ /// preset of its own.private var hasOwnPresetGuest: Bool {- !usesCustomSources && (selectedGuest?.isAppleTV == true || selectedGuest?.isWatch == true)+ !usesCustomSources && (selectedGuest?.isAppleTV == true || selectedGuest?.isWatch == true || linksKernelFirst)}/// Read again whenever the preset or the version changes: `inPreset`, which@@ -826,9 +880,9 @@ struct VPhoneLaunchpadNewMachineView: View {iphoneSource: iphone,cloudOSSource: cloudOS,// An iPad IPSW often covers two sizes; name the one chosen. An- // Apple TV or Apple Watch is named too, so the restore tree and- // log say which.- device: usesCustomSources ? nil : selectedGuest.flatMap { $0.isPad || $0.isAppleTV || $0.isWatch ? $0.productType : nil },+ // Apple TV, Apple Watch or iOS 18 guest is named too, so the+ // restore tree and log say which.+ device: usesCustomSources ? nil : selectedGuest.flatMap { $0.isPad || $0.isAppleTV || $0.isWatch || $0.linksKernelFirst ? $0.productType : nil },cpuCount: cpu,memoryMB: memoryMB,diskSizeGB: diskSizeGB,@@ -839,6 +893,7 @@ struct VPhoneLaunchpadNewMachineView: View {usesTemplate: usesTemplate,slimming: slimming,kernelcacheIPSW: rebuildsKernelcache ? kernelcacheIPSW : nil,+ kernelcacheBuilder: kernelcacheBuilder,)let pipeline = model.machines.create(options)model.machines.selection = [pipeline.machine]diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swiftindex 39923cec..add04f9b 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift@@ -297,6 +297,8 @@ nonisolated struct VPhoneLaunchpadPatchSelection: Hashable, Sendable {case "AppleTV14,1": tvOS4KPresetcase let type? where type.hasPrefix("AppleTV"): tvOSPresetcase let type? where type.hasPrefix("Watch"): watchOSPreset+ // The iOS 18 research board kernels boot no other preset.+ case "iPhone11,6", "iPhone11,4": minimalPresetdefault: defaultPreset}}diff --git a/VPhoneLaunchpad/VPhoneLaunchpadCLI/main.swift b/VPhoneLaunchpad/VPhoneLaunchpadCLI/main.swiftindex 2deb7307..327230f8 100644--- a/VPhoneLaunchpad/VPhoneLaunchpadCLI/main.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpadCLI/main.swift@@ -107,12 +107,19 @@ if words.isEmpty || ["help", "-h", "--help"].contains(words[0]) {exit(words.isEmpty ? 1 : 0)}-let request: VPhoneLaunchpadControlRequest+var request: VPhoneLaunchpadControlRequestdo {request = try VPhoneLaunchpadControlRequest.parse(words, foreground: &foreground)} catch {fail(error.message, detail: error.detail)}+// The ssh builder's password comes from this environment, never an argument,+// and goes only over the same-user socket.+if request.command == "vm.create", request.option("kmutil-ssh") != nil,+ let password = ProcessInfo.processInfo.environment["VPHONE_KMUTIL_SSH_PASSWORD"], !password.isEmpty+{+ request.options[VPhoneLaunchpadControlRequest.kmutilSSHPasswordOption] = password+}let fd = connectControl() ?? launchAndConnect(foreground: foreground)diff --git a/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swift b/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swiftindex 585b65cd..c634abff 100644--- a/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpadShared/VPhoneLaunchpadControl.swift@@ -77,6 +77,10 @@ nonisolated struct VPhoneLaunchpadControlRequest: Codable, Sendable {options[name]}+ /// Where `vm create --kmutil-ssh` carries the builder's password, which+ /// vphone-launchpad-cli reads from its environment: no argument holds it.+ static let kmutilSSHPasswordOption = "kmutil-ssh-password"+func flag(_ name: String) -> Bool {options[name] == "true"}@@ -177,10 +181,10 @@ nonisolated struct VPhoneLaunchpadControlCommand: Sendable {Self(name: "vm.log", arguments: ["name"], options: ["root", "lines", "kind"], flags: [],summary: "The last lines of the console log (--kind create, dfu or patch for those logs)."),Self(name: "vm.create", arguments: ["name"], options: [- "root", "bundle", "iphone-source", "cloudos-source", "device", "cpu", "memory", "disk-size", "network", "preset", "from", "ipsw",+ "root", "bundle", "iphone-source", "cloudos-source", "device", "cpu", "memory", "disk-size", "network", "preset", "from", "ipsw", "kmutil-ssh","slim", "trim", "keep-languages", "service-profile", "remove-apps", "keep-apps",], flags: ["keep-artifacts", "no-wait", "no-template", "accounts-off"], repeated: ["block", "allow"],- summary: "Create a machine through every step, as New Machine does, bound to --bundle (default: the default bundle): cloned from a template, built first when missing, or restored on its own with --no-template. --block and --allow turn one patch of --preset off or on, as New Machine's patch list and vphone-cli fw set-patches do: boot-chain ones go into the template, guest ones are applied to the clone. --slim, --trim, --keep-languages, --service-profile, --remove-apps, --keep-apps and --accounts-off shape the template, as in vphone-cli vm create. --ipsw <path> stages the kernelcache mix of a machine on its release's own cloudOS, as New Machine's ipsw field. --from <step> retries a failed creation from that step, with the options it started with."),+ summary: "Create a machine through every step, as New Machine does, bound to --bundle (default: the default bundle): cloned from a template, built first when missing, or restored on its own with --no-template. --block and --allow turn one patch of --preset off or on, as New Machine's patch list and vphone-cli fw set-patches do: boot-chain ones go into the template, guest ones are applied to the clone. --slim, --trim, --keep-languages, --service-profile, --remove-apps, --keep-apps and --accounts-off shape the template, as in vphone-cli vm create. --ipsw <path> stages the kernelcache mix of a machine on its release's own cloudOS, as New Machine's ipsw field. --kmutil-ssh <user@host> links an iOS 18 guest's kernel-first mix on that Mac over ssh, as New Machine's macOS builder field, with the password (for ssh and sudo there) from this tool's VPHONE_KMUTIL_SSH_PASSWORD. --from <step> retries a failed creation from that step, with the options it started with."),Self(name: "vm.set-bundle", arguments: ["name", "version"], options: ["root"], flags: ["update-environment"],summary: "Bind a machine to another installed version; its host programs change at the next start. --update-environment also redeploys that version's guest environment into the stopped machine. The boot chain stays as created."),Self(name: "vm.leases", arguments: [], options: [], flags: ["release"],