Hyper-V ISO: Fix long lines

This commit is contained in:
DanHam 2018-06-14 12:24:00 +01:00
parent 6226992757
commit 83a8537db5
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
1 changed files with 156 additions and 133 deletions

View File

@ -13,19 +13,20 @@ sidebar_current: 'docs-builders-hyperv-iso'
Type: `hyperv-iso`
The Hyper-V Packer builder is able to create [Hyper-V](https://www.microsoft.com/en-us/server-cloud/solutions/virtualization.aspx)
The Hyper-V Packer builder is able to create
[Hyper-V](https://www.microsoft.com/en-us/server-cloud/solutions/virtualization.aspx)
virtual machines and export them, starting from an ISO image.
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 Hyper-V builder is a directory
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 Hyper-V builder is a directory
containing all the files necessary to run the virtual machine portably.
## Basic Example
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:
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:
``` json
{
@ -45,13 +46,13 @@ provisioner might not be saved.
## Configuration Reference
There are many configuration options available for the Hyper-V builder.
They are organized below into two categories: required and optional. Within
each category, the available options are alphabetized and described.
There are many configuration options available for the Hyper-V builder. They
are organized below into two categories: required and optional. Within each
category, the available options are alphabetized and described.
In addition to the options listed here, a
[communicator](/docs/templates/communicator.html)
can be configured for this builder.
[communicator](/docs/templates/communicator.html) can be configured for this
builder.
### Required:
@ -64,85 +65,93 @@ can be configured for this builder.
- `iso_checksum_type` (string) - The type of the checksum specified in
`iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or
"sha512" currently. While "none" will skip checksumming, this is not
recommended since ISO files and virtual harddrive files are generally large
and corruption does happen from time to time.
recommended since ISO files and virtual harddrive files are generally
large and corruption does happen from time to time.
- `iso_url` (string) - A URL to the ISO containing the installation image or
virtual harddrive vhd or vhdx file to clone. This URL can be either an HTTP
URL or a file URL (or path to a file). If this is an HTTP URL, Packer will
download the file and cache it between runs.
virtual harddrive vhd or vhdx file to clone. This URL can be either an
HTTP URL or a file URL (or path to a file). If this is an HTTP URL, Packer
will download the file and cache it between runs.
### Optional:
- `boot_command` (array of strings) - This is an array of commands to type
when the virtual machine is first booted. The goal of these commands should
be to type just enough to initialize the operating system installer. Special
keys can be typed as well, and are covered in the section below on the boot
command. If this is not specified, it is assumed the installer will start
itself.
when the virtual machine is first booted. The goal of these commands
should be to type just enough to initialize the operating system
installer. Special keys can be typed as well, and are covered in the
section below on the boot command. If this is not specified, it is assumed
the installer will start itself.
- `boot_wait` (string) - The time to wait after booting the initial virtual
machine before typing the `boot_command`. The value of this should be
a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
five seconds and one minute 30 seconds, respectively. If this isn't specified,
the default is 10 seconds.
machine before typing the `boot_command`. The value of this should be a
duration. Examples are "5s" and "1m30s" which will cause Packer to wait
five seconds and one minute 30 seconds, respectively. If this isn't
specified, the default is 10 seconds.
- `cpu` (number) - The number of cpus the virtual machine should use. If this isn't specified,
the default is 1 cpu.
- `cpu` (number) - The number of cpus the virtual machine should use. If
this isn't specified, the default is 1 cpu.
- `disk_additional_size` (array of integers) - The size(s) of any additional
hard disks for the VM in megabytes. If this is not specified then the VM
will only contain a primary hard disk. Additional drives will be attached to the SCSI
interface only. The builder uses expandable, not fixed-size virtual hard disks,
so the actual file representing the disk will not use the full size unless it is full.
will only contain a primary hard disk. Additional drives will be attached
to the SCSI interface only. The builder uses expandable, not fixed-size
virtual hard disks, so the actual file representing the disk will not use
the full size unless it is full.
- `disk_size` (number) - The size, in megabytes, of the hard disk to create
for the VM. By default, this is 40 GB.
- `differencing_disk` (boolean) - If true enables differencing disks. Only the changes will be written to the new disk. This is especially useful if your
source is a vhd/vhdx. This defaults to false.
- `differencing_disk` (boolean) - If true enables differencing disks. Only
the changes will be written to the new disk. This is especially useful if
your source is a vhd/vhdx. This defaults to false.
- `headless` (boolean) - Packer defaults to building Hyper-V virtual
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
a console.
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 a
console.
- `skip_export` (boolean) - If true skips VM export. If you are interested only in the vhd/vhdx files, you can enable this option. This will create
inline disks which improves the build performance. There will not be any copying of source vhds to temp directory. This defaults to false.
- `skip_export` (boolean) - If true skips VM export. If you are interested
only in the vhd/vhdx files, you can enable this option. This will create
inline disks which improves the build performance. There will not be any
copying of source vhds to temp directory. This defaults to false.
- `enable_dynamic_memory` (boolean) - If true enable dynamic memory for virtual machine.
This defaults to false.
- `enable_dynamic_memory` (boolean) - If true enable dynamic memory for
virtual machine. This defaults to false.
- `enable_mac_spoofing` (boolean) - If true enable mac spoofing for virtual machine.
This defaults to false.
- `enable_mac_spoofing` (boolean) - If true enable mac spoofing for virtual
machine. This defaults to false.
- `enable_secure_boot` (boolean) - If true enable secure boot for virtual machine. This defaults to false.
- `enable_secure_boot` (boolean) - If true enable secure boot for virtual
machine. This defaults to false.
- `secure_boot_template` (string) - The secure boot template to be configured. Valid values are "MicrosoftWindows" (Windows) or
"MicrosoftUEFICertificateAuthority" (Linux). This only takes effect if enable_secure_boot is set to "true". This defaults to "MicrosoftWindows".
- `secure_boot_template` (string) - The secure boot template to be
configured. Valid values are "MicrosoftWindows" (Windows) or
"MicrosoftUEFICertificateAuthority" (Linux). This only takes effect if
enable_secure_boot is set to "true". This defaults to "MicrosoftWindows".
- `enable_virtualization_extensions` (boolean) - If true enable virtualization extensions for virtual machine.
This defaults to false. For nested virtualization you need to enable mac spoofing, disable dynamic memory
and have at least 4GB of RAM for virtual machine.
- `enable_virtualization_extensions` (boolean) - If true enable
virtualization extensions for virtual machine. This defaults to false.
For nested virtualization you need to enable mac spoofing, disable dynamic
memory and have at least 4GB of RAM for virtual machine.
- `floppy_files` (array of strings) - A list of files to place onto a floppy
disk that is attached when the VM is booted. This is most useful
for unattended Windows installs, which look for an `Autounattend.xml` file
on removable media. By default, no floppy will be attached. All files
listed in this setting get placed into the root directory of the floppy
and the floppy is attached as the first floppy device. Currently, no
support exists for creating sub-directories on the floppy. Wildcard
characters (`*`, `?`, and `[]`) are allowed. Directory names are also allowed,
which will add all the files found in the directory to the floppy.
disk that is attached when the VM is booted. This is most useful for
unattended Windows installs, which look for an `Autounattend.xml` file on
removable media. By default, no floppy will be attached. All files listed
in this setting get placed into the root directory of the floppy and the
floppy is attached as the first floppy device. Currently, no support
exists for creating sub-directories on the floppy. Wildcard characters
(`*`, `?`, and `[]`) are allowed. Directory names are also allowed, which
will add all the files found in the directory to the floppy.
- `floppy_dirs` (array of strings) - A list of directories to place onto
the floppy disk recursively. This is similar to the `floppy_files` option
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
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
The maximum summary size of all files in the listed directories are the
same as in `floppy_files`.
contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are
allowed. The maximum summary size of all files in the listed directories
are the same as in `floppy_files`.
- `generation` (number) - The Hyper-V generation for the virtual machine. By
default, this is 1. Generation 2 Hyper-V virtual machines do not support
@ -150,10 +159,11 @@ can be configured for this builder.
drives and dvd drives will also be scsi and not ide.
- `guest_additions_mode` (string) - How should guest additions be installed.
If value `attach` then attach iso image with by specified by `guest_additions_path`.
Otherwise guest additions is not installed.
If value `attach` then attach iso image with by specified by
`guest_additions_path`. Otherwise guest additions is not installed.
- `guest_additions_path` (string) - The path to the iso image for guest additions.
- `guest_additions_path` (string) - The path to the iso image for guest
additions.
- `http_directory` (string) - Path to a directory to serve using an HTTP
server. The files in this directory will be available over HTTP that will
@ -164,17 +174,19 @@ can be configured for this builder.
below.
- `http_port_min` and `http_port_max` (number) - These are the minimum and
maximum port to use for the HTTP server started to serve the `http_directory`.
Because Packer often runs in parallel, Packer will choose a randomly available
port in this range to run the HTTP server. If you want to force the HTTP
server to be on one port, make this minimum and maximum port the same.
By default the values are 8000 and 9000, respectively.
maximum port to use for the HTTP server started to serve the
`http_directory`. Because Packer often runs in parallel, Packer will
choose a randomly available port in this range to run the HTTP server. If
you want to force the HTTP server to be on one port, make this minimum and
maximum port the same. By default the values are 8000 and 9000,
respectively.
- `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
Packer will try these in order. If anything goes wrong attempting to download
or while downloading a single URL, it will move on to the next. All URLs
must point to the same file (same checksum). By default this is empty
and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
Packer will try these in order. If anything goes wrong attempting to
download or while downloading a single URL, it will move on to the next.
All URLs must point to the same file (same checksum). By default this is
empty and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be
specified.
- `iso_target_extension` (string) - The extension of the iso file after
download. This defaults to "iso".
@ -184,89 +196,96 @@ can be configured for this builder.
original filename as its name.
- `output_directory` (string) - This is the path to the directory where the
resulting virtual machine will be created. This may be relative or absolute.
If relative, the path is relative to the working directory when `packer`
is executed. This directory must not exist or be empty prior to running the builder.
By default this is "output-BUILDNAME" where "BUILDNAME" is the name
of the build.
resulting virtual machine will be created. This may be relative or
absolute. If relative, the path is relative to the working directory when
`packer` is executed. This directory must not exist or be empty prior to
running the builder. By default this is "output-BUILDNAME" where
"BUILDNAME" is the name of the build.
- `ram_size` (number) - The size, in megabytes, of the ram to create
for the VM. By default, this is 1 GB.
- `ram_size` (number) - The size, in megabytes, of the ram to create for the
VM. By default, this is 1 GB.
- `secondary_iso_images` (array of strings) - A list of iso paths to attached to a
VM when it is booted. This is most useful for unattended Windows installs, which
look for an `Autounattend.xml` file on removable media. By default, no
secondary iso will be attached.
- `secondary_iso_images` (array of strings) - A list of iso paths to
attached to a VM when it is booted. This is most useful for unattended
Windows installs, which look for an `Autounattend.xml` file on removable
media. By default, no secondary iso will be attached.
- `shutdown_command` (string) - The command to use to gracefully shut down the machine once all
the provisioning is done. By default this is an empty string, which tells Packer to just
forcefully shut down the machine unless a shutdown command takes place inside script so this may
safely be omitted. If one or more scripts require a reboot it is suggested to leave this blank
since reboots may fail and specify the final shutdown command in your last script.
- `shutdown_command` (string) - The command to use to gracefully shut down
the machine once all the provisioning is done. By default this is an empty
string, which tells Packer to just forcefully shut down the machine unless
a shutdown command takes place inside script so this may safely be
omitted. If one or more scripts require a reboot it is suggested to leave
this blank since reboots may fail and specify the final shutdown command
in your last script.
- `shutdown_timeout` (string) - The amount of time to wait after executing
the `shutdown_command` for the virtual machine to actually shut down.
If it doesn't shut down in this time, it is an error. By default, the timeout
the `shutdown_command` for the virtual machine to actually shut down. If
it doesn't shut down in this time, it is an error. By default, the timeout
is "5m", or five minutes.
- `skip_compaction` (boolean) - If true skip compacting the hard disk for virtual machine when
exporting. This defaults to false.
- `skip_compaction` (boolean) - If true skip compacting the hard disk for
virtual machine when exporting. This defaults to false.
- `switch_name` (string) - The name of the switch to connect the virtual machine to. Be defaulting
this to an empty string, Packer will try to determine the switch to use by looking for
external switch that is up and running.
- `switch_name` (string) - The name of the switch to connect the virtual
machine to. Be defaulting this to an empty string, Packer will try to
determine the switch to use by looking for external switch that is up and
running.
- `switch_vlan_id` (string) - This is the vlan of the virtual switch's network card.
By default none is set. If none is set then a vlan is not set on the switch's network card.
If this value is set it should match the vlan specified in by `vlan_id`.
- `switch_vlan_id` (string) - This is the vlan of the virtual switch's
network card. By default none is set. If none is set then a vlan is not
set on the switch's network card. If this value is set it should match
the vlan specified in by `vlan_id`.
- `use_fixed_vhd_format` (boolean) - If true, creates the boot disk on the virtual machine as
a fixed VHD format disk. The default is false, which creates a dynamic VHDX format disk. This
option requires setting `generation` to 1, `skip_compaction` to true, and `differencing_disk` to false.
Additionally, any value entered for `disk_block_size` will be ignored. The most likely use case for this
option is outputing a disk that is in the format required for upload to Azure.
- `use_fixed_vhd_format` (boolean) - If true, creates the boot disk on the
virtual machine as a fixed VHD format disk. The default is false, which
creates a dynamic VHDX format disk. This option requires setting
`generation` to 1, `skip_compaction` to true, and `differencing_disk` to
false. Additionally, any value entered for `disk_block_size` will be
ignored. The most likely use case for this option is outputing a disk that
is in the format required for upload to Azure.
- `vhd_temp_path` (string) - A separate path to be used for storing the VM's
disk image. The purpose is to enable reading and writing to take place on
different physical disks (read from VHD temp path, write to regular temp
path while exporting the VM) to eliminate a single-disk bottleneck.
- `vlan_id` (string) - This is the vlan of the virtual machine's network card
for the new virtual machine. By default none is set. If none is set then
vlans are not set on the virtual machine's network card.
- `vlan_id` (string) - This is the vlan of the virtual machine's network
card for the new virtual machine. By default none is set. If none is set
then vlans are not set on the virtual machine's network card.
- `mac_address` (string) - This allows a specific MAC address to be used on the
default virtual network card. The MAC address must be a string with no
delimiters, for example "0000deadbeef".
- `mac_address` (string) - This allows a specific MAC address to be used on
the default virtual network card. The MAC address must be a string with
no delimiters, for example "0000deadbeef".
- `vm_name` (string) - This is the name of the virtual machine for the new virtual
machine, without the file extension. By default this is "packer-BUILDNAME",
where "BUILDNAME" is the name of the build.
- `vm_name` (string) - This is the name of the virtual machine for the new
virtual machine, without the file extension. By default this is
"packer-BUILDNAME", where "BUILDNAME" is the name of the build.
- `temp_path` (string) - This is the temporary path in which Packer will create the virtual
machine. Default value is system `%temp%`
- `temp_path` (string) - This is the temporary path in which Packer will
create the virtual machine. Default value is system `%temp%`
- `disk_block_size` (string) - The block size of the VHD to be created.
Recommended disk block size for Linux hyper-v guests is 1 MiB. This defaults to "32 MiB".
Recommended disk block size for Linux hyper-v guests is 1 MiB. This
defaults to "32 MiB".
## Boot Command
The `boot_command` configuration is very important: it specifies the keys
to type when the virtual machine is first booted in order to start the
OS installer. This command is typed after `boot_wait`, which gives the
virtual machine some time to actually load the ISO.
The `boot_command` configuration is very important: it specifies the keys to
type when the virtual machine is first booted in order to start the OS
installer. This command is typed after `boot_wait`, which gives the virtual
machine some time to actually load the ISO.
As documented above, the `boot_command` is an array of strings. The
strings are all typed in sequence. It is an array only to improve readability
within the template.
As documented above, the `boot_command` is an array of strings. The strings
are all typed in sequence. It is an array only to improve readability within
the template.
The boot command is "typed" character for character over the virtual keyboard
to the machine, simulating a human actually typing the keyboard.
<%= partial "partials/builders/boot-command" %>
Example boot command. This is actually a working boot command used to start
an Ubuntu 12.04 installer:
Example boot command. This is actually a working boot command used to start an
Ubuntu 12.04 installer:
``` json
[
@ -292,18 +311,22 @@ for the version of Hyper-V that is running.
## Generation 1 vs Generation 2
Floppy drives are no longer supported by generation 2 machines. This requires you to
take another approach when dealing with preseed or answer files. Two possible options
are using virtual dvd drives or using the built in web server.
Floppy drives are no longer supported by generation 2 machines. This requires
you to take another approach when dealing with preseed or answer files. Two
possible options are using virtual dvd drives or using the built in web
server.
When dealing with Windows you need to enable UEFI drives for generation 2 virtual machines.
When dealing with Windows you need to enable UEFI drives for generation 2
virtual machines.
## Creating iso from directory
Programs like mkisofs can be used to create an iso from a directory.
There is a [windows version of mkisofs](http://opensourcepack.blogspot.co.uk/p/cdrtools.html).
Programs like mkisofs can be used to create an iso from a directory. There is
a [windows version of
mkisofs](http://opensourcepack.blogspot.co.uk/p/cdrtools.html).
Example powershell script. This is an actually working powershell script used to create a Windows answer iso:
Example powershell script. This is an actually working powershell script used
to create a Windows answer iso:
``` powershell
$isoFolder = "answer-iso"
@ -866,8 +889,8 @@ Finish proxy after sysprep -->
## Example For Ubuntu Vivid Generation 2
If you are running Windows under virtualization, you may need to create
a virtual switch with an `External` connection type.
If you are running Windows under virtualization, you may need to create a
virtual switch with an `External` connection type.
### Packer config: