Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
About dracut and detached luks headers
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Wed Dec 20, 2023 2:48 pm    Post subject: About dracut and detached luks headers Reply with quote

Hello,

does anybody have a valid setup for dracut and detached luks headers, without modifying dracuts source? It refuses to mount my LVM inside luks setup. I tried so many different rd.luks and crypttab variances, but none work. I even replicated: https://github.com/dracutdevs/dracut/issues/1778
It boots after I manually mount my luks container and then activate the volume group (just like in the workaround patches discussed in this bug)
What would be the best way to modify dracut without losing the changes if there will ever be an update to dracut in the repo?
I want to automate everything around the dist-kernel so I can update the system by just running emerge without breaking my boot process.
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Thu Dec 21, 2023 5:40 pm    Post subject: Reply with quote

Where is the header stored?
Plz post
Code:

lsblk -f
grep -ir cmdline /etc/default/grub /etc/dracut.conf /etc/dracut.conf.d/
grep " / " /etc/fstab
cat /etc/crypttab
rc-status boot

_________________
:)
Back to top
View user's profile Send private message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Thu Dec 21, 2023 7:18 pm    Post subject: Reply with quote

Header is stored next to my initramfs image and kernel on /boot
Code:
NAME           FSTYPE      FSVER    LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
sda                                                                                             
├─sda1         vfat        FAT32    EFI   ECC9-3A44                               251.9M     0% /efi
├─sda2         ext4        1.0            83f99e38-09f0-42fd-9388-4885353c4526    585.7M    13% /boot
└─sda3                                                                                         
  └─lukscont   LVM2_member LVM2 001       yCO8ad-bOXo-N92n-I5EX-rH9V-OxRz-T26dsb               
    ├─vg1-swap swap        1              d53324cf-5866-4d81-9a6d-f307f8ebfd3e                 
    └─vg1-root ext4        1.0            96dceed6-f59c-4cb6-9f22-59b2e91a5c8e     85.4G     8% /


dracut.conf from latest try(nothing in conf.d):
Code:
#kernel_cmdline="rd.luks.uuid=1d7498ea-f984-1843-8a0e-fc62e0ebf4f9 rd.lvm.vg=vg1 rd.luks.allow-discards rd.luks.options=cd2bcc19-8861-416b-92b8-ed997a5e8261=header=/header.img:UUID=83f99e38-09f0-42fd-9388-4885353c4526"
#hostonly=yes
#add_dracutmodules+=" dm crypt lvm resume "
install_items+=" /etc/crypttab "

fstab:
Code:
UUID="96dceed6-f59c-4cb6-9f22-59b2e91a5c8e"   /   ext4 defaults 0 1
UUID="d53324cf-5866-4d81-9a6d-f307f8ebfd3e" none swap sw 0 0
PARTUUID="59230c2a-4d23-8146-abbb-6343e17430dd"   /efi defaults vfat 0 2
PARTUUID="57dd7e27-f974-624d-bbc6-ff1398e46b42" /boot defaults ext4 0 2

crypttab:
Code:
cryptContainer   wwn-0x500a075112e7fd1b-part3   none   luks,header=/header.img:UUID=83f99e38-09f0-42fd-9388-4885353c4526

If I uncomment hostonly=yes it does add:
Code:
dracut: Stored kernel commandline:
dracut:  rd.lvm.lv=vg1/root 
dracut:  root=/dev/mapper/vg1-root rootfstype=ext4 rootflags=rw,relatime

Whatever I do it seems to never be able to recognize the detached header.

EDIT:
okay I noticed with
Code:
rc-status boot
that both lvm and dmcrypt services where disabled. I did only start them in my initial chroot env and not when coming back after inital boot failed, bu I guess I need to restart them manually after chrooting back in. I'll should automate going back into chroot at this point :lol: But even after the fact dracut still only seems to see the lvm setup and ignores luks.

EDIT2: I saw that row twist in fstab myself during boot and fixed it myself :oops:


Last edited by Screenager on Thu Dec 21, 2023 7:44 pm; edited 1 time in total
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Thu Dec 21, 2023 7:41 pm    Post subject: Reply with quote

Try this
I hope you have grub
Code:

/etc/default/grub----->>>>>

GRUB_CMDLINE_LINUX="cryptdevice=UUID=yCO8ad-bOXo-N92n-I5EX-rH9V-OxRz-T26dsb:lukscont root=/dev/vg1/root"

Code:

/etc/crypttab ------->>>>>

lukscont   UUID=yCO8ad-bOXo-N92n-I5EX-rH9V-OxRz-T26dsb   none   luks,header=/header.img:UUID=83f99e38-09f0-42fd-9388-4885353c4526,initramfs,discard


Then
Code:

rc-update add lvm boot
rc-update add dmcrypt boot
dracut --force
grub-mkconfig -o /boot/grub/grub.cfg

Have the cmdline either in default/grub or dracut.conf
_________________
:)
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21639

PostPosted: Thu Dec 21, 2023 7:55 pm    Post subject: Reply with quote

