Merge pull request #4013 from artburkart/closes_3999

Closes #3999 - Support VirtualBox Trim/Discard
This commit is contained in:
Matthew Hooker 2016-10-17 13:55:09 -07:00 committed by GitHub
commit 8de02e976c
3 changed files with 37 additions and 16 deletions

View File

@ -37,17 +37,19 @@ type Config struct {
vboxcommon.VBoxManagePostConfig `mapstructure:",squash"` vboxcommon.VBoxManagePostConfig `mapstructure:",squash"`
vboxcommon.VBoxVersionConfig `mapstructure:",squash"` vboxcommon.VBoxVersionConfig `mapstructure:",squash"`
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
DiskSize uint `mapstructure:"disk_size"` DiskSize uint `mapstructure:"disk_size"`
KeepRegistered bool `mapstructure:"keep_registered"` KeepRegistered bool `mapstructure:"keep_registered"`
GuestAdditionsMode string `mapstructure:"guest_additions_mode"` GuestAdditionsMode string `mapstructure:"guest_additions_mode"`
GuestAdditionsPath string `mapstructure:"guest_additions_path"` GuestAdditionsPath string `mapstructure:"guest_additions_path"`
GuestAdditionsURL string `mapstructure:"guest_additions_url"` GuestAdditionsURL string `mapstructure:"guest_additions_url"`
GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"` GuestAdditionsSHA256 string `mapstructure:"guest_additions_sha256"`
GuestOSType string `mapstructure:"guest_os_type"` GuestOSType string `mapstructure:"guest_os_type"`
HardDriveInterface string `mapstructure:"hard_drive_interface"` HardDriveInterface string `mapstructure:"hard_drive_interface"`
ISOInterface string `mapstructure:"iso_interface"` HardDriveNonrotational bool `mapstructure:"hard_drive_nonrotational"`
VMName string `mapstructure:"vm_name"` HardDriveDiscard bool `mapstructure:"hard_drive_discard"`
ISOInterface string `mapstructure:"iso_interface"`
VMName string `mapstructure:"vm_name"`
ctx interpolate.Context ctx interpolate.Context
} }

View File

@ -82,6 +82,16 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
controllerName = "SCSI Controller" controllerName = "SCSI Controller"
} }
nonrotational := "off"
if config.HardDriveNonrotational {
nonrotational = "on"
}
discard := "off"
if config.HardDriveDiscard {
discard = "on"
}
command = []string{ command = []string{
"storageattach", vmName, "storageattach", vmName,
"--storagectl", controllerName, "--storagectl", controllerName,
@ -89,6 +99,8 @@ func (s *stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction {
"--device", "0", "--device", "0",
"--type", "hdd", "--type", "hdd",
"--medium", path, "--medium", path,
"--nonrotational", nonrotational,
"--discard", discard,
} }
if err := driver.VBoxManage(command...); err != nil { if err := driver.VBoxManage(command...); err != nil {
err := fmt.Errorf("Error attaching hard drive: %s", err) err := fmt.Errorf("Error attaching hard drive: %s", err)

View File

@ -153,7 +153,7 @@ builder.
- `floppy_dirs` (array of strings) - A list of directories to place onto - `floppy_dirs` (array of strings) - A list of directories to place onto
the floppy disk recursively. This is similar to the `floppy_files` option the floppy disk recursively. This is similar to the `floppy_files` option
except that the directory structure is preserved. This is useful for when except that the directory structure is preserved. This is useful for when
your floppy disk includes drivers or if you just want to organize it's your floppy disk includes drivers or if you just want to organize its
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed. contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
- `format` (string) - Either "ovf" or "ova", this specifies the output format - `format` (string) - Either "ovf" or "ova", this specifies the output format
@ -196,6 +196,13 @@ builder.
is attached to an AHCI SATA controller. When set to "scsi", the drive is is attached to an AHCI SATA controller. When set to "scsi", the drive is
attached to an LsiLogic SCSI controller. attached to an LsiLogic SCSI controller.
- `hard_drive_nonrotational` (boolean) - Forces some guests (i.e. Windows 7+)
to treat disks as SSDs and stops them from performing disk fragmentation.
- `hard_drive_discard` (boolean) - When this value is set to true, a VDI
image will be shrunk in response to the trim command from the guest OS.
The size of the cleared area must be at least 1MB.
- `headless` (boolean) - Packer defaults to building VirtualBox virtual - `headless` (boolean) - Packer defaults to building VirtualBox virtual
machines by launching a GUI that shows the console of the machine machines by launching a GUI that shows the console of the machine
being built. When this value is set to true, the machine will start without being built. When this value is set to true, the machine will start without