Installing Ubuntu Server on a single machine is straightforward: plug in a USB drive, boot, and click through the graphical installer. However, if you need to provision fifty identical servers in a remote data center without attaching a crash cart to each one, manual installation is impossible. Ubuntu solves this using a Preseed file (often used in conjunction with PXE network booting), which provides automated, predefined answers to every question the installer would normally ask.
What is a Preseed File?
A Preseed file (usually named preseed.cfg) is a simple text file containing key-value pairs. During the boot sequence, the Ubuntu installer checks for this file. If it finds an answer for a specific installation step (like choosing a timezone or partitioning a disk), it skips the interactive prompt and automatically applies your chosen setting.
Step 1: Generating a Base Preseed File
Writing a Preseed file entirely from scratch is tedious. The easiest method is to perform one manual installation exactly how you want it, and then extract the answers to create your template.
After finishing a manual installation on a master server, install the debconf-utils package:
sudo apt update && sudo apt install debconf-utils
Now, dump the configuration into a text file:
sudo debconf-get-selections > preseed.cfg
Step 2: Editing the Preseed File
Open the generated preseed.cfg file in a text editor like Nano. You will see hundreds of lines. You only need to keep the ones relevant to the installation process. Here are some of the most critical sections you will need to configure:
Localization:
d-i debian-installer/locale string en_US
d-i keyboard-configuration/xkb-keymap select us
Network Configuration:
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string webserver01
d-i netcfg/get_domain string localdomain
Disk Partitioning (Wiping the disk automatically):
d-i partman-auto/disk string /dev/sda
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto/choose_recipe select atomic
Account Setup (Creating a default admin):
d-i passwd/user-fullname string Ubuntu Admin
d-i passwd/username string sysadmin
d-i passwd/user-password-crypted password $6$RandomSalt$EncryptedPasswordHashHere
d-i user-setup/allow-password-weak boolean false
Note: Never put plain text passwords in a Preseed file. Generate a hash using mkpasswd -m sha-512 and paste the result.
Step 3: Delivering the Preseed File
For a completely headless, network-based installation, you must host the preseed.cfg file on a web server (e.g., http://192.168.1.10/preseed.cfg).
When you configure your PXE boot server (or if you modify the boot parameters of an Ubuntu ISO), you append the URL to the kernel boot string:
auto=true url=http://192.168.1.10/preseed.cfg
Once the server grabs the DHCP address and boots the kernel, it downloads the Preseed file, wipes the disk, installs the OS, configures the network, installs the OpenSSH server, and reboots—all without a single keystroke from an administrator.