Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2159288

Summary: [leapp] IPU 7->8: grubenv should be checked before the reboot step
Product: Red Hat Enterprise Linux 7 Reporter: Christophe Besson <cbesson>
Component: leapp-repositoryAssignee: Leapp team <leapp-notifications>
Status: CLOSED ERRATA QA Contact: Upgrades and Supportability <upgrades-and-supportability>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.9CC: mmacura, mmoran, pstodulk
Target Milestone: rcKeywords: Reproducer
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: leapp-repository-0.18.0-1.el7_9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-17 15:00:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Christophe Besson 2023-01-09 10:30:21 UTC
Description of problem:
A customer had a /boot/efi/EFI/redhat/grubenv corrupted by a trailing line feed ('\n' or 0x0a). For some reason I can't explain, grubby was able to add the "UpgradeInitramfs" boot entry, but was not able to remove it during the reboot step.

Due to this, the upgrade falls in the emergency shell (some post-upgrade step have not been done, and the el8 initramfs has not been generated) and then it reboots on the el7 kernel (swith-to-blcfg likely failed and GRUB_ENABLE_BLSCFG is false).

Version-Release number of selected component (if applicable):
leapp-upgrade-el7toel8-0.17.0-1.el7_9.noarch

How reproducible:
Always

Steps to Reproduce:
1. echo >> /boot/efi/EFI/redhat/grubenv
2. leapp upgrade
3. reboot

Actual results:
2023-01-09 10:46:20.184 DEBUG    PID: 453 leapp.workflow.InitRamStart.remove_upgrade_boot_entry: External command has started: ['/usr/sbin/grubby', '--remove-kernel=/boot/vmlinuz-upgrade.x86_64']
2023-01-09 10:46:20.600 DEBUG    PID: 453 leapp.workflow.InitRamStart.remove_upgrade_boot_entry: grub2-editenv: error: environment block too small.
2023-01-09 10:46:20.614 DEBUG    PID: 453 leapp.workflow.InitRamStart.remove_upgrade_boot_entry: External command has finished: ['/usr/sbin/grubby', '--remove-kernel=/boot/vmlinuz-upgrade.x86_64']
 :
2023-01-09 10:50:06.97  WARNING  PID: 1529 leapp.workflow.Finalization.force_default_boot_to_target_kernel_version: Mandatory initrd /boot/initramfs-4.18.0-372.32.1.el8_6.x86_64.img does not exist


Expected results:
A check to prevent such an error.

Additional info:
- to fix the issue before the upgrade, remove the existing grubenv and regenerate it:

On UEFI: 
    # rm /boot/efi/EFI/redhat/grubenv
    # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg

On legacy BIOS:
    # rm -fv /boot/grub2/grubenv
    # grub2-mkconfig -o /boot/grub2/grub.cfg

(finally ensure the grubenv size is 1024)

- to fix the issue afterwards:

(1) edit /etc/default/grub and ensure GRUB_ENABLE_BLSCFG=true
(2) yum reinstall kernel-core
(3) remove /boot/efi/EFI/redhat/grubenv (UEFI) or /boot/grub2/grubenv (BIOS) and run `grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg` (UEFI) or `grub2-mkconfig -o /boot/grub2/grub.cfg` (BIOS).
(4) Run `grubby --info ALL` to identify the index of the el8 kernel and then set it with `grubby --set-default-index X` (replace X by the adequate value).
(5) reboot

Comment 3 Christophe Besson 2023-01-09 10:57:30 UTC
Also note the customer didn't have the proper symlinks:
- /etc/grub2.cfg was a broken symlink (expected on this EFI system)
- /etc/grub2-efi.cfg was not there

checking there is at least one resolvable symlink could prevent some issues that have already been seen.

Comment 4 Christophe Besson 2023-01-11 11:47:41 UTC
Ignore my previous message, when one symlink is not resolvable, the issue occurs when doing a `grubby --info ALL` hence that inhibits the upgrade.

For the original issue, I tried to write a patch and did a PR:
https://github.com/oamg/leapp-repository/pull/1006

I also wrote a few tests but I didn't test them :)

Comment 5 Michal Macura 2023-02-15 14:33:37 UTC
The upstream PR has been merged:
  https://github.com/oamg/leapp-repository/pull/1012

Comment 10 errata-xmlrpc 2023-05-17 15:00:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (leapp and leapp-repository bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:3187