4 modprobe
-a -q dm-crypt
>/dev
/null
2>&1
5 [ "${quiet}" = "y" ] && CSQUIET
=">/dev/null"
7 # Get keyfile if specified
8 ckeyfile
="/crypto_keyfile.bin"
9 if [ -n "$cryptkey" ]; then
10 IFS
=: read ckdev ckarg1 ckarg2
<<EOF
14 if [ "$ckdev" = "rootfs" ]; then
16 elif resolved
=$
(resolve_device
"${ckdev}" ${rootdelay}); then
19 # Use a file on the device
20 # ckarg1 is not numeric: ckarg1=filesystem, ckarg2=path
22 mount
-r -t "$ckarg1" "$resolved" /ckey
23 dd if="/ckey/$ckarg2" of
="$ckeyfile" >/dev
/null
2>&1
27 # Read raw data from the block device
28 # ckarg1 is numeric: ckarg1=offset, ckarg2=length
29 dd if="$resolved" of
="$ckeyfile" bs
=1 skip
="$ckarg1" count
="$ckarg2" >/dev
/null
2>&1
33 [ ! -f ${ckeyfile} ] && echo "Keyfile could not be opened. Reverting to passphrase."
36 if [ -n "${cryptdevice}" ]; then
38 IFS
=: read cryptdev cryptname cryptoptions
<<EOF
48 echo "The syntax 'root=${root}' where '${root}' is an encrypted volume is deprecated"
49 echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
52 for cryptopt
in ${cryptoptions//,/ }; do
55 cryptargs
="${cryptargs} --allow-discards"
58 echo "Encryption option '${cryptopt}' not known, ignoring." >&2
63 if resolved
=$
(resolve_device
"${cryptdev}" ${rootdelay}); then
64 if cryptsetup isLuks
${resolved} >/dev
/null
2>&1; then
65 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
67 # If keyfile exists, try to use that
68 if [ -f ${ckeyfile} ]; then
69 if eval cryptsetup
--key-file ${ckeyfile} open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; then
72 echo "Invalid keyfile. Reverting to passphrase."
75 # Ask for a passphrase
76 if [ ${dopassphrase} -gt 0 ]; then
78 echo "A password is required to access the ${cryptname} volume:"
80 #loop until we get a real password
81 while ! eval cryptsetup open
--type luks
${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do
85 if [ -e "/dev/mapper/${cryptname}" ]; then
86 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
87 export root
="/dev/mapper/root"
90 err
"Password succeeded, but ${cryptname} creation failed, aborting..."
93 elif [ -n "${crypto}" ]; then
94 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
95 msg
"Non-LUKS encrypted device found..."
96 if echo "$crypto" |
awk -F: '{ exit(NF == 5) }'; then
97 err
"Verify parameter format: crypto=hash:cipher:keysize:offset:skip"
98 err
"Non-LUKS decryption not attempted..."
101 exe
="cryptsetup open --type plain $resolved $cryptname $cryptargs"
102 IFS
=: read c_hash c_cipher c_keysize c_offset c_skip
<<EOF
105 [ -n "$c_hash" ] && exe
="$exe --hash '$c_hash'"
106 [ -n "$c_cipher" ] && exe
="$exe --cipher '$c_cipher'"
107 [ -n "$c_keysize" ] && exe
="$exe --key-size '$c_keysize'"
108 [ -n "$c_offset" ] && exe
="$exe --offset '$c_offset'"
109 [ -n "$c_skip" ] && exe
="$exe --skip '$c_skip'"
110 if [ -f "$ckeyfile" ]; then
111 exe
="$exe --key-file $ckeyfile"
113 exe
="$exe --verify-passphrase"
115 echo "A password is required to access the ${cryptname} volume:"
119 if [ $?
-ne 0 ]; then
120 err
"Non-LUKS device decryption failed. verify format: "
121 err
" crypto=hash:cipher:keysize:offset:skip"
124 if [ -e "/dev/mapper/${cryptname}" ]; then
125 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
126 export root
="/dev/mapper/root"
129 err
"Password succeeded, but ${cryptname} creation failed, aborting..."
133 err
"Failed to open encryption mapping: The device ${cryptdev} is not a LUKS volume and the crypto= paramater was not specified."
139 # vim: set ft=sh ts=4 sw=4 et: