Skip to content

Commit

Permalink
wizard(apple): support ISO boot + rootfs on Linux
Browse files Browse the repository at this point in the history
Resolves #3472
  • Loading branch information
osy committed Jan 13, 2022
1 parent 8a0711b commit c9c4f6e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 56 deletions.
129 changes: 75 additions & 54 deletions Platform/Shared/VMWizardOSLinuxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,57 +43,81 @@ struct VMWizardOSLinuxView: View {
.help("If set, boot directly from a raw kernel image and initrd. Otherwise, boot from a supported ISO.")
.disabled(wizardState.useAppleVirtualization)
if wizardState.useLinuxKernel {
Text("Linux kernel (required):")
.padding(.top)
Text(wizardState.linuxKernelURL?.lastPathComponent ?? " ")
.font(.caption)
Button {
selectImage = .kernel
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}.disabled(wizardState.isBusy)
.buttonStyle(BrowseButtonStyle())

Text("Linux initial ramdisk:")
.padding(.top)
Text(wizardState.linuxInitialRamdiskURL?.lastPathComponent ?? " ")
.font(.caption)
HStack {
Button {
selectImage = .initialRamdisk
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}
Button {
wizardState.linuxInitialRamdiskURL = nil
} label: {
Text("Clear")
}
}.disabled(wizardState.isBusy)
.buttonStyle(BrowseButtonStyle())

Text("Linux Root FS Image:")
.padding(.top)
Text(wizardState.linuxRootImageURL?.lastPathComponent ?? " ")
.font(.caption)
HStack {
Button {
selectImage = .rootImage
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}
Button {
wizardState.linuxRootImageURL = nil
} label: {
Text("Clear")
}
}.disabled(wizardState.isBusy)
.buttonStyle(BrowseButtonStyle())

TextField("Boot Arguments", text: $wizardState.linuxBootArguments)
ScrollView {
Group {
Text("Linux kernel (required):")
.padding(.top)
Text(wizardState.linuxKernelURL?.lastPathComponent ?? " ")
.font(.caption)
Button {
selectImage = .kernel
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}

Text("Linux initial ramdisk (optional):")
.padding(.top)
Text(wizardState.linuxInitialRamdiskURL?.lastPathComponent ?? " ")
.font(.caption)
HStack {
Button {
selectImage = .initialRamdisk
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}
Button {
wizardState.linuxInitialRamdiskURL = nil
} label: {
Text("Clear")
}
}
}.disabled(wizardState.isBusy)
.buttonStyle(BrowseButtonStyle())

Group{
Text("Linux Root FS Image (optional):")
.padding(.top)
Text(wizardState.linuxRootImageURL?.lastPathComponent ?? " ")
.font(.caption)
HStack {
Button {
selectImage = .rootImage
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}
Button {
wizardState.linuxRootImageURL = nil
} label: {
Text("Clear")
}
}

Text("Boot ISO Image (optional):")
.padding(.top)
Text(wizardState.bootImageURL?.lastPathComponent ?? " ")
.font(.caption)
HStack {
Button {
selectImage = .bootImage
isFileImporterPresented.toggle()
} label: {
Text("Browse")
}
Button {
wizardState.bootImageURL = nil
wizardState.isSkipBootImage = true
} label: {
Text("Clear")
}
}
}.disabled(wizardState.isBusy)
.buttonStyle(BrowseButtonStyle())

TextField("Boot Arguments", text: $wizardState.linuxBootArguments)
}
} else {
#if arch(arm64)
Link("Download Ubuntu Server for ARM", destination: URL(string: "https://ubuntu.com/download/server/arm")!)
Expand Down Expand Up @@ -128,16 +152,13 @@ struct VMWizardOSLinuxView: View {
switch selectImage {
case .kernel:
wizardState.linuxKernelURL = url
wizardState.isSkipBootImage = true
wizardState.bootImageURL = nil
case .initialRamdisk:
wizardState.linuxInitialRamdiskURL = url
case .rootImage:
wizardState.linuxRootImageURL = url
case .bootImage:
wizardState.bootImageURL = url
wizardState.isSkipBootImage = false
wizardState.linuxKernelURL = nil
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions Platform/Shared/VMWizardState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class VMWizardState: ObservableObject {
@Published var useLinuxKernel: Bool = false {
didSet {
isSkipBootImage = useLinuxKernel
bootImageURL = nil
}
}
@Published var linuxKernelURL: URL?
Expand Down Expand Up @@ -286,7 +287,7 @@ class VMWizardState: ObservableObject {
config.memorySize = systemMemory
config.cpuCount = systemCpuCount
if !isSkipBootImage, let bootImageURL = bootImageURL {
config.diskImages.append(DiskImage(importImage: bootImageURL, isReadOnly: false, isExternal: true))
config.diskImages.append(DiskImage(importImage: bootImageURL, isReadOnly: true, isExternal: true))
}
switch operatingSystem {
case .Other:
Expand Down Expand Up @@ -316,7 +317,7 @@ class VMWizardState: ObservableObject {
case .Windows:
config.icon = "windows"
if let windowsBootVhdx = windowsBootVhdx {
config.diskImages.append(DiskImage(importImage: windowsBootVhdx, isReadOnly: false, isExternal: true))
config.diskImages.append(DiskImage(importImage: windowsBootVhdx, isReadOnly: false, isExternal: false))
}
}
if windowsBootVhdx == nil {
Expand Down

0 comments on commit c9c4f6e

Please sign in to comment.