Created
June 5, 2025 14:25
-
-
Save dknoodle/9b76449b91cf13c59005d55ef2fe469a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Fix Proxmox VM Initramfs/GRUB Issues After Cloning | |
# Run from Ubuntu Live ISO - Select "Try Ubuntu" | |
# wget https://gist.githubusercontent.com/YOUR_USERNAME/GIST_ID/raw/fix-vm-boot.sh | |
# sudo bash fix-vm-boot.sh | |
set -e | |
# Check root | |
[ "$EUID" -ne 0 ] && { echo "Run with sudo: sudo bash $0"; exit 1; } | |
# Detect disk | |
if [ -b /dev/sda ]; then DISK="/dev/sda"; else DISK="/dev/vda"; fi | |
echo "Using disk: $DISK" | |
# Mount filesystems | |
mkdir -p /mnt/root | |
mount ${DISK}2 /mnt/root | |
mount ${DISK}1 /mnt/root/boot/efi | |
mount --bind /dev /mnt/root/dev | |
mount --bind /proc /mnt/root/proc | |
mount --bind /sys /mnt/root/sys | |
# Fix boot in chroot | |
chroot /mnt/root /bin/bash -c ' | |
# Install GRUB | |
grub-install /dev/sda 2>/dev/null || grub-install /dev/vda | |
update-grub | |
# Add virtio modules | |
echo -e "virtio_scsi\nvirtio_blk\nvirtio_pci\nvirtio_net" >> /etc/initramfs-tools/modules | |
sort -u /etc/initramfs-tools/modules > /tmp/m && mv /tmp/m /etc/initramfs-tools/modules | |
# Rebuild initramfs | |
update-initramfs -u -k all | |
' | |
# Cleanup | |
umount -R /mnt/root | |
echo "Fixed! Reboot with: sudo reboot" | |
echo "After boot: qm set VMID --boot 'order=scsi0;ide2;net0'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment