mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 18:11:35 +00:00
Robustify ISO/kernel detection on hyperkit
Much easier to follow and more correct; also ignores directories. fix #2385 Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
bbf8741002
commit
34dc65561b
@ -67,18 +67,33 @@ func runHyperKit(args []string) {
|
|||||||
path := remArgs[0]
|
path := remArgs[0]
|
||||||
prefix := path
|
prefix := path
|
||||||
|
|
||||||
_, err := os.Stat(path)
|
info, err := os.Stat(path)
|
||||||
stat := err == nil
|
stat := err == nil
|
||||||
|
|
||||||
|
/// ignore a directory
|
||||||
|
if stat && info.Mode().IsDir() {
|
||||||
|
stat = false
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = os.Stat(path + "-kernel")
|
||||||
|
statKernel := err == nil
|
||||||
|
|
||||||
var isoPaths []string
|
var isoPaths []string
|
||||||
|
|
||||||
// if the path does not exist, must be trying to do a kernel boot
|
// try to autodetect boot type if not specified
|
||||||
if !stat {
|
// if the path does not exist, and the kernel does, must be trying to do a kernel boot
|
||||||
_, err = os.Stat(path + "-kernel")
|
// if the path does exist and ends in ISO, must be trying ISO boot
|
||||||
statKernel := err == nil
|
if !stat && statKernel && !*isoBoot {
|
||||||
if statKernel {
|
*kernelBoot = true
|
||||||
*kernelBoot = true
|
} else if stat && strings.HasSuffix(path, ".iso") && !*kernelBoot {
|
||||||
} else {
|
*isoBoot = true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case *kernelBoot && *isoBoot:
|
||||||
|
log.Fatalf("Cannot specify both kernel and ISO boot together")
|
||||||
|
case *kernelBoot:
|
||||||
|
if !statKernel {
|
||||||
log.Fatalf("Cannot find kernel file (%s): %v", path+"-kernel", err)
|
log.Fatalf("Cannot find kernel file (%s): %v", path+"-kernel", err)
|
||||||
}
|
}
|
||||||
_, err = os.Stat(path + "-initrd.img")
|
_, err = os.Stat(path + "-initrd.img")
|
||||||
@ -86,19 +101,15 @@ func runHyperKit(args []string) {
|
|||||||
if !statInitrd {
|
if !statInitrd {
|
||||||
log.Fatalf("Cannot find initrd file (%s): %v", path+"-initrd.img", err)
|
log.Fatalf("Cannot find initrd file (%s): %v", path+"-initrd.img", err)
|
||||||
}
|
}
|
||||||
} else {
|
case *isoBoot:
|
||||||
// if path ends in .iso they meant an ISO
|
if !stat {
|
||||||
if strings.HasSuffix(path, ".iso") {
|
log.Fatalf("Cannot find ISO to boot")
|
||||||
*isoBoot = true
|
}
|
||||||
prefix = strings.TrimSuffix(path, ".iso")
|
prefix = strings.TrimSuffix(path, ".iso")
|
||||||
// hyperkit only supports UEFI ISO boot at present
|
// hyperkit only supports UEFI ISO boot at present
|
||||||
if !*uefiBoot {
|
if !*uefiBoot {
|
||||||
log.Fatalf("Hyperkit requires --uefi to be set to boot an ISO")
|
log.Fatalf("Hyperkit requires --uefi to be set to boot an ISO")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if *isoBoot {
|
|
||||||
isoPaths = append(isoPaths, path)
|
isoPaths = append(isoPaths, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user