Skip to content

Commit

Permalink
xhyve: support modifiable vmlinuz and initrd filename for custom ISO
Browse files Browse the repository at this point in the history
- Support modifiable kernel executable and initrd image filename,
  because of different filename by distro, tools. such as buildroot

Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Oct 9, 2016
1 parent 5014eb8 commit d0a465c
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions xhyve/xhyve.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,25 @@ const (
type Driver struct {
*drivers.BaseDriver
*b2d.B2dUtils

Boot2DockerURL string
BootCmd string
CPU int
CaCertPath string
PrivateKeyPath string

CPU int
Memory int
DiskSize int64
DiskNumber int
MacAddr string
Memory int
PrivateKeyPath string
UUID string
NFSShare bool
DiskNumber int
Qcow2 bool
Virtio9p bool
Virtio9pFolder string
Qcow2 bool
NFSShare bool

BootCmd string
Initrd string
Vmlinuz string
}

var (
Expand Down Expand Up @@ -209,6 +214,9 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Virtio9p = flags.Bool("xhyve-virtio-9p")
d.Virtio9pFolder = "/Users"

d.Vmlinuz = "vmlinuz64"
d.Initrd = "initrd.img"

return nil
}

Expand Down Expand Up @@ -367,7 +375,7 @@ func (d *Driver) Create() error {
return err
}

log.Infof("Extracting vmlinuz64 and initrd.img from %s...", isoFilename)
log.Infof("Extracting kernel and initrd from %s...", isoFilename)
if err := d.extractKernelImages(); err != nil {
return err
}
Expand Down Expand Up @@ -588,21 +596,21 @@ func (d *Driver) publicSSHKeyPath() string {
func (d *Driver) extractKernelImages() error {
log.Debugf("Mounting %s", isoFilename)

err := hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", d.ResolveStorePath("b2d-image"))
err := hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", d.ResolveStorePath(isoMountPath))
if err != nil {
return err
}

volumeRootDir := d.ResolveStorePath(isoMountPath)
vmlinuz64 := volumeRootDir + "/boot/vmlinuz64"
initrd := volumeRootDir + "/boot/initrd.img"
vmlinuz := filepath.Join(volumeRootDir, "boot", d.Vmlinuz)
initrd := filepath.Join(volumeRootDir, "boot", d.Initrd)

log.Debugf("Extracting vmlinuz64 into %s", d.ResolveStorePath("."))
if err := mcnutils.CopyFile(vmlinuz64, d.ResolveStorePath("vmlinuz64")); err != nil {
log.Debugf("Extracting kernel into %s", d.ResolveStorePath("."))
if err := mcnutils.CopyFile(vmlinuz, d.ResolveStorePath(d.Vmlinuz)); err != nil {
return err
}
log.Debugf("Extracting initrd.img into %s", d.ResolveStorePath("."))
if err := mcnutils.CopyFile(initrd, d.ResolveStorePath("initrd.img")); err != nil {
log.Debugf("Extracting initrd into %s", d.ResolveStorePath("."))
if err := mcnutils.CopyFile(initrd, d.ResolveStorePath(d.Initrd)); err != nil {
return err
}
log.Debugf("Unmounting %s", isoFilename)
Expand Down Expand Up @@ -896,6 +904,7 @@ func trimMacAddress(rawUUID string) string {

func (d *Driver) xhyveArgs() []string {
iso := d.ResolveStorePath(isoFilename)

var diskImage string
if d.Qcow2 {
imgPath := fmt.Sprintf("file://%s", filepath.Join(d.ResolveStorePath("."), d.MachineName+".qcow2"))
Expand All @@ -905,8 +914,15 @@ func (d *Driver) xhyveArgs() []string {
diskImage = fmt.Sprintf("4:0,ahci-hd,%s", imgPath)
}

vmlinuz := d.ResolveStorePath("vmlinuz64")
initrd := d.ResolveStorePath("initrd.img")
// assume the boot2docker.iso if empty
if d.Vmlinuz == "" {
d.Vmlinuz = "vmlinuz64"
}
if d.Initrd == "" {
d.Initrd = "initrd.img"
}
vmlinuz := d.ResolveStorePath(d.Vmlinuz)
initrd := d.ResolveStorePath(d.Initrd)

return []string{
"xhyve",
Expand Down

0 comments on commit d0a465c

Please sign in to comment.