Howto fix GRUB after Windows install?

I know this is an old question asked a million times but every answer I find is always incomplete.

I had installed Windows but then my wifi didn’t work in Windows after reboot, it has a driver and I know the RFKILL flag can be enabled by weird/faulty drivers such as those in Linux also. But anyway after installing Windows I needed to get Grub2 back.

Long story short I had to boot with a Kubuntu Live CD because I couldn’t get my LVM mapped after cryptsetup open (for LUKS) on the volume/partition that contained the root logical volume for openSUSE.

So I am in Kubuntu and I do:

cryptsetup open /dev/sda5 sda5_crypt

mount /dev/linux/root /mnt

mount --bind /dev/ /mnt/dev

mount --bind /proc/ /mnt/proc

mount --bind /sys/ /mnt/sys

At that point I am going to look for openSUSE’s way of installing grub2.

chroot /mnt → I am in openSUSE’s environment now.

grub-install /dev/sda → results in error: use grub-install.unsupported or yast2 bootloader

But yast2 bootloader requires an X session and I can’t get it to run in Kubuntu’s live session.

grub-install.unsupported /dev/sda → results in error: /dev/md-2 does not have matching BIOS device

grub2-install /dev/sda → results in error: it detects my cryptsetup and wants me to pass an option to grub such as GRUB_ENABLE_CRYPTODISK=1.

I make the required change, it still complains. Turns out the error message is wrong, it has to be “y” not “1” as the value.

So now grub2 installs. But it doesn’t install the openSUSE menu.

I get a prompt at reboot asking for my password to the LUKS, which is not even needed to load the menu. I enter my password.

I get a grub prompt. I try various things.

grub> linux (hd0,msdos3)/vmlinuz root=/dev/linux/root → this one ends in a root device not found
grub> linux (hd0,msdos3)/vmlinuz root=(lvm/linux-root) → this one results in a different error but the system still locking up.
grub> initrd (hd0,msdos3)/initrd
grub> boot

This fails. Next time I remember the configfile option.

grub> configfile (hd0,msdos3)/grub2/grub.cfg

It loads beautifully giving me the default openSUSE boot loader.

And I’m in. Now I run kdesu yast2 bootloader, and it installs grub2 for me.

There’s gotta be an easier way, right?. For years I’ve had this problem, also with Kubuntu, of not knowing how to install or recover grub. All of the options I’ve seen always failed. This was the only time I’ve succeeded thus far. I’m generally apprehensive of installing Windows or losing my MBR because of this and I generally just take out an USB stick or SD card and install grub on that so I always have a way back into my system.

Pretty fancy that Grub can ask for the password but it’s butt-ugly of course ;-D.

So what is the tried and tested way to get Grub back?. I had tried the openSUSE rescue option from the DVD but it wouldn’t load my LVM after the cryptopen. I believe I needed vgchange -ay <volname> (volume group name) to get it activated, not sure. So I had to get into Kubuntu because it does it automatically there.

What’s the answer?..?.

Easy, don’t run Windows as dual boot use virtual machines if you must have it at all. Windows is totally oblivious to any other OS and will ding it all the time.

In any case exact procedure would be different depending on BIOS type. Today you may have legacy BIOS or EFI (BIOS). The boot procedure is different thus any kind of back up of the boot details would need to be different. With legacy the problem is most often that a boot flag being changed or if grub code is in the MBR it may be over written by Windows generic code. If thing were setup this way then you must reinstall grub or change the boot to use generic boot code and install the grub code in the partition that contains /boot. You will note that in legacy alone there could be many ways to save the boot info and where that booting is actually stored. And I’m just touching the common ways.

Then we have EFI which is different the EFI boot looks for a spacial efi boot partitions which is FAT formatted and contains directories for each bootable OS. The actual files run depend on the information stored in the EFI flash memory. So at times we have seen Window wipe the EFI boot partition basically breaking the boot chain for any other OS. Also it has been see that a Windows install wipes references in the EFI flash again breaking the chain at an even earlier part.

So any general fixit program would have to deal with all those different methods and probably others I have not thought of. And it is often not obvious from the outside what booting is used :stuck_out_tongue:

If you use Windows for games VM’s are not suitable so dedicate a machine running Windows for games.

If you installed with an encrypted LVM, then you probably had a separate partition for “/boot”. You need to mount that at “/mnt/boot” before you reinstall grub2.

I’m not quite sure what your setup is. I’m guessing that you want grub2 to boot from the MBR. I usually prefer to have it boot from “/boot”.

After the mounts, including that for “/boot”, you would need something like:


chroot /mnt
mkinitrd
grub2-install /dev/sda   ## install in MBR
grub2-mkconfig -o /boot/grub2/grub.cfg
exit

then reboot and see if you have solved the problem.

The “vgchange” should be done automatically by the “initrd”.

And maybe I guess wrongly on what you are trying to do. In that case, provide more details.