Skip to content

Instantly share code, notes, and snippets.

@SamSirry
Forked from gusennan/crypt_unlock.sh
Last active March 7, 2021 18:02
Show Gist options
  • Select an option

  • Save SamSirry/fe6150f8bdcd86fea3258330d74318b6 to your computer and use it in GitHub Desktop.

Select an option

Save SamSirry/fe6150f8bdcd86fea3258330d74318b6 to your computer and use it in GitHub Desktop.
initramfs-hook for unlocking LUKS-encrypted LVM partition
#!/bin/sh
PREREQ="dropbear"
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. "${CONFDIR}/initramfs.conf"
. /usr/share/initramfs-tools/hook-functions
if [ "${DROPBEAR}" != "n" ] && [ -r "/etc/crypttab" ] ; then
cat > "${DESTDIR}/bin/u" << EOF
#!/bin/sh
if PATH=/lib/unlock:/bin:/sbin /scripts/local-top/cryptroot; then
kill \`ps | grep cryptroot | grep -v "grep" | awk '{print \$1}'\`
# following line kill the remote shell right after the passphrase has
# been entered.
kill -9 \`ps | grep "\-sh" | grep -v "grep" | awk '{print \$1}'\`
exit 0
fi
exit 1
EOF
chmod 755 "${DESTDIR}/bin/u"
mkdir -p "${DESTDIR}/lib/unlock"
cat > "${DESTDIR}/lib/unlock/plymouth" << EOF
#!/bin/sh
[ "\$1" == "--ping" ] && exit 1
/bin/plymouth "\$@"
EOF
chmod 755 "${DESTDIR}/lib/unlock/plymouth"
echo To unlock root-partition run u >> ${DESTDIR}/etc/motd
fi
@SamSirry

SamSirry commented Mar 7, 2021

Copy link
Copy Markdown
Author

changed the command from "unlock" to just "u" for simpler activation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment