2013-12-22 18:44:43 -05:00
|
|
|
---
|
2018-04-13 22:48:19 -04:00
|
|
|
modeline: |
|
|
|
|
vim: set ft=pandoc:
|
2017-06-14 21:04:16 -04:00
|
|
|
description: |
|
2020-03-18 18:46:47 -04:00
|
|
|
The VirtualBox Packer builder is able to create VirtualBox virtual machines
|
|
|
|
and export them in the OVF format, starting from an ISO image.
|
2015-07-22 22:31:00 -04:00
|
|
|
layout: docs
|
2020-03-18 18:46:47 -04:00
|
|
|
page_title: VirtualBox ISO - Builders
|
2020-03-24 19:48:37 -04:00
|
|
|
sidebar_title: 'ISO'
|
2020-03-18 18:46:47 -04:00
|
|
|
sidebar_current: docs-builders-virtualbox-iso
|
2017-03-25 18:13:52 -04:00
|
|
|
---
|
2013-12-22 18:44:43 -05:00
|
|
|
|
|
|
|
# VirtualBox Builder (from an ISO)
|
|
|
|
|
2014-01-13 14:11:55 -05:00
|
|
|
Type: `virtualbox-iso`
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The VirtualBox Packer builder is able to create
|
|
|
|
[VirtualBox](https://www.virtualbox.org/) virtual machines and export them in
|
|
|
|
the OVF format, starting from an ISO image.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The builder builds a virtual machine by creating a new virtual machine from
|
|
|
|
scratch, booting it, installing an OS, provisioning software within the OS, then
|
|
|
|
shutting it down. The result of the VirtualBox builder is a directory containing
|
|
|
|
all the files necessary to run the virtual machine portably.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
|
|
|
## Basic Example
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Here is a basic example. This example is not functional. It will start the OS
|
|
|
|
installer but then fail because we don't provide the preseed file for Ubuntu to
|
|
|
|
self-install. Still, the example serves to show the basic configuration:
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2013-12-22 18:44:43 -05:00
|
|
|
{
|
2013-12-26 19:16:30 -05:00
|
|
|
"type": "virtualbox-iso",
|
2013-12-22 18:44:43 -05:00
|
|
|
"guest_os_type": "Ubuntu_64",
|
2014-08-20 00:08:22 -04:00
|
|
|
"iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso",
|
|
|
|
"iso_checksum": "769474248a3897f4865817446f9a4a53",
|
2013-12-22 18:44:43 -05:00
|
|
|
"iso_checksum_type": "md5",
|
|
|
|
"ssh_username": "packer",
|
|
|
|
"ssh_password": "packer",
|
|
|
|
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
|
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
It is important to add a `shutdown_command`. By default Packer halts the virtual
|
|
|
|
machine and the file system may not be sync'd. Thus, changes made in a
|
2013-12-22 18:44:43 -05:00
|
|
|
provisioner might not be saved.
|
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
## VirtualBox-ISO Builder Configuration Reference
|
|
|
|
|
|
|
|
There are many configuration options available for the builder. In addition to
|
|
|
|
the items listed here, you will want to look at the general configuration
|
|
|
|
references for [ISO](#iso-configuration),
|
|
|
|
[HTTP](#http-directory-configuration),
|
|
|
|
[Floppy](#floppy-configuration),
|
|
|
|
[Export](#export-configuration),
|
|
|
|
[Boot](#boot-configuration),
|
|
|
|
[Shutdown](#shutdown-configuration),
|
|
|
|
[Run](#run-configuration),
|
|
|
|
[Communicator](#communicator-configuration)
|
|
|
|
configuration references, which are
|
|
|
|
necessary for this build to succeed and can be found further down the page.
|
|
|
|
|
|
|
|
#### Optional:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/iso/Config-not-required.mdx'
|
2020-03-27 14:22:33 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/VBoxVersionConfig-not-required.mdx'
|
2020-03-27 14:22:33 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/VBoxBundleConfig-not-required.mdx'
|
2020-03-27 14:22:33 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/GuestAdditionsConfig-not-required.mdx'
|
2019-06-19 11:22:49 -04:00
|
|
|
|
|
|
|
### ISO Configuration
|
2019-06-12 10:32:24 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/ISOConfig.mdx'
|
2019-06-12 10:32:24 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Required:
|
2019-06-12 10:32:24 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/ISOConfig-required.mdx'
|
2019-06-12 10:32:24 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2019-06-12 10:32:24 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/ISOConfig-not-required.mdx'
|
Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 07:11:58 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
### Http directory configuration
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/HTTPConfig.mdx'
|
2020-03-18 18:46:47 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/HTTPConfig-not-required.mdx'
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
### Floppy configuration
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/FloppyConfig.mdx'
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/FloppyConfig-not-required.mdx'
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
### Export configuration
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/ExportConfig-not-required.mdx'
|
2015-06-23 17:44:57 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
### Output configuration
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/OutputConfig-not-required.mdx'
|
2015-07-22 23:25:58 -04:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
### Run configuration
|
2018-11-17 05:40:44 -05:00
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2016-08-23 17:51:15 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/RunConfig-not-required.mdx'
|
2019-06-19 11:22:49 -04:00
|
|
|
|
|
|
|
### Shutdown configuration
|
|
|
|
|
|
|
|
#### Optional:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/ShutdownConfig-not-required.mdx'
|
2019-06-19 11:22:49 -04:00
|
|
|
|
|
|
|
### Hardware configuration
|
|
|
|
|
|
|
|
#### Optional:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/HWConfig-not-required.mdx'
|
2019-06-19 11:22:49 -04:00
|
|
|
|
|
|
|
### VBox Manage configuration
|
|
|
|
|
|
|
|
#### Optional:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx'
|
2019-06-19 11:22:49 -04:00
|
|
|
|
|
|
|
### Communicator configuration
|
|
|
|
|
2019-06-20 06:22:26 -04:00
|
|
|
#### Optional common fields:
|
2019-06-19 11:22:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'helper/communicator/Config-not-required.mdx'
|
2020-03-24 19:48:37 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builder/virtualbox/common/CommConfig-not-required.mdx'
|
2019-06-20 06:22:26 -04:00
|
|
|
|
|
|
|
#### Optional SSH fields:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'helper/communicator/SSH-not-required.mdx'
|
2019-06-20 06:22:26 -04:00
|
|
|
|
|
|
|
#### Optional WinRM fields:
|
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'helper/communicator/WinRM-not-required.mdx'
|
2019-06-19 11:22:49 -04:00
|
|
|
|
|
|
|
### Boot Configuration
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/bootcommand/BootConfig.mdx'
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2018-04-13 19:48:26 -04:00
|
|
|
The boot command is sent to the VM through the `VBoxManage` utility in as few
|
2018-05-23 18:24:18 -04:00
|
|
|
invocations as possible. We send each character in groups of 25, with a default
|
|
|
|
delay of 100ms between groups. The delay alleviates issues with latency and CPU
|
2018-08-22 14:25:43 -04:00
|
|
|
contention. If you notice missing keys, you can tune this delay by specifying
|
|
|
|
"boot_keygroup_interval" in your Packer template, for example:
|
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2018-08-22 14:25:43 -04:00
|
|
|
{
|
|
|
|
"builders": [
|
|
|
|
{
|
|
|
|
"type": "virtualbox",
|
2018-08-23 16:16:01 -04:00
|
|
|
"boot_keygroup_interval": "500ms"
|
2018-08-22 14:25:43 -04:00
|
|
|
...
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-06-19 11:22:49 -04:00
|
|
|
#### Optional:
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'common/bootcommand/BootConfig-not-required.mdx'
|
2019-06-17 10:42:49 -04:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builders/boot-command.mdx'
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2020-03-23 20:02:12 -04:00
|
|
|
@include 'builders/virtualbox-ssh-key-pair.mdx'
|
2019-02-06 16:03:40 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Example boot command. This is actually a working boot command used to start an
|
|
|
|
Ubuntu 12.04 installer:
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2020-03-18 18:46:47 -04:00
|
|
|
```text
|
2013-12-22 18:44:43 -05:00
|
|
|
[
|
2015-01-30 11:51:20 -05:00
|
|
|
"<esc><esc><enter><wait>",
|
2013-12-22 18:44:43 -05:00
|
|
|
"/install/vmlinuz noapic ",
|
|
|
|
"preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
|
|
|
|
"debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
|
|
|
|
"hostname={{ .Name }} ",
|
|
|
|
"fb=false debconf/frontend=noninteractive ",
|
|
|
|
"keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
|
|
|
|
"keyboard-configuration/variant=USA console-setup/ask_detect=false ",
|
2015-01-30 11:51:20 -05:00
|
|
|
"initrd=/install/initrd.gz -- <enter>"
|
2013-12-22 18:44:43 -05:00
|
|
|
]
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2019-06-21 14:31:57 -04:00
|
|
|
Please note that for the Virtuabox builder, the IP address of the HTTP server
|
|
|
|
Packer launches for you to access files like the preseed file in the example
|
|
|
|
above (`{{ .HTTPIP }}`) is hardcoded to 10.0.2.2. If you change the network
|
|
|
|
of your VM you must guarantee that you can still access this HTTP server.
|
|
|
|
|
2017-10-12 01:58:03 -04:00
|
|
|
For more examples of various boot commands, see the sample projects from our
|
2017-10-13 21:59:58 -04:00
|
|
|
[community templates page](/community-tools.html#templates).
|
2017-10-12 01:58:03 -04:00
|
|
|
|
2013-12-22 18:44:43 -05:00
|
|
|
## Guest Additions
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Packer will automatically download the proper guest additions for the version of
|
|
|
|
VirtualBox that is running and upload those guest additions into the virtual
|
|
|
|
machine so that provisioners can easily install them.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Packer downloads the guest additions from the official VirtualBox website, and
|
|
|
|
verifies the file with the official checksums released by VirtualBox.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
After the virtual machine is up and the operating system is installed, Packer
|
|
|
|
uploads the guest additions into the virtual machine. The path where they are
|
|
|
|
uploaded is controllable by `guest_additions_path`, and defaults to
|
|
|
|
"VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home
|
|
|
|
directory of the SSH user.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
|
|
|
## VBoxManage Commands
|
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
In order to perform extra customization of the virtual machine, a template can
|
|
|
|
define extra calls to `VBoxManage` to perform.
|
2018-12-26 15:37:09 -05:00
|
|
|
[VBoxManage](https://www.virtualbox.org/manual/ch09.html) is the command-line
|
2015-07-22 22:31:00 -04:00
|
|
|
interface to VirtualBox where you can completely control VirtualBox. It can be
|
|
|
|
used to do things such as set RAM, CPUs, etc.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Extra VBoxManage commands are defined in the template in the `vboxmanage`
|
2019-05-20 10:09:45 -04:00
|
|
|
section. An example is shown below that sets the VRAM within the virtual machine:
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2013-12-22 18:44:43 -05:00
|
|
|
{
|
2020-03-18 18:46:47 -04:00
|
|
|
"vboxmanage": [["modifyvm", "{{.Name}}", "--vram", "64"]]
|
2013-12-22 18:44:43 -05:00
|
|
|
}
|
2014-10-20 13:55:16 -04:00
|
|
|
```
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
The value of `vboxmanage` is an array of commands to execute. These commands are
|
|
|
|
executed in the order defined. So in the above example, the memory will be set
|
|
|
|
followed by the CPUs.
|
2013-12-22 18:44:43 -05:00
|
|
|
|
2015-07-22 22:31:00 -04:00
|
|
|
Each command itself is an array of strings, where each string is an argument to
|
|
|
|
`VBoxManage`. Each argument is treated as a [configuration
|
2017-03-28 18:28:34 -04:00
|
|
|
template](/docs/templates/engine.html). The only available
|
2015-07-22 22:31:00 -04:00
|
|
|
variable is `Name` which is replaced with the unique name of the VM, which is
|
|
|
|
required for many VBoxManage calls.
|
2019-11-22 05:17:08 -05:00
|
|
|
|
|
|
|
## Creating an EFI enabled VM
|
|
|
|
|
|
|
|
If you want to create an EFI enabled VM, make sure you set the `iso_interface`
|
|
|
|
to "sata". Otherwise your attached drive will not be bootable. Example:
|
|
|
|
|
2020-03-12 10:05:08 -04:00
|
|
|
```json
|
2019-11-22 05:17:08 -05:00
|
|
|
"iso_interface": "sata",
|
|
|
|
"vboxmanage": [
|
|
|
|
[ "modifyvm", "{{.Name}}", "--firmware", "EFI" ]
|
|
|
|
]
|
2020-03-18 18:46:47 -04:00
|
|
|
```
|