Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Created May 14, 2017 12:04
Show Gist options
  • Save samuelcolvin/43c5ed2807e7db004b1058d0c9bfb068 to your computer and use it in GitHub Desktop.
Save samuelcolvin/43c5ed2807e7db004b1058d0c9bfb068 to your computer and use it in GitHub Desktop.
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
@thierryale
Copy link

Thanks a lot, this has saved my installation! :-)
(with small adaptations for XUbuntu 20.04 live USB as the vg root directory was automatically mounted under /media/xubuntu/ )

btw, as efi & boot were already unmounted under the chroot, shouldn't the following:

umount /media/linux/boot/efi
umount /media/linux/boot

be rather:

umount /media/linux/proc
umount /media/linux/dev
umount /media/linux/sys

?

@SeaMonkey82
Copy link

SeaMonkey82 commented Dec 5, 2021

Thank you so much for this! I would have been completely lost without it. As the first reply suggests, knowing the correct label for the LUKS partition is necessary for this to work. I actually just checked another system with Linux Mint on an NVMe drive to find it. It was nvme0n1p3_crypt

edit Just in case anyone else would run into the same situation I did, while this worked to get back into my OS, whenever I was running kernel updates, nothing was changing in the grub menu. I was racking my brain trying to figure out why, and it turned out that my /etc/fstab was missing the mount point for /boot at the UUID of /dev/nvme0n1p2.

@childersd
Copy link

Amazing, thank you!

@drakewild
Copy link

Thanks, saved a lot of time cause of this!

@ravelzh
Copy link

ravelzh commented Feb 20, 2022

Not all heroes wearing capes, THANK YOU :-) 👍

@F-Phi
Copy link

F-Phi commented Mar 13, 2022

update-grub NOT "OR grub-update" as mentioned above

@brandon1024
Copy link

Thank you!!

@marcosvfc
Copy link

Thank you!!! Many many thanks

@themmm
Copy link

themmm commented Feb 7, 2023

Had to use "rbind" to make it work:

mount -o rbind /proc /media/linux/proc
mount -o rbind /dev /media/linux/dev
mount -o rbind /sys /media/linux/sys

Other than that it worked great ty!

@mindnuts
Copy link

mindnuts commented Nov 10, 2024

@samuelcolvin Thank you so much, i had to combine a few other things because my disk is NVME. Also thanks to @themmm for the rbind. Saved me couple of days of full set up.

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