You are not logged in.

#1 2024-11-26 04:11:22

live4thamuzik
Member
Registered: 2024-02-27
Posts: 49

[SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

Looking at changing my GRUB config to use UUID instead of the device name for cryptdevice. Just want to make sure I am understanding what I've read and applying it correctly for my drive setup before changing /etc/default/grub.   -- Thanks!

Resources:
https://wiki.archlinux.org/title/Dm-cry … VM_on_LUKS
https://bbs.archlinux.org/viewtopic.php?id=290148


Disk setup

fdisk /dev/nvme0n1
g                          // Create new GPT table
n                          // Create new partition
press enter          // Set partition number - 1 is default
press eneter        // Set partition sector - kept default
512M                   // Set last partition sector (makes partition 1 512MB)
t                           // Set partition type 
1                          // Sets partition type to EFI
n                          // Create new partition
press enter          // Set partition number - 2 is default
press eneter        // Set partition sector - kept default
1G                       // Set last partition sector (makes partition 1 1GB)
n                          // Create new partition - not setting a type on partition 2 keeps it as Linux File System
press enter          // Set partition number - 3 is default
press enter          // Set partition sector - kept default
press enter          // Set last partition sector (use remaining free space)
t                           // Set partition type 
44                        // Sets partition type to LVM
w                         // Save changes (this exits fdisk)

mkfs.fat -F32 /dev/nvme0n1p1                                       // format partition 1 as Fat32
mkfs.ext4 /dev/nvme0n1p2                                            // format partition 2 as EXT4
cryptsetup luksFormat /dev/nvme0n1p3                        // Encrypt partition 3 with LUKS
cryptsetup open --type luks /dev/nvme0n1p3 lvm          // Open Encrypted partition and call it "lvm" 
pvcreate /dev/mapper/lvm                                              // Create physical volume
vgcreate volgroup0 /dev/mapper/lvm                             // Create volume group "volgroup0" on "/dev/mapper/lvm"
lvcreate -L 100GB volgroup0 -n lv_root                          // Create 100GB logical volume called "lv_root" in "volgroup0"
lvcreate -l 100%FREE volgroup0 -n lv_home                // Create logical volume using all free space called "lv_home" in "volgroup0"
modprobe md_mod                                                        // Load kernel module into memory
vgscan                                                                           // Scan system for volume groups
vgchange -ay                                                                 // Activate all volume groups

lsblk output

NAME                            MOUNTPOINT                UUID
nvme0n1                                           
├─nvme0n1p1                                                  5C77-E934
├─nvme0n1p2                     /boot                     e9176f49-7d4d-4153-9cd0-6f1e6cfd1a82
└─nvme0n1p3                                                  e336a6be-73cc-469c-b915-f7628e5cfcc1
  └─volgroup0                                                   6ePI4P-Srgi-yGwe-27Gz-33NC-JJm7-3qytcr
    ├─volgroup0-lv_root        /                             858a85a1-f31d-43b1-9975-8596f8fa828e
    └─volgroup0-lv_home     /home                     e58fef17-5495-46c8-ab5e-52f60f2c6043

current /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="cryptdevice=/dev/nvme0n1p3:volgroup0"

If I'm understanding what I'm reading correctly, it looks like I need to use

GRUB_CMDLINE_LINUX="cryptdevice=UUID=<your_crypt_device_uuid>:<device_name> root=UUID=<your_root_partition_uuid>"

Where I'm not so sure is by crypt device uuid should I be using the uuid for nvme0n1p3 or volgroup0
nvme0n1

GRUB_CMDLINE_LINUX="cryptdevice=UUID=e336a6be-73cc-469c-b915-f7628e5cfcc1:/dev/nvme0n1p3:volgroup0 root=UUID=858a85a1-f31d-43b1-9975-8596f8fa828e"

OR

volgroup0

GRUB_CMDLINE_LINUX="cryptdevice=UUID=6ePI4P-Srgi-yGwe-27Gz-33NC-JJm7-3qytcr:/dev/nvme0n1p3:volgroup0 root=UUID=858a85a1-f31d-43b1-9975-8596f8fa828e"

Last edited by live4thamuzik (2024-11-27 00:05:32)

Offline

#2 2024-11-26 04:46:11

jonno2002
Member
Registered: 2016-11-21
Posts: 706

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

this is what you want:

GRUB_CMDLINE_LINUX="cryptdevice=UUID=e336a6be-73cc-469c-b915-f7628e5cfcc1:volgroup0:allow-discards"

the ":allow-discards" is for fstrim, also you dont need to add the "root=" part as grub will take care of that when you run grub-mkconfig

Offline

#3 2024-11-26 18:28:30

live4thamuzik
Member
Registered: 2024-02-27
Posts: 49

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

jonno2002 wrote:

this is what you want:

GRUB_CMDLINE_LINUX="cryptdevice=UUID=e336a6be-73cc-469c-b915-f7628e5cfcc1:volgroup0:allow-discards"

the ":allow-discards" is for fstrim, also you dont need to add the "root=" part as grub will take care of that when you run grub-mkconfig

Solved, Thank you!



EDIT - Just Kidding, that did not work. Had to use the live boot disc to revert /etc/default grub. I should have tested before marking solved... I'll keep testing.

Last edited by live4thamuzik (2024-11-26 19:04:38)

Offline

#4 2024-11-26 19:49:58

archlynovice
Member
Registered: 2023-10-22
Posts: 28

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

jonno2002 wrote:

you dont need to add the "root=" part as grub will take care of that when you run grub-mkconfig

Just throwing in that the wiki includes it.

I don't think you need to address the LVM partitions via UUID. For the initial LVM 'container' (?) I understand. But within the container, the LVM should know its way around. Is there a specific reason to use UUID here?

Last edited by archlynovice (2024-11-26 19:57:36)

Offline

#5 2024-11-26 20:11:26

archlynovice
Member
Registered: 2023-10-22
Posts: 28

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

live4thamuzik wrote:

EDIT - Just Kidding, that did not work. Had to use the live boot disc to revert /etc/default grub. I should have tested before marking solved... I'll keep testing.

Also, where did it fail? Could you decrypt the LUKS container / Did you see a password prompt?

Last edited by archlynovice (2024-11-26 20:21:23)

Offline

#6 2024-11-26 21:56:33

live4thamuzik
Member
Registered: 2024-02-27
Posts: 49

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

archlynovice wrote:
live4thamuzik wrote:

EDIT - Just Kidding, that did not work. Had to use the live boot disc to revert /etc/default grub. I should have tested before marking solved... I'll keep testing.

Also, where did it fail? Could you decrypt the LUKS container / Did you see a password prompt?


No password prompt, was dropped into "rootfs#" error said "/dev/volgroup0/lv_root could not be found."

I was leaning toward specifying /dev/nvme0n1p3 as the cryptdevice because logically, I encrypt partition 3 before setting up LVM. This leads me to believe the partition 3 needs to be unlocked before LVM "volgroup0" can be found. The reason why i want to use a UUID is because I would like to add another 2TB nvme drive for extra storage. I have seen device names change in lsblk when adding drives.

For example:
If i just add the 2nd NVME there's a good possibility that my current disk could change to "nvme1n1" rather than "nvme0n1"


*edited for spelling

Last edited by live4thamuzik (2024-11-26 23:22:13)

Offline

#7 2024-11-26 23:30:06

live4thamuzik
Member
Registered: 2024-02-27
Posts: 49

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

SOLUTION

GRUB_CMDLINE_LINUX=" cryptdevice=UUID=cryptdevice=UUID=e336a6be-73cc-469c-b915-f7628e5cfcc1:volgroup0 root=UUID=858a85a1-f31d-43b1-9975-8596f8fa828e
NAME                                      TYPE     MOUNTPOINT              UUID
nvme0n1                                   disk             
├─nvme0n1p1                          part                                           5C77-E934
├─nvme0n1p2                          part               /boot                    e9176f49-7d4d-4153-9cd0-6f1e6cfd1a82
└─nvme0n1p3                          part                                           e336a6be-73cc-469c-b915-f7628e5cfcc1
  └─volgroup0                           crypt                                         6ePI4P-Srgi-yGwe-27Gz-33NC-JJm7-3qytcr
    ├─volgroup0-lv_root lvm                            /                          858a85a1-f31d-43b1-9975-8596f8fa828e
    └─volgroup0-lv_home lvm                         /home                 e58fef17-5495-46c8-ab5e-52f60f2c6043

Last edited by live4thamuzik (2024-11-27 00:13:51)

Offline

#8 2024-11-27 10:36:46

archlynovice
Member
Registered: 2023-10-22
Posts: 28

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

Congrats on solving this by yourself!

I just googled a bit and apparently there is a bigger discussion about UUID or LVM name. Yet I still don't see why you'd use UUIDs over LVM naming. As far as Persistent block device naming, the wiki says so as well:

This article is not relevant for LVM logical volumes as the /dev/VolumeGroupName/LogicalVolumeName device paths are persistent.

Nevertheless, in this case (and probably every other case too) it doesn't really matter. Cheers!

Offline

#9 2024-11-27 20:10:22

live4thamuzik
Member
Registered: 2024-02-27
Posts: 49

Re: [SOLVED] LVM on LUKS and GRUB cryptdevice=UUID=

archlynovice wrote:

Congrats on solving this by yourself!

I just googled a bit and apparently there is a bigger discussion about UUID or LVM name. Yet I still don't see why you'd use UUIDs over LVM naming. As far as Persistent block device naming, the wiki says so as well:

This article is not relevant for LVM logical volumes as the /dev/VolumeGroupName/LogicalVolumeName device paths are persistent.

Nevertheless, in this case (and probably every other case too) it doesn't really matter. Cheers!


Thanks for helping provide some clarity! The discussion you linked was an interesting read, I can see how using UUID and LVM can be over complicating a config. I found with the way I setup LVM on LUKS it is useful because in my case I need to reference the disk /dev/nvme* before LVM can be found. Interestingly my fstab file now has UUID's now even though I never specified to use UUID during manual install. Unless me changing /etc/default/grub updated fstab on its own... I will need to read up on that in the wiki. I think if I setup LVM then ran cryptsetup on / or /home than I would agree that I did not need UUID because the system will always look at /dev/mapper/lvm to find /dev/volgroup0/lv_root which wouldn't change. Cheers!

Offline

Board footer

Powered by FluxBB