Ubuntu 18.04 installer - select seed file based on condition

I have an ISO installation of ubuntu 18.04 which has a txt.cfg file in it.

the txt.cfg has 4 options in it, and a preseed file is selected based on the option chosen:

label option1
  menu option1
  kernel /install/vmlinuz
  append  file=/cdrom/option1.seed vga=788 initrd=/install/initrd.gz ...

label option2
  menu option2
  kernel /install/vmlinuz
  append  file=/cdrom/option2.seed vga=788 initrd=/install/initrd.gz ...

each of the seed files (in this example, option1.seed & option2.seed) sets up the partitions differently using d-i partman-auto/expert_recipe string.

Instead of the user having to choose the suitable partitioning option for him, I wrote a bash script which according to different parameters of the machine (CPU, RAM, etc..) can tell which option is suitable.

How can I run a bash script as part of the .cfg file or somewhere in the .seed file?

I saw usages of d-i preseed/late_command and d-i preseed/early_command but not sure how do use them.


I think the txt.cfg is a config for SYSLINUX/ISOLINUX. I don't think it is capable of the dynamic options you are looking for.

I suggest using early_command to copy an appropriate recipe to a specific path used by the preseed expert_recipe_file option. The same preseed file is used for all installs, but the recipe file can be chosen based on whatever logic is desired.

For example, I will use options similar to these in my preseed file to choose either a UEFI or BIOS based recipe.

d-i preseed/early_command string \
  if [ -d /sys/firmware/efi/ -o -d /proc/efi ]; then \
    cp /cdrom/recipe_efi  /run/my_recipe ; \
  else \
    cp /cdrom/recipe_bios /run/my_recipe ; \
  fi ;

d-i partman-auto/expert_recipe_file string /run/my_recipe