Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyfile support #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion arch-luks-suspend
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ BIND_PATHS="/sys /proc /dev /run"
REMOUNT=0
# Retrieve cryptdevice name from boot cmdline
CRYPTNAME="$(sed -n 's/.*cryptdevice=[^: ]*:\([^: ]*\).*$/\1/p' /proc/cmdline)"
# Retrieve cryptkey from boot cmdline
CRYPTKEYDEV="$(sed -n 's/.*cryptkey=\([^: ]*\).*$/\1/p' /proc/cmdline)"
CRYPTKEYFS="$(sed -n 's/.*cryptkey=[^: ]*:\([^: ]*\).*$/\1/p' /proc/cmdline)"
CRYPTKEYFILE="$(sed -n 's/.*cryptkey=[^: ]*:[^: ]*:\([^: ]*\).*$/\1/p' /proc/cmdline)"

# run_dir DIR ARGS...
# Run all executable scripts in directory DIR with arguments ARGS
Expand Down Expand Up @@ -71,7 +75,7 @@ sync

# Hand over execution to script inside initramfs
cd "${INITRAMFS_DIR}"
chroot . /suspend "$CRYPTNAME"
chroot . /suspend "$CRYPTNAME" "$CRYPTKEYDEV" "$CRYPTKEYFS" "$CRYPTKEYFILE"

# Restore original mount options if necessary
if ((REMOUNT)); then
Expand Down
21 changes: 20 additions & 1 deletion initramfs-suspend
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/ash

cryptname="${1}"
cryptkeydev="${2}"
cryptkeyfs="${3}"
cryptkeyfile="${4}"
cryptkeymountpoint="/rootkey"

# Start udev from initramfs
/usr/lib/systemd/systemd-udevd --daemon --resolve-names=never
Expand All @@ -11,9 +15,24 @@ cryptname="${1}"
# Suspend the system
echo mem > /sys/power/state

# Mount keydev
if [ -n "${cryptkeydev}" ] && [ -n "${cryptkeyfs}" ] && [ -n "${cryptkeyfile}" ]
then
mkdir "${cryptkeymountpoint}"
while ! mount -t "${cryptkeyfs}" "${cryptkeydev}" "${cryptkeymountpoint}"; do sleep 2; done
lukskeyfilearg="--key-file ${cryptkeymountpoint}${cryptkeyfile}"
fi

# Resume root device
[ -z "${cryptname}" ] ||
while ! cryptsetup luksResume "${cryptname}"; do sleep 2; done
while ! cryptsetup luksResume ${lukskeyfilearg} "${cryptname}"; do sleep 2; done

# Clean up keyfile
if [ -d "${cryptkeymountpoint}" ]
then
umount "${cryptkeymountpoint}"
rmdir "${cryptkeymountpoint}"
fi

# Stop udev from initramfs, as the real daemon from rootfs will be restarted
udevadm control --exit