Skip to main content

Upgrade RHEL 7 to RHEL 9 with Leapp

5 min read
#rhel #leapp #linux #hyper-v #vmware

Leapp upgrade from RHEL 7 to RHEL 8 to RHEL 9

These are the commands for my RHEL 7 to RHEL 9 in-place upgrade project.

Overview

This procedure upgrades a RHEL 7 VM to RHEL 8, then to RHEL 9, using Leapp. It works on both Hyper-V and VMware. Run each command as root unless it starts with sudo.

Marker Meaning
[Hyper-V] Run only on Hyper-V VMs
[VMware] Run only on VMware VMs
(no marker) Run on both
<VG> The real volume group name from lvs (for example vg1)
<OLDVG> The wrong VG name found in the boot args (for example rhel_template)

Most common failure: a VM cloned from a template still has the template’s VG name in its boot args. It then drops to the dracut:/# prompt after the upgrade. Step 1b catches this before the upgrade.

Part 1: RHEL 7 to RHEL 8

Step 0: Identify the hypervisor

systemd-detect-virt        # "microsoft" = Hyper-V, "vmware" = VMware

Step 1: Prep the server

  • [Hyper-V] Create a Hyper-V checkpoint.
  • [VMware] Create a VMware snapshot in vCenter.
yum update

[VMware] Check that open-vm-tools is installed:

rpm -q open-vm-tools
yum install -y open-vm-tools      # only if missing
reboot

Step 1b: Check that LVM names match the boot args

lvs                                   # note the real VG name, e.g. vg1, rhel7
grubby --info=DEFAULT                 # check rd.lvm.lv= values
grep GRUB_CMDLINE_LINUX /etc/default/grub

If rd.lvm.lv= does not match the VG from lvs (for example a leftover template name like rhel_template), fix both places before upgrading:

grubby --update-kernel=ALL \
  --remove-args="rd.lvm.lv=<OLDVG>/root rd.lvm.lv=<OLDVG>/swap" \
  --args="rd.lvm.lv=<VG>/root rd.lvm.lv=<VG>/swap"

cp /etc/default/grub /etc/default/grub.bak
vi /etc/default/grub       # change rd.lvm.lv= to <VG>/root and <VG>/swap
grubby --info=DEFAULT      # confirm
reboot                     # confirm it still boots on RHEL 7

Step 2: Install Leapp

subscription-manager release --unset   # Leapp needs no release lock
yum versionlock clear                  # only if versionlock plugin is used
subscription-manager repos --enable rhel-7-server-extras-rpms
yum install -y leapp-repository leapp

Step 3: Preupgrade

leapp preupgrade

Fix any inhibitors in the report, then run leapp preupgrade again until none remain.

Step 4: Upgrade

leapp upgrade

Check that the storage driver is in the upgrade initramfs:

# [Hyper-V]
lsinitrd /boot/initramfs-*upgrade*.img | grep hv_storvsc

# [VMware]  vmw_pvscsi = VMware Paravirtual, mptspi = LSI Logic Parallel
lsinitrd /boot/initramfs-*upgrade*.img | grep -E "vmw_pvscsi|mptspi"
reboot

