Debian Preseeded install medium

After the configuration of my servers through Saltstack, I decided to go furter and to also store the configuration to my laptops and home computed into Saltstack and thus allow an easy way to format and get a fully configured system back in place really easily and quickly.

First step was to get a quick way of formatting my computers without or with only minimal human intervention. As I’m using Debian, it means preparing a preseeded installation file so that everything is taken care of.

I tried some approaches to build manually an install image but as I went along, I decided to scratch all that and script the build of this medium. I looked around and found existing work by acatton on GitHub.

There were a number of problems I wanted to fix :

  1. The hostname should be provided by the user on build
  2. A default user account should be created
  3. Or perhaps not and the user would have to input something during the install
  4. I wanted an encrypted root partition by default
  5. I wanted to install a Saltstack minion by default
  6. I needed to copy default configuration files

The encryption and installation of a minion were easy tasks and only need edition of the preseed file. The other points introduced the need for a templating script that could generate different files as needed and using user input during the generation of the medium.

As I already knew the Mustache syntax, I decided to use Mustache as a templating engine to generate the needed preseed files. Instead of copying the preseed file from the folder into the generated medium image, I sent it through mo with various variables to get 4 different install seeds.

cat "$PRESEED" | SUITE="jessie"  TARGETNAME=$HOSTNAME CREATEUSER=1 ./mo > "$TMP/preseed-jessie-autouser.cfg"
cat "$PRESEED" | SUITE="stretch" TARGETNAME=$HOSTNAME CREATEUSER=1 ./mo > "$TMP/preseed-stretch-autouser.cfg"

unset CREATEUSER

cat "$PRESEED" | SUITE="jessie"  TARGETNAME=$HOSTNAME              ./mo > "$TMP/preseed-jessie-manualuser.cfg"
cat "$PRESEED" | SUITE="stretch" TARGETNAME=$HOSTNAME              ./mo > "$TMP/preseed-stretch-manualuser.cfg"

And then, I changed the isolinux/txt.cfg configuration file to get an entry for each configuration file.

cat >> isolinux/txt.cfg <<EOE
label install-jessie-manualuser
	menu label ^Install Jessie $HOSTNAME (manual user)
	kernel /install.amd/vmlinuz
	append vga=788 initrd=/install.amd/initrd.gz auto=true file=/cdrom/preseed-jessie-manualuser.cfg
EOE

cat >> isolinux/txt.cfg <<EOE
label install-jessie-autouser
	menu label ^Install Jessie $HOSTNAME (auto Valdor user)
	kernel /install.amd/vmlinuz
	append vga=788 initrd=/install.amd/initrd.gz auto=true file=/cdrom/preseed-jessie-autouser.cfg
EOE

cat >> isolinux/txt.cfg <<EOE
label install-stretch-autouser
	menu label ^Install Stretch $HOSTNAME (manual user)
	kernel /install.amd/vmlinuz
	append vga=788 initrd=/install.amd/initrd.gz auto=true file=/cdrom/preseed-stretch-manualuser.cfg
EOE

cat >> isolinux/txt.cfg <<EOE
label install-stretch-autouser
	menu label ^Install Stretch $HOSTNAME (auto Valdor user)
	kernel /install.amd/vmlinuz
	append vga=788 initrd=/install.amd/initrd.gz auto=true file=/cdrom/preseed-stretch-autouser.cfg
EOE

The Saltstack minion is installed by the preseed d-i pkgsel/include string salt-minion plymouth plymouth-themes directive and with the configuration file also copied at the end of the install with d-i preseed/late_command string cp -a /cdrom/preseed/minion /target/etc/salt/. The only manual interaction needed is to accept the minion key after the reboot and let Saltstack up the newly installed computer.