diff --git a/roles/configuration/tasks/bootloader.yml b/roles/configuration/tasks/bootloader.yml index ba3cf93..2ffee6e 100644 --- a/roles/configuration/tasks/bootloader.yml +++ b/roles/configuration/tasks/bootloader.yml @@ -34,6 +34,16 @@ register: configuration_efi_entry_result changed_when: configuration_efi_entry_result.rc == 0 + - name: Set installed OS as first EFI boot entry + ansible.builtin.shell: + cmd: >- + set -o pipefail && + efibootmgr | grep -i '{{ _efi_vendor }}' | grep -oP 'Boot\K[0-9A-F]+' | head -1 + | xargs -I{} efibootmgr -o {} + executable: /bin/bash + register: _efi_bootorder_result + changed_when: _efi_bootorder_result.rc == 0 + - name: Ensure lvm2 for non btrfs filesystems when: os == "archlinux" and system_cfg.filesystem != "btrfs" ansible.builtin.lineinfile: @@ -48,14 +58,48 @@ register: configuration_initramfs_result changed_when: configuration_initramfs_result.rc == 0 - - name: Generate grub config - vars: - configuration_grub_cfg_cmd: >- - {{ - '/usr/sbin/' + _configuration_platform.grub_mkconfig_prefix + ' -o /boot/grub2/grub.cfg' - if os_family == 'RedHat' - else '/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg' - }} - ansible.builtin.command: "{{ chroot_command }} {{ configuration_grub_cfg_cmd }}" + - name: Generate grub config (RedHat) + when: os_family == 'RedHat' + ansible.builtin.command: >- + {{ chroot_command }} /usr/sbin/{{ _configuration_platform.grub_mkconfig_prefix }} + -o /boot/grub2/grub.cfg + register: configuration_grub_result + changed_when: configuration_grub_result.rc == 0 + + - name: Fix btrfs BLS boot variable in grub config + when: + - os_family == 'RedHat' + - system_cfg.filesystem == 'btrfs' + ansible.builtin.replace: + path: /mnt/boot/grub2/grub.cfg + regexp: 'search --no-floppy --fs-uuid --set=boot \S+' + replace: 'set boot=$root' + + - name: Create EFI grub.cfg wrapper for RedHat + when: os_family == 'RedHat' + vars: + _grub2_path: >- + {{ + '/grub2' + if (partitioning_separate_boot | bool) + else ('/@/boot/grub2' if system_cfg.filesystem == 'btrfs' else '/boot/grub2') + }} + ansible.builtin.shell: + cmd: | + set -o pipefail + uuid=$(grep -m1 'search.*--set=root' /mnt/boot/grub2/grub.cfg | grep -oP '[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}') + cat > /mnt{{ partitioning_efi_mountpoint }}/EFI/{{ _efi_vendor }}/grub.cfg <