Step 5: Console fix (only if it drops to dracut:/#)

  • [Hyper-V] Use the Hyper-V Manager console.
  • [VMware] Use the vCenter web or remote console.
lvm lvs
cat /proc/cmdline        # compare rd.lvm.lv= to the VG in lvm lvs
lvm vgchange -ay
exit                     # the boot continues; you can SSH in now

Step 6: Fix boot args and initramfs on RHEL 8

grubby --info=DEFAULT

Only if rd.lvm.lv= is still wrong (use the real VG name, not always rhel7):

grubby --update-kernel=DEFAULT \
  --remove-args="rd.lvm.lv=<OLDVG>/root rd.lvm.lv=<OLDVG>/swap" \
  --args="rd.lvm.lv=<VG>/root rd.lvm.lv=<VG>/swap"
grep GRUB_CMDLINE_LINUX /etc/default/grub    # must match too
grubby --info=DEFAULT

[Hyper-V] Add the Hyper-V drivers to the initramfs. [VMware] Skip this block; VMware drivers are included by default.

tee /etc/dracut.conf.d/hyperv-drivers.conf << 'EOF'
add_drivers+=" hv_vmbus hv_storvsc hv_netvsc hv_utils "
add_dracutmodules+=" lvm "
EOF

Rebuild the initramfs and check the driver:

dracut -f --no-hostonly /boot/initramfs-$(uname -r).img $(uname -r)

# [Hyper-V]
lsinitrd /boot/initramfs-$(uname -r).img | grep hv_storvsc

# [VMware]
lsinitrd /boot/initramfs-$(uname -r).img | grep -E "vmw_pvscsi|mptspi"

systemctl enable lvm2-monitor
reboot

Step 7: Finish RHEL 8

dnf update

[VMware] Confirm that VMware Tools is running, and check the VM in vCenter:

systemctl status vmtoolsd

Part 2: RHEL 8 to RHEL 9

Step 8: Prep

  • [Hyper-V] Create a Hyper-V checkpoint.
  • [VMware] Create a VMware snapshot in vCenter.
dnf update -y
grubby --info=DEFAULT                        # re-check rd.lvm.lv= matches lvs
grep GRUB_CMDLINE_LINUX /etc/default/grub
reboot

Step 9: Clean up the 7 to 8 Leapp install

rm -rf /root/tmp_leapp_py3
sudo dnf config-manager --save --setopt exclude=''
sudo dnf remove "leapp*" "python*-leapp*" -y
sudo dnf install leapp-upgrade-el8toel9 -y --allowerasing

Step 10: Preupgrade

leapp preupgrade

Fix any inhibitors in the report, then run leapp preupgrade again until none remain.

Step 11: Upgrade

leapp upgrade

# [Hyper-V]
lsinitrd /boot/initramfs-*upgrade*.img | grep hv_storvsc

# [VMware]
lsinitrd /boot/initramfs-*upgrade*.img | grep -E "vmw_pvscsi|mptspi"

reboot

Watch the console. The upgrade runs during this reboot, then the VM reboots again.

Step 12: Console fix (only if it drops to dracut:/#)

lvm lvs
cat /proc/cmdline        # compare rd.lvm.lv= to the VG in lvm lvs
lvm vgchange -ay
exit

SSH in, then repeat the Step 6 grubby and GRUB_CMDLINE_LINUX fix.

Step 13: Verify RHEL 9

cat /etc/redhat-release            # should say 9.x
uname -r                           # should end in .el9_x
grubby --info=DEFAULT              # rd.lvm.lv= still matches lvs
grep GRUB_CMDLINE_LINUX /etc/default/grub

dracut -f --no-hostonly /boot/initramfs-$(uname -r).img $(uname -r)

# [Hyper-V]
lsinitrd /boot/initramfs-$(uname -r).img | grep hv_storvsc

# [VMware]
lsinitrd /boot/initramfs-$(uname -r).img | grep -E "vmw_pvscsi|mptspi"
systemctl status vmtoolsd

Step 14: Clean up after 8 to 9

Review leftover el7 and el8 packages, including old el8 kernels. Remove them one at a time after checking they’re not needed.

rpm -qa | grep -E '\.el[78]'

Remove Leapp and its leftovers:

sudo dnf remove "leapp*" "python*-leapp*" -y
rm -rf /var/log/leapp /root/tmp_leapp_py3 /var/lib/leapp
sudo dnf config-manager --save --setopt exclude=''

Rebuild the rescue kernel entry for RHEL 9 (the old one is still el8):

rm -f /boot/vmlinuz-*rescue* /boot/initramfs-*rescue*
/usr/lib/kernel/install.d/51-dracut-rescue.install add "$(uname -r)" /boot "/boot/vmlinuz-$(uname -r)"
grubby --info=ALL | grep -i rescue   # confirm new rescue entry

Step 15: Finish RHEL 9

dnf update -y
update-crypto-policies --show        # RHEL 9 = DEFAULT, blocks SHA-1
reboot                               # final reboot to confirm clean boot

RHEL 9 blocks SHA-1 by default. Test SSH and apps that connect to older systems before removing the snapshot.

Step 16: Remove the checkpoint or snapshot

Once the VM is confirmed good:

  • [Hyper-V] Delete the Hyper-V checkpoint.
  • [VMware] Delete the VMware snapshot. Don’t keep it long-term; it keeps growing and slows the VM.