Skip to content

Commit ca192e2

Browse files
priteaucityofships
authored andcommitted
Fix issue with GRUB defaulting to an old kernel
On some Rocky Linux 9 deployments, we are seeing GRUB defaulting to the old kernel included in the DIB image, even after newer kernels have been installed. This appears to be related to the presence of Boot Loader Specification (BLS) entries with a machine ID lower in alphabetical order than the current one: [stack@host ~]$ sudo cat /etc/machine-id cd3361a338fe47348de9937e51a7a4aa [stack@host ~]$ sudo ls -l /boot/loader/entries/ total 20 -rw-r--r--. 1 root root 449 Mar 31 2023 104a42359fae41b687caac066397aec2-0-rescue.conf -rw-r--r--. 1 root root 397 Mar 31 2023 104a42359fae41b687caac066397aec2-5.14.0-162.22.2.el9_1.x86_64.conf -rw-r--r-- 1 root root 446 Jun 9 2023 cd3361a338fe47348de9937e51a7a4aa-0-rescue.conf -rw-r--r-- 1 root root 422 Jun 9 2023 cd3361a338fe47348de9937e51a7a4aa-5.14.0-284.11.1.el9_2.x86_64.conf -rw-r--r-- 1 root root 422 Jan 9 09:40 cd3361a338fe47348de9937e51a7a4aa-5.14.0-284.30.1.el9_2.x86_64.conf Add a new `reset-bls-entries.yml` playbook which will rename existing BLS entries using the current machine ID. This should prompt Grub to pick the most recent kernel on next reboot.
1 parent e1a64bd commit ca192e2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# Custom playbook to reset Boot Loader Specification (BLS) entries to resolve
3+
# an issue with GRUB defaulting to an old kernel. This is adapted from a Bash
4+
# script in diskimage-builder:
5+
# https://opendev.org/openstack/diskimage-builder/src/branch/master/diskimage_builder/elements/rhel/post-install.d/03-reset-bls-entries
6+
7+
- name: Reset BLS entries
8+
hosts: overcloud
9+
become: true
10+
tags:
11+
- reset-bls-entries
12+
tasks:
13+
- name: Get machine ID
14+
command: cat /etc/machine-id
15+
register: machine_id
16+
check_mode: false
17+
18+
- name: Find entries with wrong machine ID
19+
ansible.builtin.find:
20+
paths: /boot/loader/entries
21+
patterns: "*.conf"
22+
register: bls_entries
23+
check_mode: false
24+
25+
# We set force to false to avoid replacing an existing BLS entry with the
26+
# correct machine ID.
27+
- name: Rename entries with wrong machine ID
28+
copy:
29+
src: "/boot/loader/entries/{{ item }}"
30+
dest: "/boot/loader/entries/{{ item | ansible.builtin.regex_replace('^[a-f0-9]*', machine_id.stdout) }}"
31+
force: false
32+
remote_src: true
33+
with_items: "{{ bls_entries.files | map(attribute='path') | reject('search', machine_id.stdout) | map('basename') }}"
34+
35+
- name: Remove entries with wrong machine ID
36+
file:
37+
path: "/boot/loader/entries/{{ item }}"
38+
state: absent
39+
with_items: "{{ bls_entries.files | map(attribute='path') | reject('search', machine_id.stdout) | map('basename') }}"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Add a new ``reset-bls-entries.yml`` custom playbook which will rename
5+
existing Boot Loader Specification (BLS) entries using the current machine
6+
ID for each host. This should fix an issue with Grub not selecting the most
7+
recent kernel during boot.

0 commit comments

Comments
 (0)