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
47 # This may happen if third party hooks do the crypt setup
48 if [ -b "/dev/mapper/${cryptname}" ]; then
49 echo "Device ${cryptname} already exists, not doing any crypt setup."
54 echo "The syntax 'root=${root}' where '${root}' is an encrypted volume is deprecated"
55 echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
60 for cryptopt
in ${cryptoptions}; do
62 allow-discards|discard
)
63 cryptargs
="${cryptargs} --allow-discards"
65 no-read-workqueue|perf-no_read_workqueue
)
66 cryptargs
="${cryptargs} --perf-no_read_workqueue"
68 no-write-workqueue|perf-no_write_workqueue
)
69 cryptargs
="${cryptargs} --perf-no_write_workqueue"
72 echo "Encryption option '${cryptopt}' not known, ignoring." >&2
80 if resolved
=$
(resolve_device
"${cryptdev}" ${rootdelay}); then
81 if cryptsetup isLuks
${resolved} >/dev
/null
2>&1; then
82 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
84 # If keyfile exists, try to use that
85 if [ -f ${ckeyfile} ]; then
86 if eval cryptsetup
--key-file ${ckeyfile} open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; then
89 echo "Invalid keyfile. Reverting to passphrase."
92 # Ask for a passphrase
93 if [ ${dopassphrase} -gt 0 ]; then
95 echo "A password is required to access the ${cryptname} volume:"
97 #loop until we get a real password
98 while ! eval cryptsetup open
--type luks
${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do
102 if [ -e "/dev/mapper/${cryptname}" ]; then
103 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
104 export root
="/dev/mapper/root"
107 err
"Password succeeded, but ${cryptname} creation failed, aborting..."
110 elif [ -n "${crypto}" ]; then
111 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
112 msg
"Non-LUKS encrypted device found..."
113 if echo "$crypto" |
awk -F: '{ exit(NF == 5) }'; then
114 err
"Verify parameter format: crypto=hash:cipher:keysize:offset:skip"
115 err
"Non-LUKS decryption not attempted..."
118 exe
="cryptsetup open --type plain $resolved $cryptname $cryptargs"
119 IFS
=: read c_hash c_cipher c_keysize c_offset c_skip
<<EOF
122 [ -n "$c_hash" ] && exe
="$exe --hash '$c_hash'"
123 [ -n "$c_cipher" ] && exe
="$exe --cipher '$c_cipher'"
124 [ -n "$c_keysize" ] && exe
="$exe --key-size '$c_keysize'"
125 [ -n "$c_offset" ] && exe
="$exe --offset '$c_offset'"
126 [ -n "$c_skip" ] && exe
="$exe --skip '$c_skip'"
127 if [ -f "$ckeyfile" ]; then
128 exe
="$exe --key-file $ckeyfile"
131 echo "A password is required to access the ${cryptname} volume:"
135 if [ $?
-ne 0 ]; then
136 err
"Non-LUKS device decryption failed. verify format: "
137 err
" crypto=hash:cipher:keysize:offset:skip"
140 if [ -e "/dev/mapper/${cryptname}" ]; then
141 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
142 export root
="/dev/mapper/root"
145 err
"Password succeeded, but ${cryptname} creation failed, aborting..."
149 err
"Failed to open encryption mapping: The device ${cryptdev} is not a LUKS volume and the crypto= paramater was not specified."
155 # vim: set ft=sh ts=4 sw=4 et: