From a02d64a851aae1dcba10fc0532fcde37587c9211 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Sat, 29 Oct 2016 09:21:58 -0700 Subject: [PATCH] Auto-detect whether the kernel is bzImage or vmlinuz. --- vmnet/vmnet.go | 16 ++++++++-------- xhyve/xhyve.go | 33 +++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/vmnet/vmnet.go b/vmnet/vmnet.go index 814b407..9c6f485 100644 --- a/vmnet/vmnet.go +++ b/vmnet/vmnet.go @@ -16,14 +16,8 @@ const ( NET_MASK_KEY = "Shared_Net_Mask" ) -// isExist returns whether the filename is exists. -func isExist(filename string) bool { - _, err := os.Stat(filename) - return err == nil -} - func GetNetAddr() (net.IP, error) { - if !isExist(CONFIG_PLIST + ".plist") { + if !IsExist(CONFIG_PLIST + ".plist") { return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist") } @@ -39,7 +33,7 @@ func GetNetAddr() (net.IP, error) { } func getNetMask() (net.IPMask, error) { - if !isExist(CONFIG_PLIST + ".plist") { + if !IsExist(CONFIG_PLIST + ".plist") { return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist") } @@ -70,3 +64,9 @@ func GetIPNet() (*net.IPNet, error) { Mask: mask, }, nil } + +// IsExist returns whether the filename is exists. +func IsExist(filename string) bool { + _, err := os.Stat(filename) + return err == nil +} diff --git a/xhyve/xhyve.go b/xhyve/xhyve.go index 6b42a7d..57d5c3a 100644 --- a/xhyve/xhyve.go +++ b/xhyve/xhyve.go @@ -608,17 +608,15 @@ func (d *Driver) extractKernelImages() (err error) { err = hdiutil("detach", volumeRootDir) }() - vmlinuz := filepath.Join(volumeRootDir, "boot", d.Vmlinuz) - initrd := filepath.Join(volumeRootDir, "boot", d.Initrd) - - log.Debugf("Extracting %s into %s", d.Vmlinuz, d.ResolveStorePath(d.Vmlinuz)) - if err := mcnutils.CopyFile(vmlinuz, d.ResolveStorePath(d.Vmlinuz)); err != nil { - return err - } - - log.Debugf("Extracting %s into %s", d.Initrd, d.ResolveStorePath(d.Initrd)) - if err := mcnutils.CopyFile(initrd, d.ResolveStorePath(d.Initrd)); err != nil { - return err + for _, f := range []string{"vmlinux", "vmlinuz64", "vmlinuz", "bzImage", "initrd", "initrd.gz", "initrd.img"} { + p := filepath.Join(volumeRootDir, "boot", f) + dest := d.ResolveStorePath(f) + if vmnet.IsExist(p) { + log.Debugf("Extracting %s into %s", p, dest) + if err := mcnutils.CopyFile(p, dest); err != nil { + return err + } + } } return nil @@ -917,13 +915,20 @@ func (d *Driver) xhyveArgs() []string { diskImage = fmt.Sprintf("4:0,ahci-hd,%s", imgPath) } - // assume the boot2docker.iso if empty - if d.Vmlinuz == "" { + switch { + case vmnet.IsExist(d.ResolveStorePath("vmlinuz64")): d.Vmlinuz = "vmlinuz64" + case vmnet.IsExist(d.ResolveStorePath("bzImage")): + d.Vmlinuz = "bzImage" } - if d.Initrd == "" { + + switch { + case vmnet.IsExist(d.ResolveStorePath("initrd.img")): d.Initrd = "initrd.img" + case vmnet.IsExist(d.ResolveStorePath("initrd")): + d.Initrd = "initrd" } + vmlinuz := d.ResolveStorePath(d.Vmlinuz) initrd := d.ResolveStorePath(d.Initrd)