Skip to content

Commit 261fa05

Browse files
authored
Merge pull request #152 from praveenkumar/fix_150
Fix #150 Extract kernel options from the syslinux.conf file if exist
2 parents 1b710f4 + e51c8fc commit 261fa05

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,6 @@ _build/
9191
# oasis generated files
9292
setup.data
9393
setup.log
94+
95+
# Intellij geneatered directory
96+
.idea

xhyve/xhyve.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package xhyve
33
import (
44
"archive/tar"
55
"bytes"
6+
"bufio"
67
"errors"
78
"fmt"
89
"io"
@@ -37,7 +38,7 @@ const (
3738
defaultBootKernel = ""
3839
defaultBootInitrd = ""
3940
defaultBoot2DockerURL = ""
40-
defaultBootCmd = "loglevel=3 user=docker console=ttyS0 console=tty0 noembed nomodeset norestore waitusb=10 base host=boot2docker"
41+
defaultBootCmd = ""
4142
defaultCPU = 1
4243
defaultCaCertPath = ""
4344
defaultDiskSize = 20000
@@ -84,6 +85,7 @@ var (
8485
ErrMachineNotExist = errors.New("machine does not exist")
8586
diskRegexp = regexp.MustCompile("^/dev/disk([0-9]+)")
8687
kernelRegexp = regexp.MustCompile(`(vmlinu[xz]|bzImage)[\d]*`)
88+
kernelOptionRegexp = regexp.MustCompile(`(\t|\s{2})append`)
8789
)
8890

8991
// NewDriver creates a new VirtualBox driver with default settings.
@@ -610,6 +612,46 @@ func (d *Driver) publicSSHKeyPath() string {
610612
return d.GetSSHKeyPath() + ".pub"
611613
}
612614

615+
func readLine(path string) string {
616+
line := ""
617+
inFile, err := os.Open(path)
618+
if err != nil {
619+
log.Debugf("Not able to open %s", path)
620+
}
621+
defer inFile.Close()
622+
scanner := bufio.NewScanner(inFile)
623+
scanner.Split(bufio.ScanLines)
624+
for scanner.Scan() {
625+
line = scanner.Text()
626+
if kernelOptionRegexp.MatchString(line) {
627+
break
628+
}
629+
}
630+
return line
631+
}
632+
633+
func (d *Driver) extractKernelOptions() error {
634+
log.Debugf("Extracting Kernel Options...")
635+
volumeRootDir := d.ResolveStorePath(isoMountPath)
636+
if d.BootCmd == "" {
637+
err := filepath.Walk(volumeRootDir, func(path string, f os.FileInfo, err error) error {
638+
if strings.Contains(path, "isolinux.cfg") {
639+
d.BootCmd = readLine(path)
640+
}
641+
return nil
642+
})
643+
if err != nil {
644+
return err
645+
}
646+
if d.BootCmd == "" {
647+
err = errors.New("Not able to parse isolinux.cfg, Please use --xhyve-boot-cmd option")
648+
return err
649+
}
650+
}
651+
log.Debugf("Extracted Options %s", d.BootCmd)
652+
return nil
653+
}
654+
613655
func (d *Driver) extractKernelImages() error {
614656
log.Debugf("Mounting %s", isoFilename)
615657

@@ -619,6 +661,10 @@ func (d *Driver) extractKernelImages() error {
619661
return err
620662
}
621663

664+
if err := d.extractKernelOptions(); err != nil {
665+
return err
666+
}
667+
622668
defer func() error {
623669
log.Debugf("Unmounting %s", isoFilename)
624670
return hdiutil("detach", volumeRootDir)

0 commit comments

Comments
 (0)