Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] How to unlock encrypted zfs datasets during boot?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
crocket
Guru
Guru


Joined: 29 Apr 2017
Posts: 558

PostPosted: Wed Nov 24, 2021 4:57 am    Post subject: [SOLVED] How to unlock encrypted zfs datasets during boot? Reply with quote

I want to open multiple encrypted zfs datasets during boot by entering a password once.

Even root partition is an encrypted zfs dataset.

Different datasets belong to different zfs pools but have the same passphrase. Thus, they need to be opened separately by something.


Last edited by crocket on Mon Nov 29, 2021 1:57 am; edited 1 time in total
Back to top
View user's profile Send private message
mrbassie
l33t
l33t


Joined: 31 May 2013
Posts: 772
Location: over here

PostPosted: Wed Nov 24, 2021 4:09 pm    Post subject: Reply with quote

I guess you could use zfs-change-key to switch to using keyfiles instead (I think you can switch between key types ...?), set the keylocation to be /whatever so that only / is decrypted with a passphrase and script loading the keyfiles.
Back to top
View user's profile Send private message
crocket
Guru
Guru


Joined: 29 Apr 2017
Posts: 558

PostPosted: Mon Nov 29, 2021 1:56 am    Post subject: Reply with quote

mrbassie wrote:
I guess you could use zfs-change-key to switch to using keyfiles instead (I think you can switch between key types ...?), set the keylocation to be /whatever so that only / is decrypted with a passphrase and script loading the keyfiles.


The problem is that a zfs dataset can contain only one key. If I lose the key file accidentally, I cannot ever recover the encrypted dataset again.
LUKS supports multiple keys. One of them can be a passphrase. Another can be a keyfile.

Also, a keyfile can be stolen by hackers. I can memorize one passphrase.

I figured out a dirty way to unlock multiple encrypted zfs datasets with one passphrase during boot.


Last edited by crocket on Mon Nov 29, 2021 2:08 am; edited 1 time in total
Back to top
View user's profile Send private message
crocket
Guru
Guru


Joined: 29 Apr 2017
Posts: 558

PostPosted: Mon Nov 29, 2021 2:01 am    Post subject: Reply with quote

I found a dirty way to unlock encrypted zfs datasets with one passphrase during boot.

/usr/lib/dracut/modules.d/99local/module-setup.sh

Code:
#!/bin/sh

check() {
  return 0
}

depends() {
  echo zfs
  return 0
}

install() {
  inst_hook pre-mount 80 "${moddir}/zfs-load-key-all.sh"
}


/usr/lib/dracut/modules.d/99local/zfs-load-key-all.sh

Code:
modprobe zfs
zpool import -N -a
echo 3 > /proc/sys/kernel/printk

while true; do
  stty -echo
  read -p "Passphrase for datasets: " PASS
  stty echo
  echo "$PASS" | zfs load-key encryption-root1 || continue
  echo "$PASS" | zfs load-key encryption-root2 || continue
  break
done


Execute

Code:
dracut --kver $(uname -r) --force


Somehow, `modprobe zfs` and `zpool import -N -a` are necessary.

`echo 3 > /proc/sys/kernel/printk` makes kernel print only error messages. Otherwise, kernel prints verbose messages over passphrase prompt.

The scripts are dirty because I didn't have time for cleanness. I can clean them up later.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security 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