Skip to content

Commit 8cc908a

Browse files
authored
Merge pull request #144 from dlorenc/detect
Auto-detect whether the kernel is bzImage or vmlinuz.
2 parents 58963b1 + a02d64a commit 8cc908a

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

vmnet/vmnet.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@ const (
1616
NET_MASK_KEY = "Shared_Net_Mask"
1717
)
1818

19-
// isExist returns whether the filename is exists.
20-
func isExist(filename string) bool {
21-
_, err := os.Stat(filename)
22-
return err == nil
23-
}
24-
2519
func GetNetAddr() (net.IP, error) {
26-
if !isExist(CONFIG_PLIST + ".plist") {
20+
if !IsExist(CONFIG_PLIST + ".plist") {
2721
return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist")
2822
}
2923

@@ -39,7 +33,7 @@ func GetNetAddr() (net.IP, error) {
3933
}
4034

4135
func getNetMask() (net.IPMask, error) {
42-
if !isExist(CONFIG_PLIST + ".plist") {
36+
if !IsExist(CONFIG_PLIST + ".plist") {
4337
return nil, fmt.Errorf("Does not exist %s", CONFIG_PLIST+".plist")
4438
}
4539

@@ -70,3 +64,9 @@ func GetIPNet() (*net.IPNet, error) {
7064
Mask: mask,
7165
}, nil
7266
}
67+
68+
// IsExist returns whether the filename is exists.
69+
func IsExist(filename string) bool {
70+
_, err := os.Stat(filename)
71+
return err == nil
72+
}

xhyve/xhyve.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -608,17 +608,15 @@ func (d *Driver) extractKernelImages() (err error) {
608608
err = hdiutil("detach", volumeRootDir)
609609
}()
610610

611-
vmlinuz := filepath.Join(volumeRootDir, "boot", d.Vmlinuz)
612-
initrd := filepath.Join(volumeRootDir, "boot", d.Initrd)
613-
614-
log.Debugf("Extracting %s into %s", d.Vmlinuz, d.ResolveStorePath(d.Vmlinuz))
615-
if err := mcnutils.CopyFile(vmlinuz, d.ResolveStorePath(d.Vmlinuz)); err != nil {
616-
return err
617-
}
618-
619-
log.Debugf("Extracting %s into %s", d.Initrd, d.ResolveStorePath(d.Initrd))
620-
if err := mcnutils.CopyFile(initrd, d.ResolveStorePath(d.Initrd)); err != nil {
621-
return err
611+
for _, f := range []string{"vmlinux", "vmlinuz64", "vmlinuz", "bzImage", "initrd", "initrd.gz", "initrd.img"} {
612+
p := filepath.Join(volumeRootDir, "boot", f)
613+
dest := d.ResolveStorePath(f)
614+
if vmnet.IsExist(p) {
615+
log.Debugf("Extracting %s into %s", p, dest)
616+
if err := mcnutils.CopyFile(p, dest); err != nil {
617+
return err
618+
}
619+
}
622620
}
623621

624622
return nil
@@ -917,13 +915,20 @@ func (d *Driver) xhyveArgs() []string {
917915
diskImage = fmt.Sprintf("4:0,ahci-hd,%s", imgPath)
918916
}
919917

920-
// assume the boot2docker.iso if empty
921-
if d.Vmlinuz == "" {
918+
switch {
919+
case vmnet.IsExist(d.ResolveStorePath("vmlinuz64")):
922920
d.Vmlinuz = "vmlinuz64"
921+
case vmnet.IsExist(d.ResolveStorePath("bzImage")):
922+
d.Vmlinuz = "bzImage"
923923
}
924-
if d.Initrd == "" {
924+
925+
switch {
926+
case vmnet.IsExist(d.ResolveStorePath("initrd.img")):
925927
d.Initrd = "initrd.img"
928+
case vmnet.IsExist(d.ResolveStorePath("initrd")):
929+
d.Initrd = "initrd"
926930
}
931+
927932
vmlinuz := d.ResolveStorePath(d.Vmlinuz)
928933
initrd := d.ResolveStorePath(d.Initrd)
929934

0 commit comments

Comments
 (0)