Skip to content

Instantly share code, notes, and snippets.

Last active June 16, 2024 21:51
Show Gist options
  • Save dragon788/e777ba64d373210e4f6306ad40ee0e80 to your computer and use it in GitHub Desktop.
Save dragon788/e777ba64d373210e4f6306ad40ee0e80 to your computer and use it in GitHub Desktop.
Repair "ubuntu--vg-root" not found with LUKS and LVM encryption


Use this script via curl -L -O and sudo bash ./ You may need to edit the DEVICE variable to reflect your disk and partition layout (this was created on an EFI system using LUKS and LVM). It will prompt you for your disk password once to mount and discover the correct name for the encrypted volume mount and then prompt again to mount with the correct name so that the update-initramfs command succeeds with the appropriate mapping, if this wasn't done you would get a warning and your next boot would still fail.

# Call with `sudo bash DEBUG=1 ./` for verbose output
[ -n "$DEBUG"] && set -x
# Prompt user for device from /dev/sd* /dev/nvme* /dev/mmc* prefixes?
# For /dev/sda probably sda1 is EFI and sda2 is boot and sda3 is encrypted
# Need root for mounting stuff
if ! (( $EUID == 0 )); then echo "Please run with `sudo $0`"; fi
clear_mounts () {
# Clears mounts in case of interrupt or upon exit to allow running script multiple times
umount $TARGETPATH/boot/efi
umount $TARGETPATH/boot
umount $TARGETPATH/proc
umount $TARGETPATH/dev
vgchange -an
cryptsetup close temp_name
cryptsetup close $CRYPTNAME
set +x
trap clear_mounts INT EXIT
cryptsetup open $CRYPTPATH temp_name
vgchange -ay
# Can't get this until LVM devices are scanned above
ROOTPATH=$(ls /dev/mapper/* | grep root)
# Make sure nothing else is mounted on our $TARGETPATH
# Find the name that is required for `update-initramfs` to properly update things
CRYPTNAME=$(cat $TARGETPATH/etc/crypttab | awk '/^[ ]*[^#]/ { print $1; exit }')
vgchange -an
cryptsetup close temp_name
# This proper name is required for `update-initramfs` to properly update things
cryptsetup open $CRYPTPATH $CRYPTNAME
vgchange -ay
ROOTPATH=$(ls /dev/mapper/* | grep root)
mount $EFIPATH $TARGETPATH/boot/efi
mount -t proc proc $TARGETPATH/proc
mount -o bind /dev $TARGETPATH/dev
# Have also seen people mounting dev/pts and run and sys, they don't appear to be necessary
chroot $TARGETPATH update-initramfs -c -k all
echo "Completed crypt-fix, try rebooting and you should get prompted for your passphrase after grub"
Copy link

BlayeeR commented Oct 23, 2023

I still get "dev/mapper/ubuntu--vg-root does not exist" after successfully running this Script via a live USB Stick. Any additional advice? I edited the device to match my setup: sda , 1 ,2, 3.

I know its an old problem, but had same issue just now. Script run successfully but it was still not seeing the dev/mapper/ubuntu--vg-root.
It can be that you are missing the packages: lvm2, cryptsetup-initramfs
In my case I was missing cryptsetup-initramfs package. Installing it was tricky because inside chroot I had problems with internet connection, so instead of playing with /etc/resolve.conf to get the internet working i downloaded the package inside live-cd linux, then copied it to a mounted filesystem, and with chroot installed it via dpkg(added these commands temporary to the script). If package was missing the initramfs should update automatically but I recommend running entire script again to update it for all kernel packages.

Also note that wget in current points to outdated revision of the gist, make sure you are using the newest one to avoid issues(I learned that the hard way)

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