diff --git a/articles/2017-02-25-preseededdebian.md b/articles/2017-02-25-preseededdebian.md new file mode 100644 index 0000000..c677a35 --- /dev/null +++ b/articles/2017-02-25-preseededdebian.md @@ -0,0 +1,151 @@ +--- +title: Preseeded Debian Install +date: 2017-02-25 22:00:00 +--- + +Since I tend to reinstall my laptop quite often -each time I have to use it +for work more or less-, I wanted to automate a large portion of the +installation process, from the installation itself to the configuration. + +I delegated the configuration part to SaltStack, which I will cover in a +future post, once I figured out everything I needed. This first part will +cover the Debian installation, using the *preseed* mechanism that is available +in the Debian Installer. + +Preseeding a Debian install allows the installer to skip questions that +are already answered in the preseed file, to install packages, etc... + +Here is an example of a preseed file that is generated by the current +version of the build script + +``` +## Localization +d-i debian-installer/language string en +d-i debian-installer/country string GB +d-i debian-installer/locale string en_GB.UTF-8 + +## Keyboard selection. +d-i keyboard-configuration/xkb-keymap select ch(fr) + +## Network configuration +d-i netcfg/choose_interface select auto + +d-i netcfg/get_hostname string debian +d-i netcfg/get_domain string srv.inf3.ch + +d-i netcfg/hostname string debian +d-i netcfg/domain string + +## Account setup +# No root login (Use sudo) +d-i passwd/root-login boolean false + +# Create the "administrator" user +d-i passwd/user-fullname string valdor +d-i passwd/username string valdor + +d-i passwd/user-password password valdor +d-i passwd/user-password-again password valdor + +## Time configuration +d-i clock-setup/utc boolean true +d-i time/zone string Europe/Zurich +d-i clock-setup/ntp boolean true +d-i clock-setup/ntp-server string 0.debian.pool.ntp.org + +## Partitioning +d-i partman-auto/method string crypto + +d-i partman-lvm/device_remove_lvm boolean true +d-i partman-md/device_remove_md 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-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 + +d-i partman-md/confirm boolean true +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 + +## Base system installation +d-i mirror/country string manual +d-i mirror/http/hostname string httpredir.debian.org +d-i mirror/http/directory string /debian/ +d-i mirror/http/proxy string + +d-i mirror/suite string jessie + +## Apt setup +d-i apt-setup/non-free boolean false +d-i apt-setup/contrib boolean false + +d-i apt-setup/services-select multiselect security, updates +d-i apt-setup/security_host string security.debian.org + +## Package selection +tasksel tasksel/first multiselect standard ssh-server + +d-i pkgsel/include string salt-minion plymouth plymouth-themes +d-i pkgsel/upgrade select full-upgrade + +# Lets just help debian know which packages are important and used +popularity-contest popularity-contest/participate boolean true + +## Boot loader installation +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean true +d-i grub-installer/bootdev string default + +## Finishing up the installation +# Avoid that last message about the install being complete. +d-i finish-install/reboot_in_progress note + +# Copy minion configuration file +d-i preseed/late_command string cp -a /cdrom/preseed/minion /target/etc/salt/; cp -ar /cdrom/preseed /target/home +``` + +This preseed file will discard everything on the hard-drives, create an +encrypted setup (this will be the only input needed during the installation, +to get a password for the encrypted root), create the user with a default +password which will be changed on first boot by SaltStack, install the +Salt minion and the needed configuration file, ... + +But as I wanted to create an installation medium that can be reused to +install other computers, such as my workstation or other playthings, I +needed to find a tool that can generate an USB installer easily. After +some searches, I found a script by [Antoine Catton](https://github.com/acatton/debian-preseeded-iso) +that can generate ISO files using a Debian official ISO. + +I had to change the build script to add parts that I needed for my project, +such as the capability to generate multiple preseed configuration files +using a Mustache template so that I can select whether I want to create an +user automatically or if I want to use Debian Jessie or Debian Stretch +for example. The final scripts can be found on my [Git repository](https://bitbucket.org/tschwery/debian-preseeded-iso). + +The mechanism is really simple and uses Mustache to generate a number of +preseed files based on a template. Every generated file is then added to +the ISOLINUX menu configuration. The only difference between the entries, +apart from the title, is the preseed configuration that is passed to the +installer. + +``` +label install-stretch-autouser + menu label ^Install Stretch $TARGETNAME (auto user) + kernel /install.amd/vmlinuz + append vga=788 initrd=/install.amd/initrd.gz auto=true file=/cdrom/preseed-stretch-autouser.cfg +``` + +This allows me to generate install medium easily, without special tools. +The generated ISO can be used for a physical computer after burning the +ISO to an USB key, or for a virtual machine using directly the ISO file +as a virtual CD. + +The script is available on my [Git repository](https://bitbucket.org/tschwery/debian-preseeded-iso) +and will be kept updated as needed.