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 cryptargs
="${cryptargs} --sector-size ${cryptopt#*=}"
75 echo "Encryption option '${cryptopt}' not known, ignoring." >&2
83 if resolved
=$
(resolve_device
"${cryptdev}" ${rootdelay}); then
84 if cryptsetup isLuks
${resolved} >/dev
/null
2>&1; then
85 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
87 # If keyfile exists, try to use that
88 if [ -f ${ckeyfile} ]; then
89 if eval cryptsetup
--key-file ${ckeyfile} open --type luks ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; then
92 echo "Invalid keyfile. Reverting to passphrase."
95 # Ask for a passphrase
96 if [ ${dopassphrase} -gt 0 ]; then
97 if command -v plymouth
>/dev
/null
2>&1 && plymouth
--ping 2>/dev
/null
; then
98 plymouth ask-for-password \
99 --prompt="A password is required to access the ${cryptname} volume" \
100 --command="cryptsetup open --type luks --key-file=- ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}"
103 echo "A password is required to access the ${cryptname} volume:"
105 #loop until we get a real password
106 while ! eval cryptsetup open
--type luks
${resolved} ${cryptname} ${cryptargs} ${CSQUIET}; do
111 if [ -e "/dev/mapper/${cryptname}" ]; then
112 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
113 export root
="/dev/mapper/root"
116 err
"Password succeeded, but ${cryptname} creation failed, aborting..."
119 elif [ -n "${crypto}" ]; then
120 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
121 msg
"Non-LUKS encrypted device found..."
122 if echo "$crypto" |
awk -F: '{ exit(NF == 5) }'; then
123 err
"Verify parameter format: crypto=hash:cipher:keysize:offset:skip"
124 err
"Non-LUKS decryption not attempted..."
127 exe
="cryptsetup open --type plain $resolved $cryptname $cryptargs"
128 IFS
=: read c_hash c_cipher c_keysize c_offset c_skip
<<EOF
131 [ -n "$c_hash" ] && exe
="$exe --hash '$c_hash'"
132 [ -n "$c_cipher" ] && exe
="$exe --cipher '$c_cipher'"
133 [ -n "$c_keysize" ] && exe
="$exe --key-size '$c_keysize'"
134 [ -n "$c_offset" ] && exe
="$exe --offset '$c_offset'"
135 [ -n "$c_skip" ] && exe
="$exe --skip '$c_skip'"
136 if [ -f "$ckeyfile" ]; then
137 exe
="$exe --key-file $ckeyfile"
140 echo "A password is required to access the ${cryptname} volume:"
144 if [ $?
-ne 0 ]; then
145 err
"Non-LUKS device decryption failed. verify format: "
146 err
" crypto=hash:cipher:keysize:offset:skip"
149 if [ -e "/dev/mapper/${cryptname}" ]; then
150 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
151 export root
="/dev/mapper/root"
154 err
"Password succeeded, but ${cryptname} creation failed, aborting..."
158 err
"Failed to open encryption mapping: The device ${cryptdev} is not a LUKS volume and the crypto= paramater was not specified."
164 # vim: set ft=sh ts=4 sw=4 et: