Debian Unattended Installation

Use preseed file to perform unattended installation of Debian.

2023/07/28

First, we need to configure a preseed file.

Preseeding provides a way to set answers to questions asked during the installation process, without having to manually enter the answers while the installation is running. This makes it possible to fully automate most types of installation and even offers some features not available during normal installations.

--- DebianInstaller/Preseed: https://wiki.debian.org/DebianInstaller/Preseed

Here is an example preseed file (preseed.cfg) for users in Mainland China:

d-i debian-installer/locale string zh_CN.UTF-8
d-i keyboard-configuration/xkb-keymap select us

d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string { hostname }
d-i netcfg/get_domain string { domain }
d-i netcfg/hostname string { hostname }
d-i netcfg/wireless_wep string
d-i hw-detect/load_firmware boolean true

d-i mirror/country string manual
d-i mirror/http/hostname string { mirror domain }
d-i mirror/http/directory string { mirror path, usually "/debian" }
d-i mirror/http/proxy string

d-i passwd/make-user boolean false
d-i passwd/root-password-crypted password { generate with "openssl passwd" }

d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string { ntp server address }

d-i partman-auto/method string regular
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-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman-efi/non_efi_system boolean true
d-i partman-partitioning/choose_label select gpt
d-i partman-partitioning/default_label string gpt

d-i base-installer/kernel/image string linux-image-amd64
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/non-free-firmware boolean true
d-i apt-setup/non-free boolean true
d-i apt-setup/contrib boolean true
d-i apt-setup/disable-cdrom-entries boolean true
d-i apt-setup/security_host string { mirror domain }

tasksel tasksel/first multiselect ssh-server
d-i pkgsel/include string { package to pre-install }
d-i pkgsel/upgrade select none
popularity-contest popularity-contest/participate boolean false

d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default
d-i finish-install/reboot_in_progress note

d-i partman/early_command string debconf-set partman-auto/disk "$(list-devices disk | head -n1)"
d-i preseed/late_command string { commands to preform after installation }

Here is the official example of preseed file: https://www.debian.org/releases/stable/example-preseed.txt

Then we need to add that config to initrd file of the installation ISO.

Extract the installation ISO, extract initrd.gz file in install.amd directory, and run the following commands in the parent directory:

echo preseed.cfg | cpio -H newc -o -A -F iso_extract/install.amd/initrd
gzip iso_extract/install.amd/initrd
cd iso_extract
find -follow -type f ! -name md5sum.txt -print0 | xargs -0 md5sum > md5sum.txt
genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../debian_custom.iso .

You should get a new ISO named debian_custom.iso.

More details: DebianInstaller/Preseed/EditIso