0

I have a pastbin URL: pastbin

I have two physical hard drives, Ubuntu 20.04 is installed on the second HD on a LUKS encrypted drive. The bootloader was on the first drive. I deleted the first drive (it had windows installed, I don't need that anymore). But now I cannot boot anymore.

I was asked if I also deleted the uefi partition. I do not know. I used gparted to delete the windows partition. How can I find out?

fdisk -l has the output:

Device       Start      End Sectors  Size Type
/dev/sda1       64  7465119 7465056  3.6G Microsoft basic data
/dev/sda2  7465120  7473615    8496  4.1M EFI System
/dev/sda3  7473616  7474215     600  300K Microsoft basic data
/dev/sda4  7475200 15761440 8286241    4G Linux filesystem

But of course I do not know if this EFI partition contains any data, and I also have a second EFI partition on the second SSD.

I can boot from a live USB stick and mount the encrypted partition.

Second HD has three partitions:

Device           Start        End    Sectors   Size Type
/dev/nvme1n1p1    2048    1050623    1048576   512M EFI System
/dev/nvme1n1p2 1050624    2549759    1499136   732M Linux filesystem
/dev/nvme1n1p3 2549760 2000408575 1997858816 952.7G Linux filesystem

But how can I re-install the bootloader? Should I install it on the first or the second drive?

I tried:

### Mount encrypted rootfs in chroot environment
sudo -i
apt-get update
apt-get install cryptsetup lvm2
fdisk -l
cryptsetup luksOpen /dev/nvme1n1p3 rootcrypt            # device is your root partition
vgchange -ay
vgscan
vgchange -ay vgubuntu                                # From the above command
lvscan
mount /dev/vgubuntu/root /mnt          # LOGICAL VOLUME NAME from above command
modprobe efivars
mount /dev/nvme1n1p2 /mnt/boot
mount /dev/nvme1n1p1 /mnt/boot/efi     # nvme? is your efi partition
for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B $i /mnt$i; done
cp /etc/resolv.conf /mnt/etc/
chroot /mnt

Reinstall grub

apt-get install --reinstall grub-efi-amd64 grub-install /dev/nvme1n1 update-grub exit

Not tested

umount /mnt/boot/efi umount /mnt/boot umount /mnt vgchange -an chryptsetup luksClose rootcrypt

This fixed my problem.

Lessons learned:

  • the efi and the unencrypted boot partition must be manually mounted in the decrypted root file system
  • also the efivars need to be mounted
  • grub-install on the second drive must be executed

Not yet clear to me: Why unmounting fails.

  • The grub install command defaults to the ESP in your fstab. So if doing reinstall & it still refers to an ESP you deleted it will not work. You can use Boot-Repair and do a full reinstall of grub using its advanced mode, or the chroot. Better to update UUID in fstab first. Check UUID & fstab. cat /etc/fstab & lsblk -f – oldfred Dec 24 '22 at 17:51
  • Answered my own question, it is working now. Thanks for the helpful comments! – Uwe Fechner Dec 24 '22 at 18:09

1 Answers1

0

Boot into the live environment.

Install it on the drive where your OS is.

The command sudo grub-install /dev/sdb will install Grub2 on the second drive.

I cannot see the pastebin as they don't send me an email after making an account. So I'm lacking some information. Also about how the second drive is set up.

See for more information this page: https://help.ubuntu.com/community/Grub2/Installing. Use the commands that fit your setup.

Joepie Es
  • 1,460
  • This does not really help because I have an encrypted root drive. – Uwe Fechner Dec 24 '22 at 16:25
  • I think that her EFI and swap partitions on the first hard so she need to do it on sda not sdb, while sdb has the system file partition, so she need also to try that command sudo fsck /dev/sdb3 but she has to make sure about the location as example using Disks program and choose the partition to find it's Device information under size information as sdb3 or sdb2. – Bassem Dec 24 '22 at 17:59
  • take a look here https://askubuntu.com/questions/719409/how-to-reinstall-grub-from-a-liveusb-if-the-partition-is-encrypted-and-there-is a separate /boot partition? – Joepie Es Dec 25 '22 at 14:31