Skip to content

Commit dc71617

Browse files
committed
xhyve: support modifiable vmlinuz and initrd filename for custom ISO
- 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>
1 parent 66e463f commit dc71617

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

xhyve/xhyve.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,25 @@ const (
5454
type Driver struct {
5555
*drivers.BaseDriver
5656
*b2d.B2dUtils
57+
5758
Boot2DockerURL string
58-
BootCmd string
59-
CPU int
6059
CaCertPath string
60+
PrivateKeyPath string
61+
62+
CPU int
63+
Memory int
6164
DiskSize int64
65+
DiskNumber int
6266
MacAddr string
63-
Memory int
64-
PrivateKeyPath string
6567
UUID string
66-
NFSShare bool
67-
DiskNumber int
68+
Qcow2 bool
6869
Virtio9p bool
6970
Virtio9pFolder string
70-
Qcow2 bool
71+
NFSShare bool
72+
73+
BootCmd string
74+
Initrd string
75+
Vmlinuz string
7176
}
7277

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

217+
// docker-machine used boot2docker.iso by default
218+
d.Vmlinuz = "vmlinuz64"
219+
d.Initrd = "initrd.img"
220+
212221
return nil
213222
}
214223

@@ -367,7 +376,7 @@ func (d *Driver) Create() error {
367376
return err
368377
}
369378

370-
log.Infof("Extracting vmlinuz64 and initrd.img from %s...", isoFilename)
379+
log.Infof("Extracting kernel and initrd from %s...", isoFilename)
371380
if err := d.extractKernelImages(); err != nil {
372381
return err
373382
}
@@ -588,21 +597,21 @@ func (d *Driver) publicSSHKeyPath() string {
588597
func (d *Driver) extractKernelImages() error {
589598
log.Debugf("Mounting %s", isoFilename)
590599

591-
err := hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", d.ResolveStorePath("b2d-image"))
600+
err := hdiutil("attach", d.ResolveStorePath(isoFilename), "-mountpoint", d.ResolveStorePath(isoMountPath))
592601
if err != nil {
593602
return err
594603
}
595604

596605
volumeRootDir := d.ResolveStorePath(isoMountPath)
597-
vmlinuz64 := volumeRootDir + "/boot/vmlinuz64"
598-
initrd := volumeRootDir + "/boot/initrd.img"
606+
vmlinuz := filepath.Join(volumeRootDir, "boot", d.Vmlinuz)
607+
initrd := filepath.Join(volumeRootDir, "boot", d.Initrd)
599608

600-
log.Debugf("Extracting vmlinuz64 into %s", d.ResolveStorePath("."))
601-
if err := mcnutils.CopyFile(vmlinuz64, d.ResolveStorePath("vmlinuz64")); err != nil {
609+
log.Debugf("Extracting kernel into %s", d.ResolveStorePath("."))
610+
if err := mcnutils.CopyFile(vmlinuz, d.ResolveStorePath(d.Vmlinuz)); err != nil {
602611
return err
603612
}
604-
log.Debugf("Extracting initrd.img into %s", d.ResolveStorePath("."))
605-
if err := mcnutils.CopyFile(initrd, d.ResolveStorePath("initrd.img")); err != nil {
613+
log.Debugf("Extracting initrd into %s", d.ResolveStorePath("."))
614+
if err := mcnutils.CopyFile(initrd, d.ResolveStorePath(d.Initrd)); err != nil {
606615
return err
607616
}
608617
log.Debugf("Unmounting %s", isoFilename)
@@ -896,6 +905,7 @@ func trimMacAddress(rawUUID string) string {
896905

897906
func (d *Driver) xhyveArgs() []string {
898907
iso := d.ResolveStorePath(isoFilename)
908+
899909
var diskImage string
900910
if d.Qcow2 {
901911
imgPath := fmt.Sprintf("file://%s", filepath.Join(d.ResolveStorePath("."), d.MachineName+".qcow2"))
@@ -905,8 +915,15 @@ func (d *Driver) xhyveArgs() []string {
905915
diskImage = fmt.Sprintf("4:0,ahci-hd,%s", imgPath)
906916
}
907917

908-
vmlinuz := d.ResolveStorePath("vmlinuz64")
909-
initrd := d.ResolveStorePath("initrd.img")
918+
// assume the boot2docker.iso if empty
919+
if d.Vmlinuz == "" {
920+
d.Vmlinuz = "vmlinuz64"
921+
}
922+
if d.Initrd == "" {
923+
d.Initrd = "initrd.img"
924+
}
925+
vmlinuz := d.ResolveStorePath(d.Vmlinuz)
926+
initrd := d.ResolveStorePath(d.Initrd)
910927

911928
return []string{
912929
"xhyve",

0 commit comments

Comments
 (0)