我想在启动时使用TPM 2.0加载对LUKS分区(根文件系统)的解锁。
我keyscript=/path/to/script
在/etc/crypttab
文件中使用a并没有成功,但是使用在这里找到的方法却取得了进步。
我正在使用dracut构建初始ram fs图像。
因此,在中/usr/lib/dracut/modules.d/90crypt
,我对几个文件进行了修改(根据我链接的指南):
module-setup.sh
# gives me access to these binaries at boot time in initramfs
function install() {
# existing code
# ...
inst /sbin/tpm2_nvread
inst /bin/tail
inst /bin/perl
inst /sbin/resourcemgr
}
cryptroot-ask.sh
resourcemgr &
# yum is only at tpm2-tools 1.1.0, so I can't read keys to a file
# this is my solution to grab from tpm, and convert the spaced out hex to binary
function gettpmkeyfile() {
key=`tpm2_nvread -x 0x1500001 -a 0x40000001 -s 32 -o 0 | tail -n 1`
key=${key//[[:blank:]]/}
key=`echo $key | /bin/perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie'`
printf $key
}
gettpmkeyfile | cryptsetup luksOpen $device $luksname --key-file=-
/etc/dracut.conf
omit_dracutmodules+="systemd"
add_dracutmodules+="crypt"
我知道二进制文件已正确加载,并且使用luksAddKey
,从TPM添加了密钥,并且在使用密码短语引导后在外壳程序的命令行中测试了我的功能。
我的问题是,tpm2_nvread
它引发了有关资源管理器无法初始化的错误(error 0x1
)。
但是,我注意到,在正常启动中,资源管理器也会在此处失败,但不会阻止我使用tpm2-tools
命令。
我尝试从elrepo(4.something)升级到最新的内核,并且添加了带有dracut的内核drievrs,如下所示:
dracut --add-drivers tpm_crb --force
这似乎没有帮助。
关于如何tpm2_nvread
在initrd中工作的任何建议?
我找到了解决方案!
我将其添加/sbin/strace
到已安装的二进制文件中,module-setup.sh
以便可以tpm2_nvread
在dracut shell中手动检查命令。原来的错误是我的网络无法访问。
tpm2命令用于libtcti
与tpm通信,后者使用处的套接字127.0.0.1:2323
。
现在,至于为什么环回下降了,我不确定。我的猜测是90crypt
在网络可用之前就进行了快速的运行,或者与我禁用了该事实有关systemd
。
所以我添加/sbin/ifup
到module-setup.sh
,并将其添加到我的cryptroot-ask.sh
:
ifup lo inet loopback
sleep 3
不知道我是否需要睡觉,但我还是把它放了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句