From 21b68833f431ca3569a5cbc41564bef2f2f32761 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 28 Jun 2020 22:45:16 +0200 Subject: another attempt to fix the partman recipe --- roles/installer/debian/preseed/tasks/main.yml | 7 ++ .../debian/preseed/templates/partman_config.j2 | 50 +++++++++--- .../preseed/templates/partman_early-command.sh.j2 | 34 +++++++++ .../preseed/templates/partman_raid_config.j2 | 68 ----------------- .../debian/preseed/templates/partman_ws_config.j2 | 7 ++ .../preseed_debian-buster-with-raid.cfg.j2 | 88 ---------------------- .../preseed/templates/preseed_debian-buster.cfg.j2 | 7 -- .../preseed/templates/preseed_debian-jessie.cfg.j2 | 7 -- .../templates/preseed_debian-stretch.cfg.j2 | 7 -- .../preseed/templates/preseed_ubuntu-bionic.cfg.j2 | 7 -- .../preseed/templates/preseed_ubuntu-focal.cfg.j2 | 7 -- .../preseed/templates/preseed_ubuntu-xenial.cfg.j2 | 7 -- .../templates/preseed_xubuntu-focal-desktop.cfg.j2 | 7 -- 13 files changed, 86 insertions(+), 217 deletions(-) create mode 100644 roles/installer/debian/preseed/templates/partman_early-command.sh.j2 delete mode 100644 roles/installer/debian/preseed/templates/partman_raid_config.j2 delete mode 100644 roles/installer/debian/preseed/templates/preseed_debian-buster-with-raid.cfg.j2 (limited to 'roles') diff --git a/roles/installer/debian/preseed/tasks/main.yml b/roles/installer/debian/preseed/tasks/main.yml index 46d6a1d9..53e9d225 100644 --- a/roles/installer/debian/preseed/tasks/main.yml +++ b/roles/installer/debian/preseed/tasks/main.yml @@ -10,6 +10,12 @@ src: "preseed_{{ hostvars[install_hostname].preseed_template_name | default(install_distro + '-' + install_codename) }}.cfg.j2" dest: "{{ preseed_tmpdir }}/preseed.cfg" +- name: Generate partman early-command + template: + src: "partman_early-command.sh.j2" + dest: "{{ preseed_tmpdir }}/partman_early-command.sh" + mode: 0755 + - name: Generate authorized_keys file authorized_key: user: root @@ -41,6 +47,7 @@ chdir: "{{ preseed_tmpdir }}" stdin: | preseed.cfg + partman_early-command.sh authorized_keys etc/ etc/systemd/ diff --git a/roles/installer/debian/preseed/templates/partman_config.j2 b/roles/installer/debian/preseed/templates/partman_config.j2 index 27dff5e2..ebaf180e 100644 --- a/roles/installer/debian/preseed/templates/partman_config.j2 +++ b/roles/installer/debian/preseed/templates/partman_config.j2 @@ -1,7 +1,4 @@ -d-i partman/early_command string \ - debconf-set partman-auto/disk "$(readlink -f {{ hostvars[install_hostname].install_cooked.disks.primary }})"; \ - debconf-set grub-installer/bootdev "$(readlink -f {{ hostvars[install_hostname].install_cooked.disks.primary }})"; \ - umount -l /media || true +d-i partman/early_command string /partman_early-command.sh d-i partman/confirm boolean true d-i partman/confirm_nooverwrite boolean true @@ -12,7 +9,11 @@ d-i partman-lvm/device_remove_lvm boolean true d-i partman-lvm/confirm boolean true d-i partman-lvm/confirm_nooverwrite boolean true +{% if hostvars[install_hostname].install_cooked.disks.primary == "software-raid" %} +d-i partman-auto/method string raid +{% else %} d-i partman-auto/method string lvm +{% endif %} d-i partman-auto/purge_lvm_from_device boolean true d-i partman-auto-lvm/new_vg_name string {{ hostvars[install_hostname].host_name }} d-i partman-auto-lvm/guided_size string max @@ -22,44 +23,69 @@ d-i partman-auto-lvm/no_boot boolean true d-i partman-efi/non_efi_system boolean true d-i partman/choose_label string gpt d-i partman/default_label string gpt +{% else %} +d-i partman/choose_label string dos +d-i partman/default_label string dos {% endif %} + +d-i partman-auto/choose_recipe select ansible d-i partman-auto/expert_recipe string \ - boot-root :: \ + ansible :: \ {% if (hostvars[install_hostname].install_cooked.efi | default(false)) %} 100 100 128 fat16 \ $defaultignore{ } $primary{ } $bootable{ } \ method{ efi } format{ } \ . \ +{% endif %} +{% if hostvars[install_hostname].install_cooked.disks.primary == "software-raid" %} + 256 10000 256 raid \ + $lvmignore{ } $primary{ } method{ raid } \ + . \ + 1000 10000 -1 raid \ + $lvmignore{ } $primary{ } method{ raid } \ + . \ {% endif %} 1000 10000 -1 ext4 \ $defaultignore{ } $primary{ } $bootable{ } \ method{ lvm } vg_name{ {{ hostvars[install_hostname].host_name }} } \ . \ - 2048 10000 2560 ext4 \ - $lvmok{ } in_vg{ {{ hostvars[install_hostname].host_name }} } \ + 2560 10000 2560 ext4 \ + $defaultignore{ } $lvmok{ } \ + in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ / } \ . \ - 1024 11000 1280 ext4 \ - $lvmok{ } in_vg{ {{ hostvars[install_hostname].host_name }} } \ + 1280 10000 1280 ext4 \ + $defaultignore{ } $lvmok{ } \ + in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ /var } \ . \ 768 10000 768 ext4 \ - $lvmok{ } in_vg{ {{ hostvars[install_hostname].host_name }} } \ + $defaultignore{ } $lvmok{ } \ + in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ /var/log } \ - options/nodev{ nodev } options/noatime{ noatime } \ + options/nodev{ nodev } \ + options/noatime{ noatime } \ options/noexec{ noexec } \ . \ 16 20000 -1 ext4 \ - $lvmok{ } in_vg{ {{ hostvars[install_hostname].host_name }} } \ + $defaultignore{ } $lvmok{ } \ + in_vg{ {{ hostvars[install_hostname].host_name }} } \ lv_name{ dummy } \ . + d-i partman-basicfilesystems/no_swap true d-i partman-partitioning/confirm_write_new_label boolean true d-i partman/choose_partition select finish + + +## boot devices are configured by partman/early_command +d-i grub-installer/bootdev seen true +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean false diff --git a/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 new file mode 100644 index 00000000..08d3806d --- /dev/null +++ b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 @@ -0,0 +1,34 @@ +#!/bin/sh + +umount -l /media || true + + +{% if hostvars[install_hostname].install_cooked.disks.primary == "software-raid" %} +raid_disks="$(readlink -f {{ install_cooked.disks.raid.members | join(' ') }} | xargs)" +raid_config="{{ install_cooked.disks.raid.level }} {{ install_cooked.disks.raid.members | length }} 0" + +raid_members_boot="" +raid_members_lvm="" +for disk in $raid_disks; do + [ -n "$raid_members_boot" ] && raid_members_boot="$raid_members_boot#" + [ -n "$raid_members_lvm" ] && raid_members_lvm="$raid_members_lvm#" + if echo "$disk" | grep -Eq "/dev/(s|v)d[a-z]"; then + raid_members_boot="$raid_members_boot$disk"1 + raid_members_lvm="$raid_members_lvm$disk"1 + else + raid_members_boot="$raid_members_boot$disk"p1 + raid_members_lvm="$raid_members_lvm$disk"p1 + fi +done + +debconf-set partman-auto-raid/recipe "$raid_config ext4 /boot $raid_members_boot . $raid_config lvm - $raid_members_lvm ." +debconf-set partman-auto/disk "$raid_disks" +debconf-set grub-installer/bootdev "$raid_disks" +{% else %} +debconf-set partman-auto/disk "$(readlink -f {{ hostvars[install_hostname].install_cooked.disks.primary }})" +debconf-set grub-installer/bootdev "$(readlink -f {{ hostvars[install_hostname].install_cooked.disks.primary }})" +{% endif %} + +## https://unix.stackexchange.com/questions/510445/install-grub-bootloader-dynamically-to-multiple-disks +. /usr/share/debconf/confmodule +db_fset grub-installer/bootdev seen true diff --git a/roles/installer/debian/preseed/templates/partman_raid_config.j2 b/roles/installer/debian/preseed/templates/partman_raid_config.j2 deleted file mode 100644 index 866b3b9f..00000000 --- a/roles/installer/debian/preseed/templates/partman_raid_config.j2 +++ /dev/null @@ -1,68 +0,0 @@ -d-i partman-auto/disk string /dev/sda /dev/sdb -d-i grub-installer/bootdev string /dev/sda /dev/sdb - -d-i partman/confirm boolean true -d-i partman/confirm_nooverwrite boolean true -d-i partman-md/device_remove_md boolean true -d-i partman-md/confirm boolean true -d-i partman-md/confirm_nooverwrite boolean true -d-i partman-lvm/device_remove_lvm boolean true -d-i partman-lvm/confirm boolean true -d-i partman-lvm/confirm_nooverwrite boolean true - -d-i partman-auto/method string raid -d-i partman-auto/purge_lvm_from_device boolean true -d-i partman-auto-lvm/new_vg_name string {{ hostvars[install_hostname].host_name }} -d-i partman-auto-lvm/guided_size string max - -d-i partman/choose_label string dos -d-i partman/default_label string dos -d-i partman-auto/choose_recipe select boot-root -d-i partman-auto/expert_recipe string \ - boot-root :: \ - 256 512 256 raid \ - $lvmignore{ } $primary{ } method{ raid } \ - . \ - 1000 10000 -1 raid \ - $lvmignore{ } $primary{ } method{ raid } \ - . \ - 15360 10000 20480 ext4 \ - $defaultignore{ } $lvmok{ } \ - in_vg{ {{ hostvars[install_hostname].host_name }} } \ - method{ format } format{ } \ - use_filesystem{ } filesystem{ ext4 } \ - mountpoint{ / } \ - . \ - 768 10000 768 ext4 \ - $defaultignore{ } $lvmok{ } \ - in_vg{ {{ hostvars[install_hostname].host_name }} } \ - method{ format } format{ } \ - use_filesystem{ } filesystem{ ext4 } \ - mountpoint{ /var/log } \ - options/nodev{ nodev } options/noatime{ noatime } \ - options/noexec{ noexec } \ - . \ - 20480 10000 20480 ext4 \ - $defaultignore{ } $lvmok{ } \ - in_vg{ {{ hostvars[install_hostname].host_name }} } \ - method{ format } format{ } \ - use_filesystem{ } filesystem{ ext4 } \ - mountpoint{ /home } \ - . \ - 16 20000 -1 ext4 \ - $defaultignore{ } $lvmok{ } \ - in_vg{ {{ hostvars[install_hostname].host_name }} } \ - lv_name{ dummy } \ - . - -d-i partman-auto-raid/recipe string \ - 1 2 0 ext4 /boot \ - /dev/sda1#/dev/sdb1 \ - . \ - 1 2 0 lvm - \ - /dev/sda2#/dev/sdb2 \ - . - -d-i partman-basicfilesystems/no_swap true -d-i partman-partitioning/confirm_write_new_label boolean true -d-i partman/choose_partition select finish diff --git a/roles/installer/debian/preseed/templates/partman_ws_config.j2 b/roles/installer/debian/preseed/templates/partman_ws_config.j2 index 88b3f1ec..54fe94f1 100644 --- a/roles/installer/debian/preseed/templates/partman_ws_config.j2 +++ b/roles/installer/debian/preseed/templates/partman_ws_config.j2 @@ -63,3 +63,10 @@ d-i partman-auto/expert_recipe string d-i partman-basicfilesystems/no_swap true d-i partman-partitioning/confirm_write_new_label boolean true d-i partman/choose_partition select finish + + +## boot devices are configured by partman/early_command +d-i grub-installer/bootdev seen true +d-i grub-installer/choose_bootdev seen true +d-i grub-installer/only_debian boolean true +d-i grub-installer/with_other_os boolean false diff --git a/roles/installer/debian/preseed/templates/preseed_debian-buster-with-raid.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_debian-buster-with-raid.cfg.j2 deleted file mode 100644 index 17419ce3..00000000 --- a/roles/installer/debian/preseed/templates/preseed_debian-buster-with-raid.cfg.j2 +++ /dev/null @@ -1,88 +0,0 @@ -######################################################################### -# spreadspace preseed file for Debian buster based VMs -######################################################################### - -d-i debian-installer/language string en -d-i debian-installer/country string AT -d-i debian-installer/locale string en_US.UTF-8 -d-i keyboard-configuration/xkb-keymap select us - -d-i hw-detect/load_firmware boolean false - -d-i netcfg/choose_interface select {{ install_interface | default(hostvars[install_hostname].network_cooked.primary.name) }} -{% if 'install_dhcp' in hostvars[install_hostname] and hostvars[install_hostname].install_dhcp %} -d-i netcfg/disable_dhcp boolean false -d-i netcfg/disable_autoconfig boolean false -{% else %} -d-i netcfg/disable_dhcp boolean true -d-i netcfg/disable_autoconfig boolean true -d-i netcfg/get_ipaddress string {{ hostvars[install_hostname].network_cooked.primary.address | ipaddr('address') }} -d-i netcfg/get_netmask string {{ hostvars[install_hostname].network_cooked.primary.address | ipaddr('netmask') }} -d-i netcfg/get_gateway string {{ hostvars[install_hostname].network_cooked.primary.gateway }} -d-i netcfg/get_nameservers string {{ hostvars[install_hostname].network_cooked.nameservers | join(' ') }} -d-i netcfg/confirm_static boolean true -{% endif %} - -d-i netcfg/hostname string {{ hostvars[install_hostname].host_name }} -d-i netcfg/get_hostname string {{ hostvars[install_hostname].host_name }} -d-i netcfg/domain string {{ hostvars[install_hostname].network_cooked.domain }} -d-i netcfg/get_domain string {{ hostvars[install_hostname].network_cooked.domain }} -d-i netcfg/wireless_wep string - - -d-i mirror/country string manual -d-i mirror/http/hostname string {{ apt_repo_providers[hostvars[install_hostname].apt_repo_provider].debian }} -d-i mirror/http/directory string /debian -d-i mirror/http/proxy string - - -d-i passwd/make-user boolean false -d-i passwd/root-password password this-very-very-secure-password-will-be-removed-by-latecommand -d-i passwd/root-password-again password this-very-very-secure-password-will-be-removed-by-latecommand - - -d-i clock-setup/utc boolean true -d-i time/zone string Europe/Vienna -d-i clock-setup/ntp boolean false - - -{% include 'partman_raid_config.j2' %} - - -d-i base-installer/install-recommends boolean false -d-i apt-setup/security_host string {{ apt_repo_providers[hostvars[install_hostname].apt_repo_provider].debian }} - -tasksel tasksel/first multiselect -d-i pkgsel/include string openssh-server python python-apt -d-i pkgsel/upgrade select safe-upgrade -popularity-contest popularity-contest/participate boolean false - - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - -d-i finish-install/reboot_in_progress note - - -d-i preseed/late_command string \ - lvremove -f {{ hostvars[install_hostname].host_name }}/dummy; \ - in-target bash -c "apt-get update -q && apt-get full-upgrade -y -q"; \ - in-target bash -c "sed -e 's/^allow-hotplug/auto/' -i /etc/network/interfaces"; \ -{% if preseed_force_net_ifnames_policy is defined %} - mkdir -p /target/etc/systemd/network; \ - in-target bash -c "echo '[Match]' > /etc/systemd/network/90-namepolicy.link"; \ - in-target bash -c "echo 'OriginalName=*' >> /etc/systemd/network/90-namepolicy.link"; \ - in-target bash -c "echo '' >> /etc/systemd/network/90-namepolicy.link"; \ - in-target bash -c "echo '[Link]' >> /etc/systemd/network/90-namepolicy.link"; \ - in-target bash -c "echo 'NamePolicy={{ preseed_force_net_ifnames_policy }}' >> /etc/systemd/network/90-namepolicy.link"; \ - in-target bash -c "update-initramfs -u"; \ -{% endif %} - in-target bash -c "passwd -d root && passwd -l root"; \ -{% if hostvars[install_hostname].ansible_port is defined %} - in-target bash -c "sed -e 's/^\(\s*#*\s*Port.*\)/Port {{ hostvars[install_hostname].ansible_port }}/' -i /etc/ssh/sshd_config"; \ -{% endif %} - mkdir -p -m 0700 /target/root/.ssh; \ - cp /authorized_keys /target/root/.ssh/ diff --git a/roles/installer/debian/preseed/templates/preseed_debian-buster.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_debian-buster.cfg.j2 index 8b740eef..adad515e 100644 --- a/roles/installer/debian/preseed/templates/preseed_debian-buster.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_debian-buster.cfg.j2 @@ -57,13 +57,6 @@ d-i pkgsel/include string openssh-server python python-apt d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note diff --git a/roles/installer/debian/preseed/templates/preseed_debian-jessie.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_debian-jessie.cfg.j2 index 590914a7..bd712a08 100644 --- a/roles/installer/debian/preseed/templates/preseed_debian-jessie.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_debian-jessie.cfg.j2 @@ -57,13 +57,6 @@ d-i pkgsel/include string openssh-server python python-apt d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note diff --git a/roles/installer/debian/preseed/templates/preseed_debian-stretch.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_debian-stretch.cfg.j2 index 02902b77..487e4727 100644 --- a/roles/installer/debian/preseed/templates/preseed_debian-stretch.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_debian-stretch.cfg.j2 @@ -57,13 +57,6 @@ d-i pkgsel/include string openssh-server python python-apt d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note diff --git a/roles/installer/debian/preseed/templates/preseed_ubuntu-bionic.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_ubuntu-bionic.cfg.j2 index e80d38ae..b8562e2e 100644 --- a/roles/installer/debian/preseed/templates/preseed_ubuntu-bionic.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_ubuntu-bionic.cfg.j2 @@ -66,13 +66,6 @@ d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false d-i pkgsel/update-policy select none - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note diff --git a/roles/installer/debian/preseed/templates/preseed_ubuntu-focal.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_ubuntu-focal.cfg.j2 index 8442cd31..d8208a5e 100644 --- a/roles/installer/debian/preseed/templates/preseed_ubuntu-focal.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_ubuntu-focal.cfg.j2 @@ -66,13 +66,6 @@ d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false d-i pkgsel/update-policy select none - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note diff --git a/roles/installer/debian/preseed/templates/preseed_ubuntu-xenial.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_ubuntu-xenial.cfg.j2 index d4ca1b30..0387027f 100644 --- a/roles/installer/debian/preseed/templates/preseed_ubuntu-xenial.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_ubuntu-xenial.cfg.j2 @@ -63,13 +63,6 @@ d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false d-i pkgsel/update-policy select none - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note diff --git a/roles/installer/debian/preseed/templates/preseed_xubuntu-focal-desktop.cfg.j2 b/roles/installer/debian/preseed/templates/preseed_xubuntu-focal-desktop.cfg.j2 index d3295872..4927e00b 100644 --- a/roles/installer/debian/preseed/templates/preseed_xubuntu-focal-desktop.cfg.j2 +++ b/roles/installer/debian/preseed/templates/preseed_xubuntu-focal-desktop.cfg.j2 @@ -69,13 +69,6 @@ d-i pkgsel/upgrade select safe-upgrade popularity-contest popularity-contest/participate boolean false d-i pkgsel/update-policy select none - -## grub-installer/bootdev is set by partman/early_command -d-i grub-installer/bootdev seen true -d-i grub-installer/choose_bootdev string manual -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean false - d-i finish-install/reboot_in_progress note -- cgit v1.2.3