Skip to content

Commit

Permalink
Auto-detect whether the kernel is bzImage or vmlinuz.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorenc committed Oct 31, 2016
1 parent 58963b1 commit a02d64a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
16 changes: 8 additions & 8 deletions vmnet/vmnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand Down Expand Up @@ -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
}
33 changes: 19 additions & 14 deletions xhyve/xhyve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a02d64a

Please sign in to comment.