Skip to content

Instantly share code, notes, and snippets.

@johnlane
Created December 9, 2014 12:55
Show Gist options
  • Save johnlane/31840508fdca094fac7e to your computer and use it in GitHub Desktop.
Save johnlane/31840508fdca094fac7e to your computer and use it in GitHub Desktop.
initrd support for crypt key file with offset and size
--- encrypt_hook 2014-12-09 12:47:02.379911026 +0000
+++ encrypt_hook 2014-12-09 12:47:41.416087076 +0000
@@ -7,7 +7,7 @@
# Get keyfile if specified
ckeyfile="/crypto_keyfile.bin"
if [ -n "$cryptkey" ]; then
- IFS=: read ckdev ckarg1 ckarg2 <<EOF
+ IFS=: read ckdev ckarg1 ckarg2 ckarg3 ckarg4 <<EOF
$cryptkey
EOF
@@ -18,9 +18,13 @@
*[!0-9]*)
# Use a file on the device
# ckarg1 is not numeric: ckarg1=filesystem, ckarg2=path
+ # ckarg3=offset, ckarg4=length
mkdir /ckey
mount -r -t "$ckarg1" "$resolved" /ckey
- dd if="/ckey/$ckarg2" of="$ckeyfile" >/dev/null 2>&1
+ [ -n "$ckarg3$ckarg4" ] && ckoffset="bs=1"
+ [ -n "$ckarg3" ] && ckoffset="$ckoffset skip=$ckarg3"
+ [ -n "$ckarg4" ] && ckoffset="$ckoffset count=$ckarg4"
+ dd if="/ckey/$ckarg2" of="$ckeyfile" $ckoffset >/dev/null 2>&1
umount /ckey
;;
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment