Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
repairing boot for LUKS encrypted fs

Guides:

cryptsetup luksOpen /dev/sdb3 home_sdb3
vgchange -ay
lvscan
mkdir /media/linux
mount /dev/ubuntu-vg/root /media/linux/
mount -o bind /proc /media/linux/proc
mount -o bind /dev /media/linux/dev
mount -o bind /sys /media/linux/sys
chroot /media/linux /bin/bash
> fdisk -l:

Disk /dev/sdb: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: ED00E611-2AA0-40CB-BA69-97B8FAD3303E

Device       Start       End   Sectors   Size Type
/dev/sdb1     2048   1050623   1048576   512M EFI System
/dev/sdb2  1050624   2050047    999424   488M Linux filesystem
/dev/sdb3  2050048 500117503 498067456 237.5G Linux filesystem
mount /dev/sdb2 /boot
mount /dev/sdb1 /boot/efi
grub-install /dev/sdb
**OR** grub-update

umount /boot/efi
umount /boot

leave chroot

exit 
umount /media/linux/boot/efi
umount /media/linux/boot
umount -l /media/linux
vgchange -an
cryptsetup luksClose home_sdb3
@tobszarny

This comment has been minimized.

Copy link

@tobszarny tobszarny commented Apr 2, 2020

Thanks for the instructions, however i had to do some extra steps.

  1. Mount blind just so you can read luks label from /etc/crypttab on the mounted volume and to secondly mount correctly.
    cryptsetup luksOpen /dev/sdb3 <the-label>
  2. I never get /dev/ubuntu-vg/root but /dev/mapper/sdb3_crypt

Ignoring step 1 lead to booting into initram-fs cli.

@samuelcolvin

This comment has been minimized.

Copy link
Owner Author

@samuelcolvin samuelcolvin commented Apr 2, 2020

great, thanks. Haven't used this for years.

@tobszarny

This comment has been minimized.

Copy link

@tobszarny tobszarny commented Apr 2, 2020

Latest Windows update made my day, as both occupy same machine in dual boot setup. I'm glad, I came across the work of yours, above, to help me get through issues with Ubuntu boot.

PS. I haven't check if Windows is booting, but for the time being, I'm happy Ubuntu does.

Thanks again.

@GiovaniMFMurari

This comment has been minimized.

Copy link

@GiovaniMFMurari GiovaniMFMurari commented Jul 15, 2020

Thank you very much!

@wackloner

This comment has been minimized.

Copy link

@wackloner wackloner commented Oct 20, 2020

Thanks man! Helped a lot, easy-breezy guide (:

@agjino

This comment has been minimized.

Copy link

@agjino agjino commented Nov 27, 2020

It worked for me, but with a couple of issues:

  1. If the flash drive I was booting the live CD from would mount to /dev/sda, the main Ubuntu drive would end up in /dev/sdc and even though I adjusted the script accordingly, it still would boot into the grub command line instead of the OS. I had to try over and over until the live CD got mounted to /dev/sdc and the Ubuntu drive mounted to it usual /dev/sdb.
  2. With this method os-prober fails to identify Windows with the error WARNING: Failed to connect to lvmetad. Failing back to device scanning What I did to get Windows back was copy-paste its entry from the grub.cfg generated by the main system's update-grub, once I managed to fix grub through your method. The grub.cfg that gets generated is incorrect and the steps to fix grub have to be run again, but at least the Windows entry is sound so it can be saved somewhere and pasted into the grub.cfg generated in the live CD.
@vijay-prema

This comment has been minimized.

Copy link

@vijay-prema vijay-prema commented Feb 2, 2021

Nice. This saved me after I cloned a drive onto a new ugraded SSD for my PC. I'm using Kubuntu 20.04 and mine was under /dev/vgkubuntu/root. Had to also do some corrections to disk UUIDs to stop it getting confused by the previous SSD which I cloned from having the same UUIDs, then fix erroneous entries in the the /etc/fstab to prevent slow bootup .

@erikmansson

This comment has been minimized.

Copy link

@erikmansson erikmansson commented Feb 8, 2021

Sir, you are a lifesaver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment