cryptpilot-crypt 提供了一个 systemd 服务,可在系统启动时自动解密并打开加密卷。
cryptpilot.service systemd 单元在 System Manager 阶段运行(在 initrd 完成并且系统完全启动后)。它会自动处理所有在配置文件中设置了 auto_open = true 的卷。
- 服务单元:
cryptpilot.service - 位置:
/usr/lib/systemd/system/cryptpilot.service - 执行阶段:System Manager 阶段(启动后)
- 命令:
/usr/bin/cryptpilot-crypt boot-service --stage system-volumes-auto-open
在系统启动期间,该服务:
- 扫描
/etc/cryptpilot/volumes/中的所有卷配置文件 - 识别设置了
auto_open = true的卷 - 使用配置的密钥提供者尝试打开每个卷
- 在
/dev/mapper/<volume-name>创建设备映射节点 - 记录遇到的任何错误
要在启动时自动打开加密卷:
确保卷配置包含 auto_open = true:
# /etc/cryptpilot/volumes/data0.toml
volume = "data0"
dev = "/dev/nvme1n1p1"
auto_open = true
makefs = "ext4"
[encrypt.kbs]
url = "https://kbs.example.com"
resource_path = "/secrets/data0-key"启用并启动 systemd 服务:
systemctl enable --now cryptpilot.service此命令:
enable:配置服务在启动时自动启动--now:立即启动服务(对于当前会话)
检查服务是否正在运行:
systemctl status cryptpilot.service预期输出:
● cryptpilot.service - Auto-open encrypted volumes
Loaded: loaded (/usr/lib/systemd/system/cryptpilot.service; enabled; vendor preset: disabled)
Active: active (exited) since ...
启用自动打开后,可以在 /etc/fstab 中添加条目以实现自动挂载:
# /etc/fstab
/dev/mapper/data0 /mnt/data0 ext4 defaults 0 2这样可以实现完全自动化的解密和挂载:
cryptpilot.service打开加密卷 →/dev/mapper/data0systemd根据/etc/fstab挂载设备 →/mnt/data0
systemctl start cryptpilot.servicesystemctl stop cryptpilot.service注意:停止服务不会关闭已经打开的卷。使用 cryptpilot-crypt close <volume> 手动关闭卷。
systemctl restart cryptpilot.service要防止在启动时自动打开:
systemctl disable cryptpilot.service