Skip to content

Commit 4464f9e

Browse files
authored
Merge pull request #165 from Stromweld/add-options
add new hw settings and config options
2 parents ff2aeff + cf10ee5 commit 4464f9e

4 files changed

Lines changed: 139 additions & 17 deletions

File tree

builder/virtualbox/iso/builder.go

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Config struct {
5151
// The chipset to be used: PIIX3 or ICH9.
5252
// When set to piix3, the firmare is PIIX3. This is the default.
5353
// When set to ich9, the firmare is ICH9.
54+
// When set to armv8, the firmare is ARMv8.
55+
// When set to armv8virtual, the firmare is ARMv8 Virtual.
5456
Chipset string `mapstructure:"chipset" required:"false"`
5557
// The firmware to be used: BIOS or EFI.
5658
// When set to bios, the firmare is BIOS. This is the default.
@@ -75,16 +77,36 @@ type Config struct {
7577
// When set to Am79C973, the NICs are AMD PCNet-FAST III network card (Am79C973).
7678
// When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960).
7779
// When set to virtio, the NICs are VirtIO.
80+
// When set to usbnet, the NICs are USB Network.
7881
NICType string `mapstructure:"nic_type" required:"false"`
7982
// The audio controller type to be used.
8083
// When set to ac97, the audio controller is ICH AC97. This is the default.
8184
// When set to hda, the audio controller is Intel HD Audio.
8285
// When set to sb16, the audio controller is SoundBlaster 16.
86+
// When set to none, the audio controller is disabled.
8387
AudioController string `mapstructure:"audio_controller" required:"false"`
88+
// The USB controller type to be used.
89+
// When set to ohci, the USB controller is USB 1.1 (OHCI).
90+
// When set to ehci, the USB controller is USB 2.0 (EHCI). This is the default when usb is enabled.
91+
// When set to xhci, the USB controller is USB 3.0 (xHCI).
92+
// When set to none, no USB controller is configured even if usb is enabled.
93+
// This setting is only used when usb is set to true.
94+
USBController string `mapstructure:"usb_controller" required:"false"`
95+
// The mouse device type to be used.
96+
// When set to ps2, a PS/2 mouse is emulated. This is the default.
97+
// When set to usb, a USB mouse is emulated (requires USB to be enabled).
98+
// When set to usbtablet, a USB tablet device is emulated (absolute positioning, requires USB).
99+
// When set to usbmultitouch, a USB multi-touch device is emulated (requires USB).
100+
Mouse string `mapstructure:"mouse" required:"false"`
101+
// The keyboard device type to be used.
102+
// When set to ps2, a PS/2 keyboard is emulated. This is the default.
103+
// When set to usb, a USB keyboard is emulated (requires USB to be enabled).
104+
Keyboard string `mapstructure:"keyboard" required:"false"`
84105
// The graphics controller type to be used.
85106
// When set to vboxvga, the graphics controller is VirtualBox VGA. This is the default.
86107
// When set to vboxsvga, the graphics controller is VirtualBox SVGA.
87108
// When set to vmsvga, the graphics controller is VMware SVGA.
109+
// When set to qemuramfb, the graphics controller is QEMU RAMFB.
88110
// When set to none, the graphics controller is disabled.
89111
// When this configuration is omitted, the default value is determined by VirtualBox.
90112
GfxController string `mapstructure:"gfx_controller" required:"false"`
@@ -224,11 +246,11 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
224246
b.config.Chipset = "piix3"
225247
}
226248
switch b.config.Chipset {
227-
case "piix3", "ich9":
249+
case "piix3", "ich9", "armv8", "armv8virtual":
228250
// do nothing
229251
default:
230252
errs = packersdk.MultiErrorAppend(
231-
errs, errors.New("chipset can only be piix3 or ich9"))
253+
errs, errors.New("chipset can only be piix3, ich9, armv8, or armv8virtual"))
232254
}
233255

234256
if b.config.Firmware == "" {
@@ -265,19 +287,19 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
265287
b.config.NICType = "82540EM"
266288
}
267289
switch b.config.NICType {
268-
case "82540EM", "82543GC", "82545EM", "Am79C970A", "Am79C973", "Am79C960", "virtio":
290+
case "82540EM", "82543GC", "82545EM", "Am79C970A", "Am79C973", "Am79C960", "virtio", "usbnet":
269291
// do nothing
270292
default:
271293
errs = packersdk.MultiErrorAppend(
272-
errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960 or virtio"))
294+
errs, errors.New("NIC type can only be 82540EM, 82543GC, 82545EM, Am79C970A, Am79C973, Am79C960, usbnet, virtio"))
273295
}
274296

275297
switch b.config.GfxController {
276-
case "vboxvga", "vboxsvga", "vmsvga", "none", "":
298+
case "vboxvga", "vboxsvga", "vmsvga", "qemuramfb", "none", "":
277299
// do nothing
278300
default:
279301
errs = packersdk.MultiErrorAppend(
280-
errs, errors.New("Graphics controller type can only be vboxvga, vboxsvga, vmsvga, none"))
302+
errs, errors.New("Graphics controller type can only be vboxvga, vboxsvga, vmsvga, qemuramfb, none"))
281303
}
282304

283305
if b.config.GfxVramSize == 0 {
@@ -302,13 +324,46 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
302324
b.config.AudioController = "ac97"
303325
}
304326
switch b.config.AudioController {
305-
case "ac97", "hda", "sb16":
327+
case "ac97", "hda", "sb16", "none":
306328
// do nothing
307329
default:
308330
errs = packersdk.MultiErrorAppend(
309331
errs, errors.New("Audio controller type can only be ac97, hda or sb16"))
310332
}
311333

334+
if b.config.USBController == "" {
335+
b.config.USBController = "ehci"
336+
}
337+
switch b.config.USBController {
338+
case "ohci", "ehci", "xhci", "none":
339+
// do nothing
340+
default:
341+
errs = packersdk.MultiErrorAppend(
342+
errs, errors.New("USB controller type can only be ohci, ehci, xhci, or none"))
343+
}
344+
345+
if b.config.Mouse == "" {
346+
b.config.Mouse = "ps2"
347+
}
348+
switch b.config.Mouse {
349+
case "ps2", "usb", "usbtablet", "usbmultitouch":
350+
// do nothing
351+
default:
352+
errs = packersdk.MultiErrorAppend(
353+
errs, errors.New("Mouse type can only be ps2, usb, usbtablet, or usbmultitouch"))
354+
}
355+
356+
if b.config.Keyboard == "" {
357+
b.config.Keyboard = "ps2"
358+
}
359+
switch b.config.Keyboard {
360+
case "ps2", "usb":
361+
// do nothing
362+
default:
363+
errs = packersdk.MultiErrorAppend(
364+
errs, errors.New("Keyboard type can only be ps2 or usb"))
365+
}
366+
312367
if b.config.GuestOSType == "" {
313368
b.config.GuestOSType = "Other"
314369
}

builder/virtualbox/iso/builder.hcl2spec.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/virtualbox/iso/step_create_vm.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,55 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
4646
commands = append(commands, []string{"modifyvm", name, "--ioapic", "on"})
4747
}
4848
commands = append(commands, []string{"modifyvm", name, "--memory", strconv.Itoa(config.HWConfig.MemorySize)})
49-
commands = append(commands, []string{"modifyvm", name, "--usb", map[bool]string{true: "on", false: "off"}[config.HWConfig.USB]})
49+
// Configure USB controller
50+
if config.HWConfig.USB && strings.ToLower(config.USBController) != "none" {
51+
commands = append(commands, []string{"modifyvm", name, "--usb", "on"})
52+
commands = append(commands, []string{"modifyvm", name, "--usbohci", "off", "--usbehci", "off", "--usbxhci", "off"})
53+
switch strings.ToLower(config.USBController) {
54+
case "ohci":
55+
commands = append(commands, []string{"modifyvm", name, "--usbohci", "on"})
56+
case "ehci":
57+
commands = append(commands, []string{"modifyvm", name, "--usbehci", "on"})
58+
case "xhci":
59+
commands = append(commands, []string{"modifyvm", name, "--usbxhci", "on"})
60+
}
61+
} else {
62+
commands = append(commands, []string{"modifyvm", name, "--usb", "off"})
63+
}
5064

5165
vboxVersion, _ := driver.Version()
5266
audioDriverArg := audioDriverConfigurationArg(vboxVersion)
53-
if strings.ToLower(config.HWConfig.Sound) == "none" {
54-
commands = append(commands, []string{"modifyvm", name, audioDriverArg, config.HWConfig.Sound,
55-
"--audiocontroller", config.AudioController})
67+
// Only configure audio if the audio controller is not set to "none"
68+
if strings.ToLower(config.AudioController) == "none" {
69+
commands = append(commands, []string{"modifyvm", name, "--audio-enabled", "off"})
5670
} else {
57-
commands = append(commands, []string{"modifyvm", name, audioDriverArg, config.HWConfig.Sound, "--audioin", "on", "--audioout", "on",
58-
"--audiocontroller", config.AudioController})
71+
if strings.ToLower(config.HWConfig.Sound) == "none" {
72+
commands = append(commands, []string{"modifyvm", name, audioDriverArg, config.HWConfig.Sound,
73+
"--audiocontroller", config.AudioController})
74+
} else {
75+
commands = append(commands, []string{"modifyvm", name, audioDriverArg, config.HWConfig.Sound, "--audioin", "on", "--audioout", "on",
76+
"--audiocontroller", config.AudioController})
77+
}
78+
}
79+
80+
// Configure mouse device
81+
switch strings.ToLower(config.Mouse) {
82+
case "ps2":
83+
commands = append(commands, []string{"modifyvm", name, "--mouse", "ps2"})
84+
case "usb":
85+
commands = append(commands, []string{"modifyvm", name, "--mouse", "usb"})
86+
case "usbtablet":
87+
commands = append(commands, []string{"modifyvm", name, "--mouse", "usbtablet"})
88+
case "usbmultitouch":
89+
commands = append(commands, []string{"modifyvm", name, "--mouse", "usbmultitouch"})
90+
}
91+
92+
// Configure keyboard device
93+
switch strings.ToLower(config.Keyboard) {
94+
case "ps2":
95+
commands = append(commands, []string{"modifyvm", name, "--keyboard", "ps2"})
96+
case "usb":
97+
commands = append(commands, []string{"modifyvm", name, "--keyboard", "usb"})
5998
}
6099

61100
commands = append(commands, []string{"modifyvm", name, "--chipset", config.Chipset})
@@ -71,9 +110,9 @@ func (s *stepCreateVM) Run(ctx context.Context, state multistep.StateBag) multis
71110
"--nictype7", config.NICType,
72111
"--nictype8", config.NICType})
73112

74-
// Set the graphics controller, defaulting to "vboxvga" unless overridden by "vmDefaults" or config.
113+
// Set the graphics controller, defaulting to "vboxsvga" unless overridden by "vmDefaults" or config.
75114
if config.GfxController == "" {
76-
config.GfxController = "vboxvga"
115+
config.GfxController = "vboxsvga"
77116
vmDefaultConfigs, defaultConfigsOk := state.GetOk("vmDefaults")
78117
if defaultConfigsOk {
79118
vmDefaultConfigs := vmDefaultConfigs.(map[string]string)

docs-partials/builder/virtualbox/iso/Config-not-required.mdx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
- `chipset` (string) - The chipset to be used: PIIX3 or ICH9.
44
When set to piix3, the firmare is PIIX3. This is the default.
55
When set to ich9, the firmare is ICH9.
6+
When set to armv8, the firmare is ARMv8.
7+
When set to armv8virtual, the firmare is ARMv8 Virtual.
68

79
- `firmware` (string) - The firmware to be used: BIOS or EFI.
810
When set to bios, the firmare is BIOS. This is the default.
@@ -27,16 +29,36 @@
2729
When set to Am79C973, the NICs are AMD PCNet-FAST III network card (Am79C973).
2830
When set to Am79C960, the NICs are AMD PCnet-ISA/NE2100 (Am79C960).
2931
When set to virtio, the NICs are VirtIO.
32+
When set to usbnet, the NICs are USB Network.
3033

3134
- `audio_controller` (string) - The audio controller type to be used.
3235
When set to ac97, the audio controller is ICH AC97. This is the default.
3336
When set to hda, the audio controller is Intel HD Audio.
3437
When set to sb16, the audio controller is SoundBlaster 16.
38+
When set to none, the audio controller is disabled.
39+
40+
- `usb_controller` (string) - The USB controller type to be used.
41+
When set to ohci, the USB controller is USB 1.1 (OHCI).
42+
When set to ehci, the USB controller is USB 2.0 (EHCI). This is the default when usb is enabled.
43+
When set to xhci, the USB controller is USB 3.0 (xHCI).
44+
When set to none, no USB controller is configured even if usb is enabled.
45+
This setting is only used when usb is set to true.
46+
47+
- `mouse` (string) - The mouse device type to be used.
48+
When set to ps2, a PS/2 mouse is emulated. This is the default.
49+
When set to usb, a USB mouse is emulated (requires USB to be enabled).
50+
When set to usbtablet, a USB tablet device is emulated (absolute positioning, requires USB).
51+
When set to usbmultitouch, a USB multi-touch device is emulated (requires USB).
52+
53+
- `keyboard` (string) - The keyboard device type to be used.
54+
When set to ps2, a PS/2 keyboard is emulated. This is the default.
55+
When set to usb, a USB keyboard is emulated (requires USB to be enabled).
3556

3657
- `gfx_controller` (string) - The graphics controller type to be used.
3758
When set to vboxvga, the graphics controller is VirtualBox VGA. This is the default.
3859
When set to vboxsvga, the graphics controller is VirtualBox SVGA.
3960
When set to vmsvga, the graphics controller is VMware SVGA.
61+
When set to qemuramfb, the graphics controller is QEMU RAMFB.
4062
When set to none, the graphics controller is disabled.
4163
When this configuration is omitted, the default value is determined by VirtualBox.
4264

@@ -71,14 +93,14 @@
7193
Virtualbox 6, install an [extension
7294
pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack)
7395
and you will need to enable EFI mode for nvme to work, ex:
74-
96+
7597
In JSON:
7698
```json
7799
"vboxmanage": [
78100
[ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
79101
]
80102
```
81-
103+
82104
In HCL2:
83105
```hcl
84106
vboxmanage = [

0 commit comments

Comments
 (0)