Skip to content

Commit

Permalink
vm(qemu): add option to reset UEFI variables
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Jul 14, 2023
1 parent 8737ac4 commit f8d5203
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Configuration/UTMQemuConfigurationQEMU.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ struct UTMQemuConfigurationQEMU: Codable {
/// Set to true to request guest tools install. Not saved.
var isGuestToolsInstallRequested: Bool = false

/// Set to true to request UEFI variable reset. Not saved.
var isUefiVariableResetRequested: Bool = false

enum CodingKeys: String, CodingKey {
case hasDebugLog = "DebugLog"
case hasUefiBoot = "UEFIBoot"
Expand Down
5 changes: 5 additions & 0 deletions Platform/Shared/VMConfigQEMUView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ struct VMConfigQEMUView: View {
.disabled(!supportsPs2)
.help("Instantiate PS/2 controller even when USB input is supported. Required for older Windows.")
}
DetailedSection("Maintenance", description: "Options here only apply on next boot and are not saved.") {
Toggle("Reset UEFI Variables", isOn: $config.isUefiVariableResetRequested)
.help("You can use this if your boot options are corrupted or if you wish to re-enroll in the default keys for secure boot.")
.disabled(!config.hasUefiBoot)
}
DetailedSection("QEMU Machine Properties", description: "This is appended to the -machine argument.") {
DefaultTextField("", text: $config.machinePropertyOverride.bound, prompt: "Default")
}
Expand Down
16 changes: 11 additions & 5 deletions Services/UTMQemuVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,17 @@ extension UTMQemuVirtualMachine {
guard let efiVarsURL = config.qemu.efiVarsURL else {
return
}
guard config.isLegacy else {
return
var doesVarsExist = FileManager.default.fileExists(atPath: efiVarsURL.path)
if config.qemu.isUefiVariableResetRequested {
if doesVarsExist {
try FileManager.default.removeItem(at: efiVarsURL)
doesVarsExist = false
}
config.qemu.isUefiVariableResetRequested = false
}
if !doesVarsExist {
_ = try await config.qemu.saveData(to: efiVarsURL.deletingLastPathComponent(), for: config.system)
}
_ = try await config.qemu.saveData(to: efiVarsURL.deletingLastPathComponent(), for: config.system)
}

private func _start(options: UTMVirtualMachineStartOptions) async throws {
Expand Down Expand Up @@ -285,8 +292,7 @@ extension UTMQemuVirtualMachine {
try ioService.start()
try Task.checkCancellation()

// create EFI variables for legacy config
// this is ugly code and should be removed when legacy config support is removed
// create EFI variables for legacy config as well as handle UEFI resets
try await qemuEnsureEfiVarsAvailable()
try Task.checkCancellation()

Expand Down

0 comments on commit f8d5203

Please sign in to comment.