forked from msvsphere/cloud-images
parent
6884e279dd
commit
e362d41997
@ -0,0 +1,44 @@
|
|||||||
|
Unify Bootloader Configuration
|
||||||
|
=========
|
||||||
|
|
||||||
|
Unify bootloader configuration to support BIOS and UEFI boot at the same time.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||||
|
|
||||||
|
- name: AlmaLinux Generic Cloud
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- role: unified_boot
|
||||||
|
when: is_unified_boot is defined
|
||||||
|
- gencloud_guest
|
||||||
|
- cleanup_vm
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
GPL-3.0-only
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Cloud Special Interest Group (Cloud SIG) of AlmaLinux OS Foundation
|
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
unified_boot_kernel_opts: console=tty0 console=ttyS0,115200n8 no_timer_check biosdevname=0 net.ifnames=0
|
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
galaxy_info:
|
||||||
|
author: AlmaLinux OS Cloud SIG
|
||||||
|
description: Unify bootloader configuration for BIOS and UEFI support
|
||||||
|
company: AlmaLinux OS Foundation
|
||||||
|
license: GPL-3.0-only
|
||||||
|
min_ansible_version: 2.13.9
|
||||||
|
galaxy_tags:
|
||||||
|
- unifiedboot
|
||||||
|
- bios
|
||||||
|
- uefi
|
@ -0,0 +1,115 @@
|
|||||||
|
---
|
||||||
|
# We do this as a part on kickstart files
|
||||||
|
# - name: Install GRUB for BIOS
|
||||||
|
# ansible.builtin.dnf:
|
||||||
|
# name: grub2-pc
|
||||||
|
# state: present
|
||||||
|
|
||||||
|
# - name: Find root disk
|
||||||
|
# ansible.builtin.command:
|
||||||
|
# cmd: grub2-probe --target=disk /boot/grub2
|
||||||
|
# register: root_disk
|
||||||
|
# changed_when: false
|
||||||
|
#
|
||||||
|
# - name: Install GRUB for BIOS
|
||||||
|
# ansible.builtin.command:
|
||||||
|
# cmd: grub2-install --target=i386-pc {{ root_disk.stdout }}
|
||||||
|
# creates: /boot/grub2/i386-pc
|
||||||
|
|
||||||
|
- name: Get UUID of boot partition
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: grub2-probe --target=fs_uuid /boot/grub2
|
||||||
|
register: boot_uuid
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Get UUID of root partition
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: findmnt -n -o UUID /
|
||||||
|
register: root_uuid
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Generate GRUB2 stub configuration
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: grub_cfg_stub.j2
|
||||||
|
dest: /boot/efi/EFI/almalinux/grub.cfg
|
||||||
|
mode: "0700"
|
||||||
|
|
||||||
|
- name: Generate GRUB2 main configuration
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: grub_cfg_main.j2
|
||||||
|
dest: /boot/grub2/grub.cfg
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
|
- name: Remove symlink of GRUB2 environment block
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /boot/grub2/grubenv
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Remove old GRUB2 environment block on ESP
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /boot/efi/EFI/almalinux/grubenv
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Get version of installed kernel # noqa: command-instead-of-module
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: rpm -qa --queryformat "%{VERSION}-%{RELEASE}.%{ARCH}" kernel
|
||||||
|
register: kernel_ver
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Read machine ID
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
src: /etc/machine-id
|
||||||
|
register: machine_id_base64
|
||||||
|
|
||||||
|
- name: Store machine ID
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
machine_id: "{{ machine_id_base64['content'] | b64decode | trim }}"
|
||||||
|
|
||||||
|
- name: Remove old GRUB2 environment block
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /boot/grub2/grubenv
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
# The kernelopts is only needed for AlmaLinux OS 8
|
||||||
|
- name: Generate new GRUB2 environment block
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: >
|
||||||
|
grub2-editenv -v - set
|
||||||
|
kernelopts="root=UUID={{ root_uuid.stdout }}
|
||||||
|
{{ unified_boot_kernel_opts }}"
|
||||||
|
saved_entry={{ machine_id }}-{{ kernel_ver.stdout }}
|
||||||
|
creates: /boot/grub2/grubenv
|
||||||
|
|
||||||
|
- name: Set permissions of new GRUB2 environment block
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /boot/grub2/grubenv
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0600"
|
||||||
|
|
||||||
|
# Test if the size of GRUB2 environment block is correct
|
||||||
|
- name: Get size of GRUB2 environment block
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /boot/grub2/grubenv
|
||||||
|
register: grubenv
|
||||||
|
|
||||||
|
- name: Check if file size of GRUB2 environment block is 1024 bytes
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- grubenv.stat.size == 1024
|
||||||
|
fail_msg: The file size of GRUB2 environment block is not 1024 bytes
|
||||||
|
success_msg: The file size of GRUB2 environment block is 1024 bytes
|
||||||
|
|
||||||
|
# Test if grubby is able to identify absolute path of default kernel
|
||||||
|
- name: Get absolute path of default kernel using grubby
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: grubby --default-kernel
|
||||||
|
register: default_kernel_path
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Check if grubby can correctly identify the default kernel
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- default_kernel_path.stdout == "/boot/vmlinuz-" ~ kernel_ver.stdout
|
||||||
|
fail_msg: Grubby could not found the absolute path of default kernel
|
||||||
|
success_msg: Grubby correctly identify the absolute path of default kernel
|
@ -0,0 +1,25 @@
|
|||||||
|
set timeout=0
|
||||||
|
|
||||||
|
# load the grubenv file
|
||||||
|
load_env
|
||||||
|
|
||||||
|
# selection of the next boot entry via variables 'next_entry' and
|
||||||
|
# `saved_entry` present in the 'grubenv' file. Both variables are
|
||||||
|
# set by grub tools, like grub2-reboot, grub2-set-default
|
||||||
|
|
||||||
|
if [ "${next_entry}" ] ; then
|
||||||
|
set default="${next_entry}"
|
||||||
|
set next_entry=
|
||||||
|
save_env next_entry
|
||||||
|
set boot_once=true
|
||||||
|
else
|
||||||
|
set default="${saved_entry}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
search --no-floppy --set=root --fs-uuid {{ boot_uuid.stdout }}
|
||||||
|
set boot=${root}
|
||||||
|
function load_video {
|
||||||
|
insmod all_video
|
||||||
|
}
|
||||||
|
${serial}${terminal_input}${terminal_output}
|
||||||
|
blscfg
|
@ -0,0 +1,4 @@
|
|||||||
|
search --no-floppy --fs-uuid --set=dev {{ boot_uuid.stdout }}
|
||||||
|
set prefix=($dev)/grub2
|
||||||
|
export $prefix
|
||||||
|
configfile $prefix/grub.cfg
|
Loading…
Reference in new issue