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} luksOpen ${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:"
79 plymouth ask-for-password --prompt="Password for ${cryptname} volume" --dont-pause-progress --number-of-tries=5 --command="/sbin/cryptsetup luksOpen --key-file=- ${resolved} ${cryptname} ${cryptargs} ${CSQUIET}"
82 if [ -e "/dev/mapper/${cryptname}" ]; then
83 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
84 export root="/dev/mapper/root"
87 err "Password succeeded, but ${cryptname} creation failed, aborting..."
90 elif [ -n "${crypto}" ]; then
91 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
92 msg "Non-LUKS encrypted device found..."
93 if echo "$crypto" | awk -F: '{ exit(NF == 5) }'; then
94 err "Verify parameter format: crypto=hash:cipher:keysize:offset:skip"
95 err "Non-LUKS decryption not attempted..."
98 exe="cryptsetup create $cryptname $resolved $cryptargs"
99 IFS=: read c_hash c_cipher c_keysize c_offset c_skip <<EOF
102 [ -n "$c_hash" ] && exe="$exe --hash '$c_hash'"
103 [ -n "$c_cipher" ] && exe="$exe --cipher '$c_cipher'"
104 [ -n "$c_keysize" ] && exe="$exe --key-size '$c_keysize'"
105 [ -n "$c_offset" ] && exe="$exe --offset '$c_offset'"
106 [ -n "$c_skip" ] && exe="$exe --skip '$c_skip'"
107 if [ -f "$ckeyfile" ]; then
108 exe="$exe --key-file $ckeyfile"
110 exe="$exe --verify-passphrase"
112 echo "A password is required to access the ${cryptname} volume:"
116 if [ $? -ne 0 ]; then
117 err "Non-LUKS device decryption failed. verify format: "
118 err " crypto=hash:cipher:keysize:offset:skip"
121 if [ -e "/dev/mapper/${cryptname}" ]; then
122 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
123 export root="/dev/mapper/root"
126 err "Password succeeded, but ${cryptname} creation failed, aborting..."
130 err "Failed to open encryption mapping: The device ${cryptdev} is not a LUKS volume and the crypto= paramater was not specified."