How to copy answers to the configuration questions for Debian packages

Human memory is sometimes unreliable, so it is not always possible to answer in the same way to the configuration questions. Fortunately, this process can be automated using debconf utilities.

How to print configuration

Use Pipe driver to print configuration settings matched by provided pattern to standard output.

$ sudo debconf-copydb configdb stdout \
    --config=Name:stdout                    \
    --config=Driver:Pipe                    \
    --config=InFd:none                      \
    --pattern='^shared/default-x-display-manager'
Name: shared/default-x-display-manager
Template: shared/default-x-display-manager
Value: slim
Owners: gdm3, slim
Flags: seen
Variables:
 choices = gdm3, slim

How to store configuration

Use File driver to store settings matched by provided pattern and in specified file.

$ sudo debconf-copydb configdb partialdb \
    --config=Name:partialdb              \
    --config=Driver:File             \
    --config=Filename:export.dat     \
    --pattern='^shared/default-x-display-manager'

How to import configuration

Import settings stored in specified file (export.dat in this example).

$ sudo debconf-copydb importmedb configdb  \
    --config=Name:importmedb               \
    --config=Driver:File              \
    --config=Filename:export.dat

Copy settings matched by provided pattern over SSH protocol to different machine.

$ sudo debconf-copydb configdb pipe                      \
    --config=Name:pipe                                   \
    --config=Driver:Pipe                                 \
    --config=InFd:none                                   \
    --pattern='^shared/default-x-display-manager'      | \
        ssh remotemachine debconf-copydb pipe configdb   \
            --config=Name:pipe                           \
            --config=Driver:Pipe

Additional notes

Available databases are defined inside /etc/debconf.conf configuration file.

I am using above-mentioned techniques inside custom built shell scripts altogether with apt-offline utility to perform initial system setup and configuration using the method shown below.

[...]
debconf-copydb defaultdb configdb       \
                --config=Name:defaultdb \
                --config=Driver:File    \
                --config=Filename:defaultdb.dat

apt-offline install --allow-unauthenticated system_packages/debian-update.zip 
apt-offline install system_packages/debian-upgrade.zip 

apt-get -y upgrade

apt-offline install system_packages/debian-packages.zip

export DEBIAN_FRONTEND=noninteractive
apt-get -y install task-desktop openbox openbox-themes obconf slim obmenu
[...]

Read debconf-copydb, debconf and debconf.conf manual pages for more information.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu