From c750374c93682f18b4e91dec3c88dfdd1a8af3e2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 29 Jun 2020 01:28:43 +0200 Subject: simplified partman early command --- inventory/host_vars/sk-testvm.yml | 9 +++++-- roles/installer/debian/preseed/tasks/main.yml | 2 +- .../debian/preseed/templates/partman_config.j2 | 28 ++++++++++++---------- .../preseed/templates/partman_early-command.sh.j2 | 17 +++++++------ roles/vm/define/templates/libvirt-domain.xml.j2 | 2 +- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/inventory/host_vars/sk-testvm.yml b/inventory/host_vars/sk-testvm.yml index c61dc4e1..63538708 100644 --- a/inventory/host_vars/sk-testvm.yml +++ b/inventory/host_vars/sk-testvm.yml @@ -5,11 +5,16 @@ install: numcpu: 1 autostart: False disks: - primary: /dev/sda + primary: software-raid + raid: + level: 1 + members: + - /dev/sda + - /dev/sdb scsi: sda: type: zfs - name: root + name: root1 size: 10g sdb: type: zfs diff --git a/roles/installer/debian/preseed/tasks/main.yml b/roles/installer/debian/preseed/tasks/main.yml index 53e9d225..599d9ddb 100644 --- a/roles/installer/debian/preseed/tasks/main.yml +++ b/roles/installer/debian/preseed/tasks/main.yml @@ -10,7 +10,7 @@ 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 +- name: Generate partmam early-command script template: src: "partman_early-command.sh.j2" dest: "{{ preseed_tmpdir }}/partman_early-command.sh" diff --git a/roles/installer/debian/preseed/templates/partman_config.j2 b/roles/installer/debian/preseed/templates/partman_config.j2 index ebaf180e..2d125b50 100644 --- a/roles/installer/debian/preseed/templates/partman_config.j2 +++ b/roles/installer/debian/preseed/templates/partman_config.j2 @@ -1,3 +1,4 @@ +{# https://unix.stackexchange.com/questions/510445/install-grub-bootloader-dynamically-to-multiple-disks #} d-i partman/early_command string /partman_early-command.sh d-i partman/confirm boolean true @@ -9,11 +10,6 @@ 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 @@ -28,35 +24,44 @@ d-i partman/choose_label string dos d-i partman/default_label string dos {% endif %} + +{% 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/choose_recipe select ansible d-i partman-auto/expert_recipe string \ ansible :: \ {% if (hostvars[install_hostname].install_cooked.efi | default(false)) %} 100 100 128 fat16 \ - $defaultignore{ } $primary{ } $bootable{ } \ + $primary{ } $bootable{ } \ method{ efi } format{ } \ . \ {% endif %} {% if hostvars[install_hostname].install_cooked.disks.primary == "software-raid" %} 256 10000 256 raid \ - $lvmignore{ } $primary{ } method{ raid } \ + $lvmignore{ } $primary{ } $bootable{ } \ + method{ raid } \ . \ 1000 10000 -1 raid \ - $lvmignore{ } $primary{ } method{ raid } \ + $lvmignore{ } $primary{ } \ + method{ raid } \ . \ {% endif %} 1000 10000 -1 ext4 \ $defaultignore{ } $primary{ } $bootable{ } \ method{ lvm } vg_name{ {{ hostvars[install_hostname].host_name }} } \ . \ - 2560 10000 2560 ext4 \ + 2048 10000 2560 ext4 \ $defaultignore{ } $lvmok{ } \ in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ / } \ . \ - 1280 10000 1280 ext4 \ + 1024 10000 1280 ext4 \ $defaultignore{ } $lvmok{ } \ in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ @@ -86,6 +91,5 @@ 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 +d-i grub-installer/with_other_os boolean true diff --git a/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 index 08d3806d..9c720e92 100644 --- a/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 +++ b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 @@ -4,30 +4,29 @@ 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" +disks="{% for disk in hostvars[install_hostname].install_cooked.disks.raid.members %}$(readlink -f {{ disk }}) {% endfor %}" raid_members_boot="" raid_members_lvm="" -for disk in $raid_disks; do +for disk in $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 + raid_members_lvm="$raid_members_lvm$disk"2 else raid_members_boot="$raid_members_boot$disk"p1 - raid_members_lvm="$raid_members_lvm$disk"p1 + raid_members_lvm="$raid_members_lvm$disk"p2 fi done +raid_config="{{ hostvars[install_hostname].install_cooked.disks.raid.level }} {{ hostvars[install_hostname].install_cooked.disks.raid.members | length }} 0" 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 }})" +disks="$(readlink -f {{ hostvars[install_hostname].install_cooked.disks.primary }})" {% endif %} +debconf-set partman-auto/disk "$disks" +debconf-set grub-installer/bootdev "$disks" ## https://unix.stackexchange.com/questions/510445/install-grub-bootloader-dynamically-to-multiple-disks . /usr/share/debconf/confmodule diff --git a/roles/vm/define/templates/libvirt-domain.xml.j2 b/roles/vm/define/templates/libvirt-domain.xml.j2 index af9fbf52..be2fd8b4 100644 --- a/roles/vm/define/templates/libvirt-domain.xml.j2 +++ b/roles/vm/define/templates/libvirt-domain.xml.j2 @@ -9,7 +9,7 @@ {% if install_distro == 'debian' or install_distro == 'ubuntu' %} {{ installer_path }}/{{ install_distro }}-{{ install_codename }}/{{ hostvars[install_hostname].install_cooked.arch | default('amd64') }}/linux {{ preseed_tmpdir }}/initrd.preseed.gz - console=ttyS0,115200n8 + console=ttyS0,115200n8 DEBCONF_DEBUG=5 {% elif install_distro == 'openbsd' %} -- cgit v1.2.3