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 --- .../preseed/templates/partman_early-command.sh.j2 | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 roles/installer/debian/preseed/templates/partman_early-command.sh.j2 (limited to 'roles/installer/debian/preseed/templates/partman_early-command.sh.j2') 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 -- cgit v1.2.3 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(-) (limited to 'roles/installer/debian/preseed/templates/partman_early-command.sh.j2') 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 From ee6843f01f382ac81a6ea48f7c3c074e56b5a996 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 2 Jul 2020 02:00:06 +0200 Subject: another attempt to tackle root_lvm_size issue --- inventory/host_vars/sk-testvm.yml | 26 ++++++------ .../debian/preseed/templates/partman_config.j2 | 48 ++++++++++++++++------ .../preseed/templates/partman_early-command.sh.j2 | 6 +++ 3 files changed, 55 insertions(+), 25 deletions(-) (limited to 'roles/installer/debian/preseed/templates/partman_early-command.sh.j2') diff --git a/inventory/host_vars/sk-testvm.yml b/inventory/host_vars/sk-testvm.yml index cad79e49..73012082 100644 --- a/inventory/host_vars/sk-testvm.yml +++ b/inventory/host_vars/sk-testvm.yml @@ -5,21 +5,23 @@ install: numcpus: 1 autostart: False disks: - primary: software-raid - raid: - level: 1 - members: - - /dev/sda - - /dev/sdb + # primary: software-raid + # raid: + # level: 1 + # members: + # - /dev/sda + # - /dev/sdb + primary: /dev/sda + root_lvm_size: 10G scsi: sda: type: zfs - name: root1 - size: 10g - sdb: - type: zfs - name: root2 - size: 10g + name: root + size: 20g + # sdb: + # type: zfs + # name: root2 + # size: 10g interfaces: - bridge: br-public name: primary0 diff --git a/roles/installer/debian/preseed/templates/partman_config.j2 b/roles/installer/debian/preseed/templates/partman_config.j2 index 2d125b50..88b6a088 100644 --- a/roles/installer/debian/preseed/templates/partman_config.j2 +++ b/roles/installer/debian/preseed/templates/partman_config.j2 @@ -19,9 +19,17 @@ 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 +d-i partman-partitioning/choose_label string gpt +d-i partman-partitioning/default_label string gpt +d-i partman-basicfilesystems/choose_label string gpt +d-i partman-basicfilesystems/default_label string gpt {% else %} -d-i partman/choose_label string dos -d-i partman/default_label string dos +d-i partman/choose_label string msdos +d-i partman/default_label string msdos +d-i partman-partitioning/choose_label string msdos +d-i partman-partitioning/default_label string msdos +d-i partman-basicfilesystems/choose_label string msdos +d-i partman-basicfilesystems/default_label string msdos {% endif %} @@ -31,44 +39,56 @@ d-i partman-auto/method string raid 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 \ + 128 128 128 fat16 \ $primary{ } $bootable{ } \ method{ efi } format{ } \ . \ {% endif %} {% if hostvars[install_hostname].install_cooked.disks.primary == "software-raid" %} - 256 10000 256 raid \ + 256 256 256 raid \ $lvmignore{ } $primary{ } $bootable{ } \ method{ raid } \ . \ - 1000 10000 -1 raid \ + 10240 10340 -1 raid \ $lvmignore{ } $primary{ } \ method{ raid } \ . \ -{% endif %} - 1000 10000 -1 ext4 \ - $defaultignore{ } $primary{ } $bootable{ } \ +{% else %} +{% if 'root_lvm_size' in hostvars[install_hostname].install_cooked.disks and hostvars[install_hostname].install_cooked.disks.root_lvm_size != 'all' %} +{% set root_lvm_size = ((hostvars[install_hostname].install_cooked.disks.root_lvm_size | human_to_bytes) / (1024*1024)) | int %} + {{ root_lvm_size }} {{ root_lvm_size }} {{ root_lvm_size }} lvm \ + $defaultignore{ } $primary{ } \ method{ lvm } vg_name{ {{ hostvars[install_hostname].host_name }} } \ . \ - 2048 10000 2560 ext4 \ + 8 108 -1 ext4 \ + $defaultignore{ } $primary{ } \ + method{ unused } \ + . \ +{% else %} + 5120 5120 5120 lvm \ + $defaultignore{ } $primary{ } \ + method{ lvm } vg_name{ {{ hostvars[install_hostname].host_name }} } \ + . \ +{% endif %} +{% endif %} + 2560 2560 2560 ext4 \ $defaultignore{ } $lvmok{ } \ in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ / } \ . \ - 1024 10000 1280 ext4 \ + 1280 1280 1280 ext4 \ $defaultignore{ } $lvmok{ } \ in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ use_filesystem{ } filesystem{ ext4 } \ mountpoint{ /var } \ . \ - 768 10000 768 ext4 \ + 768 768 768 ext4 \ $defaultignore{ } $lvmok{ } \ in_vg{ {{ hostvars[install_hostname].host_name }} } \ method{ format } format{ } \ @@ -78,13 +98,15 @@ d-i partman-auto/expert_recipe string options/noatime{ noatime } \ options/noexec{ noexec } \ . \ - 16 20000 -1 ext4 \ + 8 108 -1 ext4 \ $defaultignore{ } $lvmok{ } \ in_vg{ {{ hostvars[install_hostname].host_name }} } \ lv_name{ dummy } \ + method{ unused } \ . + 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_early-command.sh.j2 b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 index 9c720e92..6187fbea 100644 --- a/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 +++ b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 @@ -31,3 +31,9 @@ debconf-set grub-installer/bootdev "$disks" ## https://unix.stackexchange.com/questions/510445/install-grub-bootloader-dynamically-to-multiple-disks . /usr/share/debconf/confmodule db_fset grub-installer/bootdev seen true + + +## wipe existing partition tables, 1M should be enough to get rid of them +for disk in $disks; do + dd if=/dev/zero "of=$disk" bs=32768 count=32 +done -- cgit v1.2.3 From 2f00ada542d9ac3c29ce3d6af9a2fad994413d09 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 3 Jul 2020 01:52:18 +0200 Subject: preseed: software-raid with root_lvm_size works now --- roles/installer/debian/preseed/templates/partman_config.j2 | 14 +++++++++++++- .../debian/preseed/templates/partman_early-command.sh.j2 | 6 ------ 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'roles/installer/debian/preseed/templates/partman_early-command.sh.j2') diff --git a/roles/installer/debian/preseed/templates/partman_config.j2 b/roles/installer/debian/preseed/templates/partman_config.j2 index 88b6a088..ca6feb41 100644 --- a/roles/installer/debian/preseed/templates/partman_config.j2 +++ b/roles/installer/debian/preseed/templates/partman_config.j2 @@ -52,10 +52,22 @@ d-i partman-auto/expert_recipe string $lvmignore{ } $primary{ } $bootable{ } \ method{ raid } \ . \ - 10240 10340 -1 raid \ +{% if 'root_lvm_size' in hostvars[install_hostname].install_cooked.disks and hostvars[install_hostname].install_cooked.disks.root_lvm_size != 'all' %} +{% set root_lvm_size = ((hostvars[install_hostname].install_cooked.disks.root_lvm_size | human_to_bytes) / (1024*1024)) | int %} + {{ root_lvm_size }} {{ root_lvm_size }} {{ root_lvm_size }} raid \ $lvmignore{ } $primary{ } \ method{ raid } \ . \ + 8 108 -1 ext4 \ + $lvmignore{ } $primary{ } \ + method{ unused } \ + . \ +{% else %} + 5120 5120 5120 raid \ + $lvmignore{ } $primary{ } \ + method{ raid } \ + . \ +{% endif %} {% else %} {% if 'root_lvm_size' in hostvars[install_hostname].install_cooked.disks and hostvars[install_hostname].install_cooked.disks.root_lvm_size != 'all' %} {% set root_lvm_size = ((hostvars[install_hostname].install_cooked.disks.root_lvm_size | human_to_bytes) / (1024*1024)) | int %} 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 6187fbea..9c720e92 100644 --- a/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 +++ b/roles/installer/debian/preseed/templates/partman_early-command.sh.j2 @@ -31,9 +31,3 @@ debconf-set grub-installer/bootdev "$disks" ## https://unix.stackexchange.com/questions/510445/install-grub-bootloader-dynamically-to-multiple-disks . /usr/share/debconf/confmodule db_fset grub-installer/bootdev seen true - - -## wipe existing partition tables, 1M should be enough to get rid of them -for disk in $disks; do - dd if=/dev/zero "of=$disk" bs=32768 count=32 -done -- cgit v1.2.3