A preseed.cfg
file is a configuration file used by the Debian and Ubuntu installers to automate the installation process. It allows you to pre-answer all the questions that would normally be asked during a manual installation, such as language, keyboard layout, partitioning scheme, and user accounts. This is particularly useful for deploying many identical systems, as it ensures consistency and saves a lot of time and effort.
The installer, whether from a CD, USB, or network boot, can be pointed to a preseed.cfg
file. When it starts, it reads the file and uses the provided answers to automatically progress through the installation steps. This completely bypasses the need for human interaction. The preseed
file can be hosted on a web server, embedded in the installation media, or served via a network boot setup.
Here's a snippet from a basic preseed.cfg
file to show how it works. Each line specifies an answer for a particular question. The syntax is package_name/variable_name
followed by a space and then the value.
# Language and keyboard
d-i debian-installer/language string en
d-i keyboard-configuration/xkb-model select pc105
d-i keyboard-configuration/xkb-layout select us
# Networking
d-i netcfg/get_hostname string my-server
d-i netcfg/get_domain string my-domain.local
# Partitioning
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string regular
d-i partman-auto/expert_recipe string \
boot-root :: \
100 200 100 ext4 \
$primary{ } $bootable{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ / } \
. \
100 500 100 ext4 \
$primary{ } \
method{ format } format{ } \
use_filesystem{ } filesystem{ ext4 } \
mountpoint{ /home } \
. \
100 200 100 swap \
$primary{ } \
method{ swap } format{ } \
.
Using a preseed.cfg
file offers significant advantages, especially in environments where you need to deploy many systems.
By automating the installation process, you can deploy multiple systems simultaneously without manual intervention. This drastically reduces the time and labor required for system setup.
A preseed
file ensures that every system is installed with the exact same configuration. This eliminates human error and guarantees that all your systems are standardized, which simplifies management, troubleshooting, and security.
Once you've created a preseed.cfg
file, you can use it to deploy dozens or even hundreds of machines. It's a key component of scalable infrastructure management, particularly when combined with network booting (PXE).
Because the preseed.cfg
file is a plain text file, you can easily store it in a version control system like Git. This allows you to track changes, revert to previous versions, and collaborate with others on the installation configuration.
You can customize the preseed
file to include specific packages, run custom scripts after the base installation, and configure post-install settings. This allows you to create a "golden image" that's tailored to your exact needs.
-
Create your
preseed.cfg
file: Start with a template or use the Debian Installer Reference Manual to find the variables you need. -
Host the file: Place the
preseed.cfg
file on a web server, TFTP server, or embed it on your installation media. -
Boot the installer: Point the installer to your
preseed
file. This can be done via a boot parameter at the beginning of the installation. For example:-
For a network boot (PXE): Add
preseed/url=http://your-server/path/to/preseed.cfg
to the kernel boot command line. -
For an ISO: You can edit the
isolinux
orgrub
bootloader configuration on the media to automatically load the preseed file.
-
-
Watch it go: The installer will read the file and complete the installation without any prompts.
This is a common example of a kernel boot command line you might use for a network boot (PXE) setup.
auto=true preseed/url=http://<host_ip>:8000/preseed.cfg priority=critical interface=auto
Let's break down the parameters:
-
auto=true
: This flag tells the installer to run in an automated, non-interactive mode. -
preseed/url=http://<host_ip>:8000/preseed.cfg
: This is the core part, specifying the URL where the installer can find thepreseed.cfg
file. You should replace<host_ip>
with the actual IP address of your web server. -
priority=critical
: This sets the priority level of the installer questions.critical
tells the installer to only ask questions if they are absolutely essential for the installation to proceed, which further automates the process. -
interface=auto
: This tells the installer to automatically configure the network interface, which is useful for a network boot scenario.