mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 11:00:25 +00:00
Merge pull request #2461 from ijc/qemu-iso-and-metadata
qemu: Support ISO boot at the same time as metadata
This commit is contained in:
commit
584acd9fd8
@ -32,7 +32,7 @@ type QemuConfig struct {
|
|||||||
Kernel bool
|
Kernel bool
|
||||||
GUI bool
|
GUI bool
|
||||||
Disks Disks
|
Disks Disks
|
||||||
MetadataPath string
|
ISOImages []string
|
||||||
StatePath string
|
StatePath string
|
||||||
FWPath string
|
FWPath string
|
||||||
Arch string
|
Arch string
|
||||||
@ -217,7 +217,12 @@ func runQemu(args []string) {
|
|||||||
log.Fatalf("Could not create state directory: %v", err)
|
log.Fatalf("Could not create state directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
isoPath := ""
|
var isoPaths []string
|
||||||
|
|
||||||
|
if *isoBoot {
|
||||||
|
isoPaths = append(isoPaths, path)
|
||||||
|
}
|
||||||
|
|
||||||
if *data != "" {
|
if *data != "" {
|
||||||
var d []byte
|
var d []byte
|
||||||
if _, err := os.Stat(*data); os.IsNotExist(err) {
|
if _, err := os.Stat(*data); os.IsNotExist(err) {
|
||||||
@ -228,10 +233,11 @@ func runQemu(args []string) {
|
|||||||
log.Fatalf("Cannot read user data: %v", err)
|
log.Fatalf("Cannot read user data: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isoPath = filepath.Join(*state, "data.iso")
|
isoPath := filepath.Join(*state, "data.iso")
|
||||||
if err := WriteMetadataISO(isoPath, d); err != nil {
|
if err := WriteMetadataISO(isoPath, d); err != nil {
|
||||||
log.Fatalf("Cannot write user data ISO: %v", err)
|
log.Fatalf("Cannot write user data ISO: %v", err)
|
||||||
}
|
}
|
||||||
|
isoPaths = append(isoPaths, isoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, d := range disks {
|
for i, d := range disks {
|
||||||
@ -261,9 +267,6 @@ func runQemu(args []string) {
|
|||||||
disks = append(d, disks...)
|
disks = append(d, disks...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *isoBoot && isoPath != "" {
|
|
||||||
log.Fatalf("metadata and ISO boot currently cannot coexist")
|
|
||||||
}
|
|
||||||
if *networking == "" || *networking == "default" {
|
if *networking == "" || *networking == "default" {
|
||||||
dflt := qemuNetworkingDefault
|
dflt := qemuNetworkingDefault
|
||||||
networking = &dflt
|
networking = &dflt
|
||||||
@ -306,7 +309,7 @@ func runQemu(args []string) {
|
|||||||
Kernel: *kernelBoot,
|
Kernel: *kernelBoot,
|
||||||
GUI: *enableGUI,
|
GUI: *enableGUI,
|
||||||
Disks: disks,
|
Disks: disks,
|
||||||
MetadataPath: isoPath,
|
ISOImages: isoPaths,
|
||||||
StatePath: *state,
|
StatePath: *state,
|
||||||
FWPath: *fw,
|
FWPath: *fw,
|
||||||
Arch: *arch,
|
Arch: *arch,
|
||||||
@ -396,8 +399,8 @@ func runQemuContainer(config QemuConfig) error {
|
|||||||
}
|
}
|
||||||
addBind(config.Path)
|
addBind(config.Path)
|
||||||
|
|
||||||
if config.MetadataPath != "" {
|
for _, p := range config.ISOImages {
|
||||||
addBind(config.MetadataPath)
|
addBind(p)
|
||||||
}
|
}
|
||||||
// also try to bind mount disk paths so the command works
|
// also try to bind mount disk paths so the command works
|
||||||
for _, d := range config.Disks {
|
for _, d := range config.Disks {
|
||||||
@ -516,6 +519,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastDisk int
|
||||||
for i, d := range config.Disks {
|
for i, d := range config.Disks {
|
||||||
index := i
|
index := i
|
||||||
// hdc is CDROM in qemu
|
// hdc is CDROM in qemu
|
||||||
@ -527,13 +531,25 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
|||||||
} else {
|
} else {
|
||||||
qemuArgs = append(qemuArgs, "-drive", "file="+d.Path+",index="+strconv.Itoa(index)+",media=disk")
|
qemuArgs = append(qemuArgs, "-drive", "file="+d.Path+",index="+strconv.Itoa(index)+",media=disk")
|
||||||
}
|
}
|
||||||
|
lastDisk = index
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ISOBoot {
|
if config.ISOBoot {
|
||||||
qemuArgs = append(qemuArgs, "-cdrom", config.Path)
|
|
||||||
qemuArgs = append(qemuArgs, "-boot", "d")
|
qemuArgs = append(qemuArgs, "-boot", "d")
|
||||||
} else if config.MetadataPath != "" {
|
}
|
||||||
qemuArgs = append(qemuArgs, "-cdrom", config.MetadataPath)
|
|
||||||
|
// Ensure CDROMs start from at least hdc
|
||||||
|
if lastDisk < 2 {
|
||||||
|
lastDisk = 2
|
||||||
|
}
|
||||||
|
for i, p := range config.ISOImages {
|
||||||
|
if i == 0 {
|
||||||
|
// This is hdc/CDROM which is skipped by the disk loop above
|
||||||
|
qemuArgs = append(qemuArgs, "-cdrom", p)
|
||||||
|
} else {
|
||||||
|
index := lastDisk + i
|
||||||
|
qemuArgs = append(qemuArgs, "-drive", "file="+p+",index="+strconv.Itoa(index)+",media=cdrom")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.UEFI {
|
if config.UEFI {
|
||||||
|
Loading…
Reference in New Issue
Block a user