Unattended Debian installation

Español English
Debian GNU/Linux

Debian is a rock solid GNU/Linux distribution with more than 30,000 packages available in its official repositories. Debian is suitable for servers, workstations, mobile devices and embedded systems.

Debian has a simple and clean installation system which allows installing Debian with little effort as long as the number of installations to be executed is minimal, but as this number grows the installation procedure becomes cumbersome and tedious (Please note that during the installation process it is necessary to answer configuration questions and package selection), for example if we want to install Debian in a lab that has 15 workstations, we need to repeat this process 15 times, which is possible , but if we want to deploy Debian in mass, for example 100, 200, 500 or 1000 installations, it is no longer feasible, this is the reason why the Debian developers have created a system that allows automatic or unattended installations starting from a configuration file (preseed).

There are three methods that can be used to execute an unattended installation:

  1. Adding the preseed file to the installer’s initrd.gz, link
  2. Add the file boot parameter to the ISO image
  3. Load the preseed.cfg file from the network

In this post we’re going to use method 1 for unattended installation starting from DebianInstaller/Preseed/EditIso

1. Dowload Debian image

We will download the “net-install” image that allows a minimal installation, an internet connection is needed since the files are downloaded from Debian repositories.

$ curl -LO# https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.8.0-amd64-netinst.iso

Ponga aqui la contraseña encryptada
Recommended reading: How to download files using curl

2. Install xorriso

xorriso allows to extract files from an ISO image and dump into the file system

$ sudo apt -y install xorriso

3. Extract the files from the ISO

With the following command we put the files contained in the “net-install” image into the file system under the isofiles DIR if the isofiles DIR does not exist, xorriso creates it automatically.

$ xorriso -osirrox on -indev debian-10.1.0-amd64-netinst.iso  -extract / isofiles/

4. Dowload a base preseed

A basic template is available from Debian site which serves as a starting point for our unattended installation system.

$ curl -#L https://www.debian.org/releases/stable/example-preseed.txt -o preseed.cfg

Recommended reading: How to download files using curl

5. Modify preseed template according our needs

5.1. Setting the locale

Set operating system language to English, UTF-8 encoding and locale settings (date, currencies) to English U.S.

d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debian-installer/locale string en_US.UTF-8

5.2. Setting the timezone

Set the hardware clock to UTC and set the timezone to America/New_York (we can use any value found on /usr/share/zoneinfo/) and use NTP for time synchronization.

d-i clock-setup/utc boolean true
d-i time/zone string America/New_York
d-i clock-setup/ntp boolean true

5.3. Configure the keyboard

Set the keyboard to US.

d-i keyboard-configuration/xkb-keymap select us

5.4. Configure the network

With the following configuration the installation system will try to configure the network automatically, set the hostname to debian10, set localdomain as domain name and use the http.us.debian.org as mirror it is also possible to specify a proxy which in this case is empty.

d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string debian10
d-i netcfg/get_domain string localdomain
# Avoid to show WEP dialog
d-i netcfg/wireless_wep string
d-i mirror/country string manual
d-i mirror/http/hostname string http.us.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string

5.5. Configure users

We disable the the root user authentication user, instead we will use sudo with a standard user with encrypted password.

d-i passwd/root-login boolean false
d-i passwd/user-fullname string Put_your_full_name_here
d-i passwd/username string your_user_name
d-i passwd/user-password-crypted password put_encrypted_password

To encrypt the password you can execute the following command:

$ python3 -c 'import crypt; print(crypt.crypt("mipass", crypt.METHOD_SHA512))'

5.6. Partitioning

We’re going to use LVM as partition method, any old partition will be removed, the selected partition scheme is atomic that means use the the entire hard disk for a single partition, another options are: home (living in its own partition) and multi (separate partitions for /home, /var, /tmp).

d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm 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-auto-lvm/guided_size string max

Avoid that partman asks for confirmation to continue with the partition process.

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

5.7. Packages selection

In addition to the base system, install an SSH server.

tasksel tasksel/first multiselect
d-i pkgsel/include string openssh-server

5.8. Disable send stats

popularity-contest popularity-contest/participate boolean false

5.9. Some GRUB configuration

d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev  string default

5.10. Final configurations

# Don't show "Installation has been completed" message
d-i finish-install/reboot_in_progress note
# Avoid CD/DVD scan
d-i apt-setup/cdrom/set-first boolean false
d-i apt-setup/cdrom/set-next boolean false
d-i apt-setup/cdrom/set-failed boolean false

You can download the preseed file with the settings described above at: Debian preseed

6. Add preseed to initrd

Set write permissions to install.amd DIR

$ chmod +w -R isofiles/install.amd/

Unzip initrd image

$ gunzip isofiles/install.amd/initrd.gz

Add preseed.cfg to initrd

$ echo preseed.cfg | cpio -H newc -o -A -F isofiles/install.amd/initrd

Recreate the initrd image

$ gzip isofiles/install.amd/initrd

Remove write permission to install.amd DIR.

$ chmod -w -R isofiles/install.amd/

7. Modify the boot loader

7.1 ISOLINUX

The ISOLINUX boot loader is compatible with BIOS

We should edit the isolinux/isolinux.cfg file and delete the line default vesamenu.c32 this avoid the Debian installation menu.

7.2 GRUB

GRUB boot loader is compatible with UEFI

We should edit boot/grub/grub.cfg file and the following lines that avoid the Debian installation menu.

set timeout_style=hidden
set timeout=0
set default=1

8. Generate the MD5 sum (md5sum.txt)

$ cd isofiles/
$ chmod a+w md5sum.txt
$ md5sum `find -follow -type f` > md5sum.txt
$ chmod a-w md5sum.txt

9. Create the ISO

$ cd ..
$ chmod a+w isofiles/isolinux/isolinux.bin
$ genisoimage -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o debian-10-unattended.iso isofiles

8 thoughts on “Unattended Debian installation”

    1. Sorry your comment was not notified. Yes it’s the same procedure for Ubuntu and there is preseed/late_command to execute custom commands and scripts.

  1. hi Sir, i already try your tutorial its work like a charm on virtual machine, but he problem on real machine , i install the iso to usb and i got an error “no common cdrom was detected.” how to solve this issue?

    1. Hi, Honestly I don’t have a answer for you, maybe the error is related with the way in the iso was dumped to usb.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.