Skip to content

regenerate initramfs#1502

Closed
OmkarDeshpande7 wants to merge 1 commit intomainfrom
private/main/omkard/re-generate-initrmfs
Closed

regenerate initramfs#1502
OmkarDeshpande7 wants to merge 1 commit intomainfrom
private/main/omkard/re-generate-initrmfs

Conversation

@OmkarDeshpande7
Copy link
Copy Markdown
Collaborator

@OmkarDeshpande7 OmkarDeshpande7 commented Feb 13, 2026

What this PR does / why we need it

RCA - The VM was landing into emergency mode because the initramfs did not have virtio drivers installed, so it could not find the disk to boot even though it was attached.
Fix - This PR adds script to re-generate the initramfs within generate-mount-persistence.sh script

Which issue(s) this PR fixes

(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged)

Special notes for your reviewer

Testing done

please add testing details (logs, screenshots, etc.)


Note

High Risk
Touches boot-critical system state by modifying /etc/fstab/udev and now regenerating initramfs and rewriting GRUB config; failures could leave guests unbootable on certain distros/boot setups.

Overview
Improves post-migration boot reliability by extending generate-mount-persistence.sh --apply to regenerate the guest initramfs (via dracut, mkinitramfs, or mkinitrd) and attempt to update GRUB configuration across common BIOS/UEFI paths, with warnings when tooling/updates fail.

Also switches RunCommandInGuest to use CombinedOutput() instead of Output() so guestfish stderr is captured in errors/logging for easier debugging.

Written by Cursor Bugbot for commit 2767b73. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Contributor

@windsurf-bot windsurf-bot Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 To request another review, post a new comment with "/windsurf-review".

elif command -v mkinitramfs >/dev/null 2>&1; then
# Debian/Ubuntu - use mkinitramfs
KERNEL_VERSION=$(uname -r)
if mkinitramfs -o "/boot/initrd.img-${KERNEL_VERSION}" "$KERNEL_VERSION" 2>&1; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mkinitramfs command is being used incorrectly. The kernel version should not be passed as a positional argument.

Suggested change
if mkinitramfs -o "/boot/initrd.img-${KERNEL_VERSION}" "$KERNEL_VERSION" 2>&1; then
if mkinitramfs -o "/boot/initrd.img-${KERNEL_VERSION}" 2>&1; then

elif command -v mkinitrd >/dev/null 2>&1; then
# Older RHEL/SUSE - use mkinitrd
KERNEL_VERSION=$(uname -r)
if mkinitrd "/boot/initrd-${KERNEL_VERSION}" "$KERNEL_VERSION" 2>&1; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mkinitrd command is being used incorrectly. For most distributions, mkinitrd takes the output file and kernel version as arguments, but in the reverse order of what's shown here.

Suggested change
if mkinitrd "/boot/initrd-${KERNEL_VERSION}" "$KERNEL_VERSION" 2>&1; then
if mkinitrd "/boot/initrd-${KERNEL_VERSION}" "${KERNEL_VERSION}" 2>&1; then

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on March 11

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

fi
else
echo " -> Warning: No initramfs tool found (dracut/mkinitramfs/mkinitrd), skipping initramfs regeneration"
fi
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initramfs regeneration uses wrong kernel version via guestfish

High Severity

When this script is invoked through RunMountPersistenceScript via guestfish sh, uname -r returns the libguestfs appliance kernel version, not the guest OS kernel version. This means dracut/mkinitramfs/mkinitrd would attempt to generate an initramfs for a kernel that likely doesn't exist in the guest, causing the regeneration to either fail silently or produce an incorrect initramfs. The same issue affects the GRUB update section — /sys/firmware/efi reflects the appliance, not the guest's BIOS/UEFI mode. This defeats the core purpose of the PR (regenerating the guest's initramfs to include virtio drivers).

Additional Locations (1)

Fix in Cursor Fix in Web

break
fi
fi
done
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UEFI GRUB config written to wrong EFI path

Medium Severity

The condition [ -d "$(dirname "$GRUB_CFG")" ] matches any existing EFI vendor directory, not just the active one. The iteration order (centos → redhat → rocky → fedora) means on a Rocky Linux system with a stale /boot/efi/EFI/centos/ directory, grub2-mkconfig writes to the centos path instead of the correct rocky path, leaving the actual GRUB configuration unupdated.

Fix in Cursor Fix in Web

cmd.Stdin = strings.NewReader(command)
log.Printf("Executing %s", cmd.String()+" "+command)
out, err := cmd.Output()
out, err := cmd.CombinedOutput()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CombinedOutput mixes stderr into parsed return values

Low Severity

Changing cmd.Output() to cmd.CombinedOutput() in RunCommandInGuest means stderr from guestfish is now included in the success return value. Callers like GetInterfaceNames and GetNetworkInterfaceNames parse this output to extract filenames and interface names — any stderr warnings or informational messages could pollute the parsed results.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant