I need to know how can I add this to preseeding via d-i early/command or d-i preseed/run to set my mirror inside preseed.cfg from /proc/cmdline argument.

If I do:

d-i preseed/run string ws/ubuntu.sh

     for x in `cat /proc/cmdline`; do
             case $x in RPHOST*)
                     eval $x

                     d-i mirror/http/hostname string ${RPHOST}
                     d-i mirror/http/mirror string ${RPHOST}
                     d-i apt-setup/security_host string ${RPHOST}

it fails.

It works well in the CentOS kickstart %pre section but i have no clue how to do it via debian/ubuntu preseeding.


after some research on debconf i came up with this solution:

in your preseed.cfg you call the script via:

d-i preseed/run string ws/ubuntu.sh    // subdir from preseed file location

content of ubuntu.sh:

echo "Start ubuntu.sh runscript" >> /var/log/syslog
for x in `cat /proc/cmdline`; do
        case $x in RPHOST*)
                eval $x
                echo "d-i mirror/http/hostname string ${HOST}" > /tmp/mirror.cfg
                echo "d-i mirror/http/mirror string ${HOST}" >> /tmp/mirror.cfg
                echo "d-i apt-setup/security_host string ${HOST}" >> /tmp/mirror.cfg
// add´s values to /var/lib/cdebconf/question.dat
debconf-set-selections /tmp/mirror.cfg

works good @ 12.04.2 LTS !

  • You can also use d-i preseed/early_command instead of run. – dragon788 Aug 14 '18 at 22:23
  • Where the run actually executes is up for debate, it might be equivalent to preseed/late_command according to some open bugs, so if it doesn't work right in 16.04/18.04 try with preseed/early_command. – dragon788 Aug 15 '18 at 17:30

It sounds like you are trying to pass an arbitrary value to the kernel during a (PXE?) boot and then detect and react to it during the preseed? I think there may be better ways of accomplishing this but I'd have to know more about your specific scenario. The Cobbler project comes to mind though.

Regardless, another way to accomplish this may be to use a conditional include based on the hostname or cmdline that includes a config file with the appropriate mirror settings, as include files override values from any earlier file.

# More flexibly, this runs a shell command and if it outputs the names of
# preconfiguration files, includes those files. 
#d-i preseed/include_command \
#      string if [ "`hostname`" = bob ]; then echo bob.cfg; fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.