Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.

Commit 1dfab34

Browse files
committed
Add vmdk diskman; first successful Fusion boot
1 parent 233e407 commit 1dfab34

3 files changed

Lines changed: 43 additions & 26 deletions

File tree

vmware/machine.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import (
44
"fmt"
55
"os"
66
"path/filepath"
7-
"strings"
87
"text/template"
98

109
"github.com/boot2docker/boot2docker-cli/driver"
1110
"github.com/ogier/pflag"
1211
)
1312

1413
var (
15-
verbose bool // Verbose mode (Local copy of B2D.Verbose).
14+
verbose bool // Verbose mode.
1615
cfg DriverCfg
1716
)
1817

1918
type DriverCfg struct {
20-
VMRUN string // Path to VBoxManage utility.
21-
VMDK string // base VMDK to use as persistent disk.
19+
VMRUN string // Path to vmrun utility.
20+
VDISKMAN string // Path to vdiskmanager utility.
2221
}
2322

2423
func init() {
@@ -46,7 +45,10 @@ func InitFunc(mc *driver.MachineConfig) (driver.Machine, error) {
4645
// Add cmdline params for this driver
4746
func ConfigFlags(mc *driver.MachineConfig, flags *pflag.FlagSet) error {
4847
cfg.VMRUN = "/Applications/VMware Fusion.app/Contents/Library/vmrun"
49-
flags.StringVar(&cfg.VMRUN, "vmrun", cfg.VMRUN, "path to vmrun management utility.")
48+
flags.StringVar(&cfg.VMRUN, "vmrun", cfg.VMRUN, "path to vmrun utility.")
49+
50+
cfg.VDISKMAN = "/Applications/VMware Fusion.app/Contents/Library/vmware-vdiskmanager"
51+
flags.StringVar(&cfg.VDISKMAN, "vmdiskman", cfg.VDISKMAN, "path to vdiskmanager utility.")
5052

5153
return nil
5254
}
@@ -67,7 +69,7 @@ type Machine struct {
6769

6870
// Refresh reloads the machine information.
6971
func (m *Machine) Refresh() error {
70-
mm, err := GetMachine(m.Name)
72+
mm, err := GetMachine(m.VMX)
7173
mm.State = driver.Running
7274
if err != nil {
7375
return err
@@ -217,18 +219,32 @@ func CreateMachine(mc *driver.MachineConfig) (*Machine, error) {
217219
return nil, ErrMachineExist
218220
}
219221

222+
// Generate vmx config file from template
220223
vmxt := template.Must(template.New("vmx").Parse(vmx))
221224
vmxfile, err := os.Create(getVMX(mc))
222225
if err != nil {
223226
return nil, err
224227
}
225228
vmxt.Execute(vmxfile, mc)
229+
230+
// Generate vmdk file
231+
diskImg := filepath.Join(getBaseFolder(mc), fmt.Sprintf("%s.vmdk", mc.VM))
232+
if _, err := os.Stat(diskImg); err != nil {
233+
if !os.IsNotExist(err) {
234+
return nil, err
235+
}
236+
237+
if err := vdiskmanager(diskImg, mc.DiskSize); err != nil {
238+
return nil, err
239+
}
240+
}
241+
226242
return nil, nil
227243
}
228244

229245
func getBaseFolder(mc *driver.MachineConfig) string {
230246
return filepath.Join(mc.Dir, mc.VM)
231247
}
232248
func getVMX(mc *driver.MachineConfig) string {
233-
return filepath.Join(getBaseFolder(mc), strings.Join([]string{mc.VM, "vmx"}, "."))
249+
return filepath.Join(getBaseFolder(mc), fmt.Sprintf("%s.vmx", mc.VM))
234250
}

vmware/vmrun.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package vmware
22

33
import (
44
"errors"
5+
"fmt"
56
"log"
67
"os"
78
"os/exec"
@@ -28,3 +29,15 @@ func vmrun(args ...string) error {
2829
}
2930
return nil
3031
}
32+
33+
// Make a vmdk disk image with the given size (in MB).
34+
func vdiskmanager(dest string, size uint) error {
35+
cmd := exec.Command(cfg.VDISKMAN, "-c", "-t", "0", "-s", fmt.Sprintf("%dMB", size), "-a", "lsilogic", dest)
36+
37+
if stdout := cmd.Run(); stdout != nil {
38+
if ee, ok := stdout.(*exec.Error); ok && ee == exec.ErrNotFound {
39+
return ErrVMRUNNotFound
40+
}
41+
}
42+
return nil
43+
}

vmware/vmx.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,30 @@ package vmware
22

33
const vmx = `
44
.encoding = "UTF-8"
5-
bios.bootOrder = "CDROM"
65
config.version = "8"
76
displayName = "{{.VM}}"
8-
ethernet0.addressType = "static"
7+
ethernet0.addressType = "generated"
98
ethernet0.connectionType = "nat"
10-
ethernet0.address = "00:0c:29:2c:fe:e5"
11-
ethernet0.linkStatePropagation.enable = "FALSE"
12-
ethernet0.pciSlotNumber = "33"
9+
ethernet0.linkStatePropagation.enable = "TRUE"
1310
ethernet0.present = "TRUE"
1411
ethernet0.virtualDev = "e1000"
1512
ethernet0.wakeOnPcktRcv = "FALSE"
16-
ethernet1.addressType = "static"
17-
ethernet1.connectionType = "hostonly"
18-
ethernet1.address = "00:0c:29:2c:fe:ef"
19-
ethernet1.pciSlotNumber = "34"
20-
ethernet1.present = "TRUE"
21-
ethernet1.virtualDev = "e1000"
22-
ethernet1.wakeOnPcktRcv = "FALSE"
2313
floppy0.present = "FALSE"
2414
guestOS = "other26xlinux-64"
2515
hpet0.present = "TRUE"
2616
ide1:0.deviceType = "cdrom-image"
2717
ide1:0.fileName = "{{.ISO}}"
2818
ide1:0.present = "TRUE"
2919
mem.hotadd = "TRUE"
30-
memsize = "1024"
20+
memsize = "{{.Memory}}"
3121
powerType.powerOff = "soft"
3222
powerType.powerOn = "soft"
3323
powerType.reset = "soft"
3424
powerType.suspend = "soft"
35-
sata0.present = "TRUE"
36-
sata0:0.fileName = "{{.VMDK}}"
37-
sata0:0.present = "TRUE"
38-
scsi0.pciSlotNumber = "16"
39-
scsi0.present = "FALSE"
25+
scsi0.present = "TRUE"
4026
scsi0.virtualDev = "lsilogic"
41-
scsi0:0.present = "FALSE"
27+
scsi0:0.fileName = "{{.VM}}.vmdk"
28+
scsi0:0.present = "TRUE"
29+
virtualHW.productCompatibility = "hosted"
4230
virtualHW.version = "10"
4331
`

0 commit comments

Comments
 (0)