Screenager wrote:
Header is stored next to my initramfs image and kernel on /boot
What are you trying to achieve by using a detached LUKS header? I am aware of a few use cases for detached headers, but all of them involve the detached header actually being on a different (and often removable) device than the encrypted LUKS volume. However, you are storing the header on the same device, which seems to defeat the deniability justification and the multi-factor justification.
Back to top
View user's profile Send private message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Thu Dec 21, 2023 9:21 pm    Post subject: Reply with quote

My reasons are: merciless unification of installation setups, I am not going to use a boot stick with detached headers on this device, but I will on others. It should not matter where the header is located, why support it if nobody is going to use it? Might even change the script and store headers remotely when traveling, so even if the entire travelbag get's stolen there is no header anywhere 8)

Thank you alamahant, but it still does show the same behaviour: dracut drops to rescue shell -> openLuks -> lvm_scan -> vgchange -a y vg1 -> exit , and then it boots.

I'll guess I'll just add my own workaround as a user patch for now. I will do many more installs in the future and somewhere along this path I will figure out if it really is buggy or if it is just due to my user error. That was the main reason I asked if anybody has a working detached headers+dracut setup, cause then it would be obvious I am doing something wrong. I am still very noobish if it comes to bash scripting and the raw dracut code is certainly not easy to understand, would be easier for me if it was made in C :lol:

EDIT:
Because this thread is found searching for "dracut luks detached header" and I did some more digging, here is some information for the pour souls trying to do the same:

If you are not using systemd, just stop and fix the script yourself by either following https://rich0gentoo.wordpress.com/2012/01/21/a-quick-dracut-module/ and creating your own function call that will do what needs to be done or
modify your dracut source with this rejected pull request which will add rd.luks.header and rd.luks.header.disk parameters to work with.
Back to top
View user's profile Send private message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Fri Dec 29, 2023 7:47 pm    Post subject: Reply with quote

I found the bug!!! But I can't even fathom WTF is going wrong here, much less formulate a coherent bug report for that which I am about to show you:

So I went deep into the dracut source, wrote my own module and hooked it into dracuts initqueue. I then found out that it prints my prompt to enter somewhere right inbetween the dmesg lines. So I just enter my pw and voilà - it boots. So I refactored my module, added more checks, even started to use dracuts own ask_for_password functions - and what did I see - somewhere in the dmesg before it halted, it was now asking for the original prompt as defined in cryptroot-ask.sh - so it is working like it should the only problem is: it prints the input prompt somewhere where it should not:
https://i.imgur.com/xKf47Vh.png
It is important to note: This line is not logged to /var/log/dmesg according to the log that line never existed.
So dracut is somehow not putting the prompt into the right pipe... WTF is going on here... I propably need to join their mailing list at this point, but I am completly flabbergasted - how many times did I not see that prompt in the past weeks? How many of my tries where actually valid configs? Ahhhhhhh :evil:
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21639

PostPosted: Fri Dec 29, 2023 8:17 pm    Post subject: Reply with quote

This is entirely normal, and I'm not sure it even counts as a bug. I get behavior like this somewhat often, too. The problem is that the system console is a shared resource. It can be written to by the kernel and by any process running on the terminal. The flow is:
  • Kernel gains control from bootloader, and begins initializing the system
  • Kernel probes asynchronous hardware, like USB and mass storage
  • Kernel starts your initramfs
  • Initramfs prints the prompt
  • Probes of asynchronous hardware complete, and the kernel prints the results of those probes, which necessarily appear later in the console than the prompt
The initramfs is still waiting for input at this point. You cannot see the initramfs prompt in /var/log/dmesg because that file is a snapshot of the output of dmesg. The initramfs did not write to the kernel's ring buffer; it wrote directly to your screen.

If this really bothers you, you might be able to fix it by setting the kernel to minimum verbosity before you request the password from the user, so that the slower asynchronous probes never print anything when they finish.
Back to top
View user's profile Send private message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Fri Dec 29, 2023 8:56 pm    Post subject: Reply with quote

Ahhh I see, so that is what is happening. I was under the impression I am already in a blocking bash shell... at least I could use non POSIX bash scripting...
Thank you! That workaround sounds like it should work on every machine. I guess it will also be no problem if using a plymouth splash screen. A little bit of sleep before invoking the prompt should be fine too, although the optimal amount will vary for each machine.
So I will fix this up, complete my own documentation and share a little bit more info about custom modules to the wiki.
Back to top
View user's profile Send private message
Screenager
n00b
n00b


Joined: 26 Nov 2023
Posts: 37

PostPosted: Sat Dec 30, 2023 11:52 pm    Post subject: Reply with quote

Sorry for the doubleposting, but it is done and works like a charm.
I documented the whole installation and how to do the custom dracut module here
I already decided to start over again, because I noticed so much stuff I could do better, so I won't update the wiki page any longer, but it seems like valuable information for anyone who wants to do dracut with detached headers so I decided to bump the thread and share.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21639

PostPosted: Sun Dec 31, 2023 12:59 am    Post subject: Reply with quote

Announcing additional progress is a good reason for a bump, so there is no need to apologize for the follow-up posting.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum