regenerate initramfs#1502
Conversation
| 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 |
There was a problem hiding this comment.
The mkinitramfs command is being used incorrectly. The kernel version should not be passed as a positional argument.
| 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 |
There was a problem hiding this comment.
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.
| if mkinitrd "/boot/initrd-${KERNEL_VERSION}" "$KERNEL_VERSION" 2>&1; then | |
| if mkinitrd "/boot/initrd-${KERNEL_VERSION}" "${KERNEL_VERSION}" 2>&1; then |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
| break | ||
| fi | ||
| fi | ||
| done |
There was a problem hiding this comment.
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.
| cmd.Stdin = strings.NewReader(command) | ||
| log.Printf("Executing %s", cmd.String()+" "+command) | ||
| out, err := cmd.Output() | ||
| out, err := cmd.CombinedOutput() |
There was a problem hiding this comment.
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.


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.shscriptWhich 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 --applyto regenerate the guest initramfs (viadracut,mkinitramfs, ormkinitrd) and attempt to update GRUB configuration across common BIOS/UEFI paths, with warnings when tooling/updates fail.Also switches
RunCommandInGuestto useCombinedOutput()instead ofOutput()soguestfishstderr is captured in errors/logging for easier debugging.Written by Cursor Bugbot for commit 2767b73. This will update automatically on new commits. Configure here.