I had a LUKS-encrypted Ubuntu 20.04 setup. I followed my own instructions here to shrink the LUKS partition and install Ubuntu 22.04, also LUKS-encrypted. Now, my grub boot menu no longer gives me the option to boot my old LUKS-encrypted Ubuntu 20.04 version. Rather, it just boots the new 22.04 one.
How do I add the LUKS-encrypted Ubuntu 20.04 version back in?
Here's my disk, as shown in gparted while logged into the new Ubuntu 22.04 OS.
Description:
/dev/nvme0n1p1
is the 512 MiB EFI partition/dev/nvme0n1p2
is the ext4/boot
non-encrypted partition for the old Ubuntu 20.04 OS/dev/nvme0n1p3
is the LUKS-encrypted partition containing a single LVM volume with Ubuntu 20.04 in it (no longer in the grub menu)/dev/nvme0n1p4
is the ext4/boot
non-encrypted partition for the new Ubuntu 22.04 OS/dev/nvme0n1p5
is the LUKS-encrypted partition containing a single LVM volume with Ubuntu 22.04 in it (is in the grub menu, and is the OS running right now)
Possibly useful:
- For more-experienced people, this answer to a different question may have some clues, but I don't understand it: How to get grub to boot from a newly encrypted partition
- How to repair
/boot
on LUKS encrypted harddrive?
After a lot of effort and investigation, I figured it out!
1. How to add other LUKS-encrypted Linux distributions back to your Grub bootloader startup menu
Quick summary
Stop here if you just wanted the quick answer.
Details
Edit your
/etc/default/grub
file to add the lineGRUB_DISABLE_OS_PROBER=false
in it:The
GRUB_DISABLE_OS_PROBER=false
line enables the Operating System prober, which scans your filesystems for valid operating systems and adds them to the Grub bootloader. This feature is disabled by default, so to enable it we setGRUB_DISABLE_OS_PROBER=false
. Here is what the Grub user manual has to say about this: https://www.gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html:Note to self: though it appears to not be necessary: if the above ever doesn't work by itself, try adding
GRUB_ENABLE_CRYPTODISK=y
too. From the link above:Unlock all LUKS-encrypted partitions which contain operating systems you'd like to add to your Grub menu.
In my case, my old Ubuntu 20.04 OS is in my
/dev/nvme0n1p3
partition, as explained in my question.Note: I like to look at my partitions in the
gparted
GUI partition editor.So, here is how to unlock that partition:
For additional help, see
man cryptsetup
. Notice that theluksOpen
option is equivalent toopen --type luks
.Now that your LUKS-encrypted partitions are unlocked, and you have told Grub to search for other operating systems in your filesystems, update the Grub bootloader:
In its output, look for lines like this, showing that it is finding and adding operating systems to the Grub menu:
Full example command and output for me, with that line above in the output:
To verify the new Grub menu entries, you can manually open the file at
/boot/grub/grub.cfg
and look formenuentry
entries after the comment in that file which says### BEGIN /etc/grub.d/30_os-prober ###
. Do not edit that file directly.Troubleshooting, debugging, & extra info.
When running
sudo update-grub
, if you see these lines in the output:...then it means you forgot to add
GRUB_DISABLE_OS_PROBER=false
to your/etc/default/grub
file.If you run
sudo update-grub
without having first unlocked all of your LUKS-encrypted partitions containing bootable operating systems, then those operating systems will be removed from your Grub menu (if they were previously present) when you runupdate-grub
(see the next section). If your find yourself in this situation, simply boot into whatever Linux OS that is available in the Grub menu, and follow the steps above to add the other OS's back into the Grub menu.You can see which partitions are unlocked by looking at the output of
sudo fdisk -l
andlsblk
.With only my running partition (
/dev/nvme0n1p5
) unlocked (ie: right after a reboot), here's what my output looks like. Notice that in both cases, onlynvme0n1p5_crypt
is shown:Now, after running
sudo cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3_crypt
to also unlock that LUKS-encrypted partition, here's what I see. Notice that I now seenvme0n1p3_crypt
and/dev/mapper/system-root
as well, where/dev/mapper/system-root
is the Logical Volume (LVM) within the/dev/mapper/nvme0n1p3
LUKS-encrypted partition:Note: for UUID (Universal Unique Identifier) numbers for each partition, run this:
Note that 3 of the main disk-related files to be aware of are the following. View them with
cat
:2. How to remove other LUKS-encrypted Linux distributions from your Grub bootloader startup menu
To remove all but the running operating system from the Grub boot menu, simply reboot into your desired operating system (this locks all other LUKS-encrypted partitions again), and run:
Since no other LUKS-encrypted partitions are unlocked, they'll be automatically removed from the Grub bootloader. Here's what that command and output looks like for me:
If you have a single, shared
/boot
partition for all of your operating systems (unliked me), then that's it! Runningsudo update-grub
in this operating system will have updated that single/boot
partition, affecting the Grub bootloader used to boot. Or, if you are in your latest-installed operating system, which updates the/boot
partition actually used by your Grub bootloader, that's it!But, if you're in any other operating system, it will have updated its own, old
/boot
partition instead of the latest one actually used to boot. In that case, you probably need to remount the latest/boot
partition into the/boot
dir of your filesystem and then runsudo update-grub
again, or perhaps there is some sort ofchroot
magic you can run. However, I didn't have time for that, so here's a dirty hack I did:Quick summary:
I simply manually copied the newly-created
/boot/grub/grub.cfg
file into the correct location on the actual (latest) boot partition, since that/boot
path it was created in is on the old (now unused) boot partition.Details:
I booted into my
/dev/nvme0n1p3
Ubuntu 20.04 OS, which had automatically mounted the old (now wrong/unused)/dev/nvme0n1p2
boot partition into the filesystem at path/boot
. I ransudo update-grub
to update that (now wrong/unused)/dev/nvme0n1p2
boot partition at path/boot
.I opened a GUI file browser and double-clicked on the new boot partition at
/dev/nvme0n1p4
, to automatically mount it into the filesystem at path/media/gabriel/abcd-1234-efgh-abcdefghij
. In other words, when I am logged into Ubuntu 20.04 in partition/dev/nvme0n1p3
, then path/media/gabriel/abcd-1234-efgh-abcdefghij
is the exact same as path/boot
when I am logged into the Ubuntu 22.04 OS on partition/dev/nvme0n1p5
!Dirty hack: back up the old grub.cfg file and copy the new one into its place.
Summary of the commands:
Another dirty hack to undo the previous dirty hack:
To undo this, simply restore the old
grub.cfg
file which you had previously backed up asgrub.cfg.bak
:References:
GRUB_DISABLE_OS_PROBER=false
to/etc/default/grub
: https://forum.manjaro.org/t/warning-os-prober-will-not-be-executed-to-detect-other-bootable-partitions/57849man update-grub
man 8 grub-mkconfig
man cryptsetup
man 5 crypttab
, and https://man7.org/linux/man-pages/man5/crypttab.5.html