Automated Debian Installation Using Preseed Files
This article explains how the Debian-Installer (d-i) automates operating system deployment using preseed configuration files. It covers the underlying mechanism of the Debian configuration database, how the installer retrieves and parses preseed directives, the primary execution stages, and the methods used to deliver preseed configurations during boot.
The Mechanism: Debconf Preconfiguration
At the core of the Debian-Installer is debconf, the configuration system responsible for prompting users with setup questions. Preseeding works by populating the debconf database with predefined answers before the installer reaches the corresponding questions.
Each preseed directive adheres to a four-part syntax:
<owner> <question-name> <question-type> <value>
- Owner: Typically the package or installer module
(udeb) asking the question (e.g.,
d-i,partman,passwd). - Question name: The unique debconf template
identifier (e.g.,
netcfg/choose_interface). - Question type: The expected data format (e.g.,
string,boolean,select). - Value: The intended answer.
When the installer runs a component, it queries debconf for an
existing answer. If an answer exists at or above the current debconf
priority threshold (commonly set via
debconf/priority=critical), the installer applies the value
and suppresses the user prompt.
How Debian-Installer Loads Preseed Directives
Debian-Installer employs dedicated micro-packages
(udebs), specifically preseed-common and its
transport-specific companions (network-preseed,
file-preseed, initrd-preseed), to ingest
configurations.
- Boot Argument Parsing: The process begins when the
bootloader (such as GRUB, PXELINUX, or ISOLINUX) passes kernel
command-line arguments to the installer. Directives like
auto=trueset the debconf priority to critical, while location parameters (e.g.,preseed/urlorfile=) instruct the installer where to fetch the configuration. - Database Ingestion: The preseed udeb reads the file, parses the directives line by line, and injects them into the debconf database.
- Execution Control: The installer proceeds through its modular phases, consulting the debconf database sequentially. If any required value is omitted and debconf requires user validation, the installation halts and displays an interactive dialog.
Delivery Methods
Preseed configurations can be introduced to the installer at different stages depending on the infrastructure:
- Initrd Preseeding: The file is bundled directly
into the initial ramdisk as
/preseed.cfg. Because it is available before any installer components start, it can automate the earliest setup tasks, including keyboard layout, language, and locale configuration, without prompting. - File/Media Preseeding: The configuration resides on
the local installation media (CD/USB) and is referenced via the kernel
command line (e.g.,
preseed/file=/cdrom/preseed.cfg). - Network Preseeding: The installer configures the
network interface—often automatically via DHCP—and retrieves the preseed
file over HTTP, HTTPS, or FTP (e.g.,
preseed/url=http://example.com/preseed.cfg). This is the standard approach for PXE-based network installations.
Installation Phases and Command Hooks
Debian-Installer executes preseed directives in an orchestrated sequence:
- Early Stage: Handled by
preseed/early_command. This runs shell commands directly in the installer's memory space before disk partitioning or package retrieval begins. - Core Installation: The installer automatically
configures hardware, sets up storage partitions using the
partmanmodule, installs the base Debian system, and deploys selected package tasks usingtasksel. - Late Stage: Handled by
preseed/late_command. This executes scripts near the end of the installation, just before the installer reboots the system. Commands can run inside the installer environment or target the newly installed system viain-target(e.g.,in-target apt-get install -y custom-tool), making it a critical phase for post-install configurations, adding SSH keys, or deploying management agents.