Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFI firmware/bootloader support #41

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: macos-11
runs-on: macos-13

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A set of utilities to help you manage VMs with `Virtualization.framework`

### Prerequisites

* macOS Big Sur (11+)
* macOS Ventura (13+)
* XCode.app installed

```
Expand Down
35 changes: 32 additions & 3 deletions vmcli/Sources/vmcli/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Virtualization

enum BootLoader: String, ExpressibleByArgument {
case linux
@available(macOS 13, *)
case efi
}

enum SizeSuffix: UInt64, ExpressibleByArgument {
Expand Down Expand Up @@ -175,13 +177,16 @@ Omit mac address for a generated address.
@Option(name: .shortAndLong, help: "Bootloader to use")
var bootloader: BootLoader = BootLoader.linux

@Option(name: .shortAndLong, help: "Kernel to use")
@Option(name: .shortAndLong, help: "EFI variable store location (EFI bootloader only)")
var efiVars: String?

@Option(name: .shortAndLong, help: "Kernel to use (Linux bootloader only)")
var kernel: String?

@Option(help: "Initrd to use")
@Option(help: "Initrd to use (Linux bootloader only)")
var initrd: String?

@Option(help: "Kernel cmdline to use")
@Option(help: "Kernel cmdline to use (Linux bootloader only)")
var cmdline: String?

@Option(help: "Escape Sequence, when using a tty")
Expand All @@ -200,6 +205,9 @@ Omit mac address for a generated address.
if kernel == nil {
throw ValidationError("Kernel not specified")
}
if efiVars != nil {
throw ValidationError("EFI variable store cannot be used with Linux bootloader")
}
let vmKernelURL = URL(fileURLWithPath: kernel!)
let vmBootLoader = VZLinuxBootLoader(kernelURL: vmKernelURL)
if initrd != nil {
Expand All @@ -209,6 +217,27 @@ Omit mac address for a generated address.
vmBootLoader.commandLine = cmdline!
}
vmCfg.bootLoader = vmBootLoader
case BootLoader.efi:
if #available(macOS 13, *) {
if efiVars == nil {
throw ValidationError("EFI variable store must be specified if using EFI bootloader")
}
if kernel != nil || initrd != nil || cmdline != nil {
throw ValidationError("Kernel, initrd and cmdline options cannot be used with EFI bootloader")
}
let efiVarStoreURL = URL(fileURLWithPath: efiVars!)
var efiVarStore: VZEFIVariableStore
if FileManager.default.fileExists(atPath: efiVars!) {
efiVarStore = VZEFIVariableStore(url: efiVarStoreURL)
} else {
efiVarStore = try VZEFIVariableStore(creatingVariableStoreAt: efiVarStoreURL)
}
let vmBootLoader = VZEFIBootLoader()
vmBootLoader.variableStore = efiVarStore
vmCfg.bootLoader = vmBootLoader
} else {
throw ValidationError("EFI bootloader is only available on macOS 13 and later versions")
}
}

// set up tty
Expand Down
Loading