Skip to content

Commit

Permalink
vm(apple): support booting into recoveryOS on Ventura
Browse files Browse the repository at this point in the history
Resolves #3526
  • Loading branch information
osy committed Aug 3, 2022
1 parent 683125c commit cb4b8a9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Configuration/UTMAppleConfigurationBoot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct UTMAppleConfigurationBoot: Codable {
var linuxCommandLine: String?
var linuxInitialRamdiskURL: URL?

/// Next startup should be in recovery. Not saved.
var startUpFromMacOSRecovery: Bool = false

private enum CodingKeys: String, CodingKey {
case operatingSystem = "OperatingSystem"
case linuxKernelPath = "LinuxKernelPath"
Expand Down
17 changes: 16 additions & 1 deletion Managers/UTMAppleVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,23 @@ import Virtualization

private func _vmStart() async throws {
try createAppleVM()
try await withCheckedThrowingContinuation { continuation in
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) -> Void in
vmQueue.async {
#if os(macOS) && arch(arm64)
let boot = self.appleConfig.system.boot
if #available(macOS 13, *), boot.operatingSystem == .macOS {
let options = VZMacOSVirtualMachineStartOptions()
options.startUpFromMacOSRecovery = boot.startUpFromMacOSRecovery
self.apple.start(options: options) { result in
if let result = result {
continuation.resume(with: .failure(result))
} else {
continuation.resume()
}
}
return
}
#endif
self.apple.start { result in
continuation.resume(with: result)
}
Expand Down
11 changes: 11 additions & 0 deletions Platform/Shared/VMContextMenuModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ struct VMContextMenuModifier: ViewModifier {
Label("Run", systemImage: "play.fill")
}.help("Run the VM in the foreground.")

#if os(macOS) && arch(arm64)
if #available(macOS 13, *), let appleConfig = vm.config.appleConfig, appleConfig.system.boot.operatingSystem == .macOS {
Button {
appleConfig.system.boot.startUpFromMacOSRecovery = true
data.run(vm: vm)
} label: {
Label("Run Recovery", systemImage: "play.fill")
}.help("Boot into recovery mode.")
}
#endif

Button {
vm.isRunningAsSnapshot = true
data.run(vm: vm)
Expand Down

0 comments on commit cb4b8a9

Please sign in to comment.