Skip to content

Commit

Permalink
wizard: skip disk creation if linux rootfs is used
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Jan 13, 2022
1 parent c9c4f6e commit ceb6f91
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Platform/Shared/VMWizardState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class VMWizardState: ObservableObject {
if !isSkipBootImage, let bootImageURL = bootImageURL {
config.diskImages.append(DiskImage(importImage: bootImageURL, isReadOnly: true, isExternal: true))
}
var isSkipDiskCreate = false
switch operatingSystem {
case .Other:
break
Expand All @@ -311,16 +312,18 @@ class VMWizardState: ObservableObject {
config.bootLoader = bootloader
if let linuxRootImageURL = linuxRootImageURL {
config.diskImages.append(DiskImage(importImage: linuxRootImageURL))
isSkipDiskCreate = true
}
}
#endif
case .Windows:
config.icon = "windows"
if let windowsBootVhdx = windowsBootVhdx {
config.diskImages.append(DiskImage(importImage: windowsBootVhdx, isReadOnly: false, isExternal: false))
isSkipDiskCreate = true
}
}
if windowsBootVhdx == nil {
if !isSkipDiskCreate {
config.diskImages.append(DiskImage(newSize: storageSizeGib * bytesInGib / bytesInMib))
}
if #available(macOS 12, *), let sharingDirectoryURL = sharingDirectoryURL {
Expand Down Expand Up @@ -407,7 +410,7 @@ class VMWizardState: ObservableObject {
config.newDrive("initrd", path: linuxInitialRamdiskURL.lastPathComponent, type: .initrd, interface: "")
}
if let linuxRootImageURL = linuxRootImageURL {
config.newDrive("root", path: linuxRootImageURL.lastPathComponent, type: .disk, interface: UTMQemuConfiguration.defaultDriveInterface(forTarget: systemTarget, architecture: systemArchitecture, type: .disk))
config.newDrive("root", path: destinationFilename(forExisting: linuxRootImageURL), type: .disk, interface: mainDriveInterface)
}
if linuxBootArguments.count > 0 {
config.newArgument("-append")
Expand All @@ -417,7 +420,7 @@ class VMWizardState: ObservableObject {
case .Windows:
config.icon = "windows"
if let windowsBootVhdx = windowsBootVhdx {
config.newDrive("drive0", path: destinationFilename(forVhdx: windowsBootVhdx), type: .disk, interface: mainDriveInterface)
config.newDrive("drive0", path: destinationFilename(forExisting: windowsBootVhdx), type: .disk, interface: mainDriveInterface)
generateRemovableDrive() // order matters here
}
}
Expand Down Expand Up @@ -463,21 +466,22 @@ class VMWizardState: ObservableObject {
try vm.changeMedium(for: drive, url: bootImageURL)
}
let dataUrl = vm.qemuConfig.imagesPath
var existingImage: URL? = nil
if operatingSystem == .Linux && useLinuxKernel {
try copyItem(from: linuxKernelURL!, to: dataUrl)
if let linuxInitialRamdiskURL = linuxInitialRamdiskURL {
try copyItem(from: linuxInitialRamdiskURL, to: dataUrl)
}
if let linuxRootImageURL = linuxRootImageURL {
try copyItem(from: linuxRootImageURL, to: dataUrl)
}
existingImage = linuxRootImageURL
} else if operatingSystem == .Windows {
existingImage = windowsBootVhdx
}
if let windowsBootVhdx = windowsBootVhdx {
if let existingImage = existingImage {
#if os(macOS)
let destQcow2 = dataUrl.appendingPathComponent(destinationFilename(forVhdx: windowsBootVhdx))
try UTMQemuImage.convert(from: windowsBootVhdx, toQcow2: destQcow2)
let destQcow2 = dataUrl.appendingPathComponent(destinationFilename(forExisting: existingImage))
try UTMQemuImage.convert(from: existingImage, toQcow2: destQcow2)
#else
try copyItem(from: windowsBootVhdx, to: dataUrl)
try copyItem(from: existingImage, to: dataUrl)
#endif
} else {
let dstPath = dataUrl.appendingPathComponent("data.qcow2")
Expand All @@ -487,7 +491,7 @@ class VMWizardState: ObservableObject {
}
}

private func destinationFilename(forVhdx url: URL) -> String {
private func destinationFilename(forExisting url: URL) -> String {
#if os(macOS)
var destQcow2 = url
destQcow2.deletePathExtension()
Expand Down

0 comments on commit ceb6f91

Please sign in to comment.