Jon*_*aco 104 encryption lvm suspend luks
这个问题与@Stefan 的另一个问题有关,但它不是它的重复。问题略有不同:作者只是想知道这是否已实现,而我正在寻求有关如何执行此操作(以特定方式)的帮助。此外,另一个问题对实施者没有有用的答案,除了最近的一个仅与我对此的尝试有关的问题。
解释了“重复”问题后......
我在 Ubuntu 14.04 上使用全盘加密(LVM 在 LUKS 之上),我想合并luksSuspend到挂起过程中(以及以后使用luksResume),这样我就可以挂起到 RAM 而不会将密钥材料留在内存中,并且根解锁。
我试图为 Arch Linux移植一个脚本,到目前为止没有成功:老实说,我不知道我在做什么......
谁能帮我移植这个(或从头开始创建这样的东西)?或者,至少,任何人都可以向我指出有关如何将内容挂钩到挂起过程以及如何在所有到 root 的 IO 已被阻止(由luksSuspend)之后保持必要的二进制文件和脚本(例如 cryptsetup)可用的文档?
关于如何保持必要的二进制文件和脚本可用于简历,这篇另一篇博文(也适用于 Arch)将它们复制到/boot; 然而,我想在 Vianney 在我之前提到的脚本中使用的行中使用更多的东西,因为这种方法在这方面似乎更优雅一些。
很抱歉声明显而易见的事实,但是您是否尝试过将包含 cryptsetup luksSuspend/luksResume 命令的脚本添加到/usr/lib/pm-utils/sleep.d?如果是这样,发生了什么?
对我来说,在休眠/恢复上调用停止/启动 cryptdisks 和 cryptdisks_early 服务似乎是合乎逻辑的。在脚本中调用 cryptdisks_stop 和 cryptdisks_start 可以pm-utils/sleep.d解决问题吗?我认为这与直接调用具有相同的结果cryptsetup luksSuspend。
我能找到的最接近的解决方案是 Mikko Rauhala 的 2013 年概念验证 suspend.sh 脚本。
#!/bin/sh
# A proof of concept script for forgetting LUKS passwords on suspend
# and reasking them on resume.
# The basic idea is to copy all of the files necessary for luksResume
# onto a RAM disk so that we can be sure they'll be available without
# touching the disk at all. Then switch to a text VT to run the resume
# (easier to make sure it'll come up than to do the same with X).
# The suspend itself has to be done from the ramdisk too to make sure it
# won't hang. This is also a reason why this couldn't be reliably done as a
# self-contained /etc/pm/sleep.d script, so to make the concept clear
# (and because I'm lazy) I did just a minimal standalone proof of concept
# instead. Integrating the functionality into the usual pm tools would be
# encouraged. (Though suspend_pmu would apparently need perl on the ramdisk...)
# (C) 2013 Mikko Rauhala 2013, modifiable and distributable under
# CC0, GPLv2 or later, MIT X11 license or 2-clause BSD. Regardless
# of what you pick, there is NO WARRANTY of any kind.
RAMDEV=/dev/ram0
ROOT=/run/cryptosuspend
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# Cleanup not strictly necessary every time but good for development.
# Doing it before rather than after a suspend for debugging purposes
for a in "$ROOT"/dev/pts "$ROOT"/proc "$ROOT"/sys "$ROOT" ; do
umount "$a" > /dev/null 2>&1
done
if mount | grep -q "$ROOT" ; then
echo "Cleanup unsuccessful, cryptosuspend root premounted." 1>&2
exit 2
fi
if grep -q mem /sys/power/state; then
METHOD=mem
elif grep -q standby /sys/power/state; then
METHOD=standby
else
echo "No mem or standby states available, aborting" 1>&2
exit 1
fi
if ! mount | grep -q "$RAMDEV" ; then
mkfs -t ext2 -q "$RAMDEV" 8192
mkdir -p "$ROOT"
mount "$RAMDEV" "$ROOT"
mkdir "$ROOT"/sbin "$ROOT"/bin "$ROOT"/dev "$ROOT"/tmp "$ROOT"/proc "$ROOT"/sys
cp "$(which cryptsetup)" "$ROOT"/sbin
for a in $(ldd "$(which cryptsetup)" | grep "/" | cut -d / -f 2- | cut -d " " -f 1) ; do
mkdir -p "$ROOT""$(dirname /$a)"
cp "/$a" "$ROOT"/"$a"
done
cp "$(which busybox)" "$ROOT"/bin/
ln -s busybox "$ROOT"/bin/sh
ln -s busybox "$ROOT"/bin/sync
cp -a /dev "$ROOT"
mount -t proc proc "$ROOT"/proc
mount -t sysfs sysfs "$ROOT"/sys
mount -t devpts devpts "$ROOT"/dev/pts
fi
CRYPTDEVS="$(dmsetup --target crypt status | cut -d : -f 1)"
echo '#!/bin/sh' > "$ROOT"/bin/cryptosuspend
echo "sync" >> "$ROOT"/bin/cryptosuspend
echo "for a in $CRYPTDEVS ; do" >> "$ROOT"/bin/cryptosuspend
echo " cryptsetup luksSuspend \$a" >> "$ROOT"/bin/cryptosuspend
echo "done" >> "$ROOT"/bin/cryptosuspend
echo "echo -n \"$METHOD\" > /sys/power/state" >> "$ROOT"/bin/cryptosuspend
echo "for a in $CRYPTDEVS ; do" >> "$ROOT"/bin/cryptosuspend
echo ' while ! cryptsetup luksResume'" \$a ; do" >> "$ROOT"/bin/cryptosuspend
echo " true" >> "$ROOT"/bin/cryptosuspend
echo " done" >> "$ROOT"/bin/cryptosuspend
echo "done" >> "$ROOT"/bin/cryptosuspend
chmod a+rx "$ROOT"/bin/cryptosuspend
sync
exec openvt -s chroot "$ROOT" /bin/cryptosuspend
Run Code Online (Sandbox Code Playgroud)
为了将其移植到 Ubuntu 14.04,我们已经完成了一些工作。这绝不是一个完美的解决方案,因为仍然存在一些未解决的问题,并且自 2014 年 6 月 11 日以来似乎没有发布任何工作。然而,这似乎是未来开发的良好起点。
来源: https: //github.com/jonasmalacofilho/ubuntu-luks-suspend