fixing encrypted grub2

Hi,

I have installed my Opensuse Leap on a single partition on my laptop and used encryption.
Now I have moved my ssd from my laptop to a dekstop and obviously it doesn’t boot.
I went through many tutorials but couldn’t fix it, as it’s encrypted (I also tried commands like cryptsetup and luksopen, and they opened the partition, but wasn’t able to fix grub2)
Is there any way to fix my grub2, which is on an encrypted partition?

thanks

You will probably need to reinstall grub. Note, this should require reinstalling opensuse.

Boot from a live system (live CD or live USB). It needs to be the same architecture (i.e. 64-bit) since you are repairing a 64-bit system.

Use “cryptsetup luksOpen /dev/sdxn cr_sdxn” or similar to access the partition.

If you used an encrypted LVM, then look in “/dev/mapper” for the device names for the LVM volumes. If they are not there, you might need

vgchange -a y

Mount your root file system at “/mnt”.

If this is a UEFI box, then mount the EFI partition at “/mnt/boot/efi”

Mount any other needed partitions as needed, relative to “/mnt”.

Edit “/mnt/etc/default/grub” and make any needed changes. You might need to change the “resume=” parameter.

Do some bind mounts


mount --bind /dev  /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc

You should now be able to do a “chroot” into the mounted system for final steps:


chroot /mnt
mkinitrd    ### rebuild the initrd
grub2-install --force /dev/sdx   ### change to specify the boot code location
exit   ### exit from chroot
reboot

If you are switching between legacy booting and UEFI booting (either way), there might be a few changed needed in the above.