/etc/crypttab 未在 initramfs 中更新

Bob*_*ina 4 zfs ubuntu initramfs luks crypttab

我新安装了 ubuntu 22.04,并从 ubuntu 安装程序选项中选择了全磁盘加密 (LUKS) 和 ZFS。

我需要进行一些编辑,/etc/crypttab以便以自动方式解锁我的驱动器(花式 USB 自动解锁),但我所做的编辑/etc/crypttab不会保留到 initramfs 中。

我正在做的是:

  • 编辑/etc/crypttab
  • 跑步update-initramfs -u
  • 重新启动我的机器进入要求输入 LUKS 密码的系统 (initramfs)
  • 检查内容,/etc/但不存在 cryptotab。

我对它的工作原理的理解是否错误?我需要将某些版本的 crypttab 保留到加载程序,但它不起作用。

有任何指示我做错了什么吗?

Jaa*_*ens 8

我来这里是因为我遇到了同样的问题,通过谷歌找到了这个问题,并且有一些信息要添加。我正在尝试在不输入密码的情况下自动解锁 LUKS 驱动器。

首先,我将/etc/crypttab其条目编辑并更改为以下内容:

sda3_crypt UUID=2d661ff8-d6a8-49c9-ae96-4d6e234bffe2 /dev/zero luks,discard,keyfile-size=32      
Run Code Online (Sandbox Code Playgroud)

然后,我使用以下命令添加了一个新密钥:

sudo cryptsetup luksAddKey --new-keyfile-size 32 /dev/sda3 /dev/zero
Run Code Online (Sandbox Code Playgroud)

最后,我运行了update-initramfs以下输出:

$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-6.0.0-2-amd64
cryptsetup: WARNING: sda3_crypt: key file /dev/zero has insecure ownership, see 
    /usr/share/doc/cryptsetup/README.Debian.gz.
cryptsetup: WARNING: Skipping root target sda3_crypt: uses a key file
Run Code Online (Sandbox Code Playgroud)

这看起来已经很可疑了,但我还是重新启动了。不幸的是,这些操作导致系统无法启动:

Gave up waiting for suspend/resume device
Gave up waiting for root file system device: Common problems:
 - Boot args (cat /proc/cmdline)
   - Check rootdelay= (did the system wait long enough?)
 - Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/mapper/legend--vg-root does not exist. Dropping to a shell!


BusyBox v1.35.0 (Debian 1: 1.135.0-2) built-in shell (ash)
Enter 'help' for a list of built-in commands.

(initramfs) cat /etc/crypttab
cat: can't open '/etc/crypttab': No such file or directory
Run Code Online (Sandbox Code Playgroud)

通过在 BusyBox 提示符下输入以下命令,我能够再次成功启动系统:

cryptsetup luksOpen --key-file /dev/zero --keyfile-size 32 /dev/sda3 sda3_crypt
exit
Run Code Online (Sandbox Code Playgroud)

但最初的问题仍然存在:为什么/etc/crypttabinitramfs 中不可用?

更新

经过更多研究,我现在终于可以回答最初的问题:/etc/crypttabinitramfs 中不存在,因为默认解锁脚本不使用该位置;它使用/cryptroot/crypttab相反。

要像 initramfs 中/etc/crypttab一样可用/cryptroot/crypttab,请在目录中创建以下脚本/etc/initramfs-tools/hooks并使其可执行:

#!/bin/sh
cp /etc/crypttab "${DESTDIR}/cryptroot/crypttab"
exit 0
Run Code Online (Sandbox Code Playgroud)

最后,请注意,使用空密码来自动解锁 LUKS 设备违背了加密的目的。它与根本不使用加密一样不安全。