Skip to content

Commit

Permalink
xhyve: support any filename of vmlinuz and initrd for custom ISO
Browse files Browse the repository at this point in the history
- Support any filename of kernel executable and initrd image,
  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 8, 2016
1 parent d090929 commit efc4a99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ OCAML_LDLIBS := -L $(OCAML_WHERE) \
-lasmrun -lbigarray -lunix
CGO_CFLAGS += -DHAVE_OCAML=1 -DHAVE_OCAML_QCOW=1 -DHAVE_OCAML=1 -I$(OCAML_WHERE)
CGO_LDFLAGS += $(OCAML_LDLIBS)
bin/docker-machine-driver-xhyve: vendor/github.com/zchee/libhyperkit/mirage_block_ocaml.syso
bin/docker-machine-driver-xhyve: vendor/github.com/zchee/libhyperkit/mirage_block_ocaml.o
endif
endif

Expand Down Expand Up @@ -174,7 +174,7 @@ default: build

build: bin/docker-machine-driver-xhyve

vendor/github.com/zchee/libhyperkit/mirage_block_ocaml.syso:
vendor/github.com/zchee/libhyperkit/mirage_block_ocaml.o:
$(VERBOSE) $(GO_CMD) generate $(GO_BUILD_FLAG) $(GO_VERBOSE) ./vendor/github.com/zchee/libhyperkit

bin/docker-machine-driver-xhyve:
Expand Down
43 changes: 26 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,10 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Virtio9p = flags.Bool("xhyve-virtio-9p")
d.Virtio9pFolder = "/Users"

// assume the boot2docker.iso
d.Vmlinuz = "vmlinuz64"
d.Initrd = "initrd.img"

return nil
}

Expand Down Expand Up @@ -367,7 +376,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 +597,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 @@ -905,8 +914,8 @@ func (d *Driver) xhyveArgs() []string {
diskImage = fmt.Sprintf("4:0,ahci-hd,%s", imgPath)
}

vmlinuz := d.ResolveStorePath("vmlinuz64")
initrd := d.ResolveStorePath("initrd.img")
vmlinuz := d.ResolveStorePath(d.Vmlinuz)
initrd := d.ResolveStorePath(d.Initrd)

return []string{
"xhyve",
Expand Down

0 comments on commit efc4a99

Please sign in to comment.