Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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"

This comment has been minimized.

Copy link

@icio icio commented Nov 24, 2018

This was super useful - thanks for collecting it all together.

I somehow got myself into this situation by trying out different desktop managers. I ran sudo tasksel, unselected KDE Desktop and selected Mate Desktop, and then found I was unable to boot due to missing cryptsetup and the errors described above.

Once I was up and running again with a bootable Live USB stick, I wanted to revert to Ubuntu Desktop and fix initramfs. I first followed all of the steps in the above script up to update-initramfs to prepare /mnt. To revert the desktop manager on the encrypted drive, I had to:

cp /etc/resolv.conf /mnt/etc.resolv.conf
chroot # Pretend we're on the OS on the encrypted drive.

After doing all of this, I still had to make sure that I had cryptsetup inside initramfs:

apt-get install cryptsetup-initramfs cryptsetup-run

Which itself triggered update-initramfs, but warned:

cryptsetup: WARNING: The initramfs image may not contain cryptsetup binaries nor crypto modules. If that's on purpose, you may want to uninstall the 'crypsetup-initramfs' package in order to disable the cryptsetup initramfs integration and avoid this warning.

To finally get cryptsetup into the initramfs I had to:

mount -t sysfs sys /sys
update-initramfs -c -k all

I was then able to reboot into gdm.


This comment has been minimized.

Copy link

@lovromazgon lovromazgon commented Feb 22, 2019

Thanks for this, it helped me figure out a solution to my problem. After an update my computer booted right into a broken GRUB console which was missing commands (e.g. ls didn't work).

I was following the Manual Full System Encryption guide when installing Ubuntu. As mentioned in the Troubleshooting chapter, there is a script refreshgrub which fixed my problem. I created a separate script which helps you run refreshgrub without diving into too many details. Maybe it will help others with the same issue -


This comment has been minimized.

Copy link
Owner Author

@dragon788 dragon788 commented Oct 16, 2020

I need to come back and revisit this as using the /dev/nvme* path instead of a uuid causes issues if you ever move it between systems where it might end up on a different port/path.


This comment has been minimized.

Copy link

@zawlazaw zawlazaw commented Nov 7, 2020

Thanks so much, this saved my laptop in a critical phase after an erroneous fwupd!
However, just running the script did not work for me and gave some errors, e.g., I had ROOTPATH= being empty.
It helped to run these steps manually.
I think one could solve my issues by adding sleep 5 after every call to vgchange, but this is just a wild guess.
Thanks again!


This comment has been minimized.

Copy link
Owner Author

@dragon788 dragon788 commented Nov 8, 2020

Thanks for the notes zawlazaw. I haven't run into the issues that required running this in a while but it might help someone else if they are seeing the same errors.


This comment has been minimized.

Copy link

@sebonze sebonze commented Jun 8, 2021

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.

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