Unattended Installation for Debian
Unattended Debian/Ubuntu installation is done via "preseed" files
These files are generally named "preseed.cfg". They are not Packer-specific tools, though we do make use of them.
If, after following this guide, you're still having issues getting a preseed file working, We recommend you read the official documentation on preseed files.
The guide here is hopefully enough to get you started, but isn't a replacement for the official documentation.
When To Use a Preseed File
If you are installing the operating system from a mounted iso as part of your Packer build, you will need to use a preseed file. For example, you're building an image from scratch using the vmware-iso, virtualbox-iso, or hyperv-iso builders.
If you are not installing the operating system, you won't need to provide a preseed file. If you are using a pre-built image in a cloud, you don't need to worry about preseed files.
How to make a Preseed File
You can either start from an example preseed file from a known repo (take a look at the examples links below), or you can start with the official example preseed, and comment or uncomment the options as you need them.
Where to put the preseed file
The -iso
builders mentioned above all have an http_dir
or an http_content
option. Any file inside of your http_dir
or http_content
will be served on a
local fileserver for your virtual machine to be able to access. One very common
use for this directory is to use it to provide your preseed file.
You then reference the file using a boot_command
to kick off the installation.
In the example below, the preseed/url
command line option is being
used in the /install/vmlinuz command
. The {{ .HTTPIP }}
and
{{ .HTTPPort }}
options are special Packer template options that will get set
by Packer to point to the HTTP server we create, so that your boot command can
access it. For an example of a working boot_command, refer to the Examples section
below. For more information on how boot_command works, refer to the
boot_command section of the docs for whatever builder you are using.
What does Packer need the preseed file to do?
Packer needs the preseed file to handle any questions that would normally be answered interactively during a Debian installation.
If you want to be able to use provisioners, the preseed file must also install SSH so that Packer can connect to the instance.
Examples
A very minimal example of a preseed file can be found below. Much of this was
copied from the official example-preseed shared above. Notice that we are
installing ssh via d-i pkgsel/include string openssh-server
and configuring
a username so that Packer will be able to connect.
You need to make sure that your mirror settings are properly configured for your specific distribution of Debian.
Here's an example of the vmware-iso builder being used to call this preseed. In this case, it is assumed that the file is saved as preseed.cfg inside of a directory called "http", and Packer is being called from the directory containing the "http" directory.
For more functional examples of a Debian preseeded installation, you can refer to the Chef-maintained bento box preseed, the Ubuntu autoinstall config, their builders.