2 # TODO this one needs some work to work with lots of different
6 /sbin/modprobe -a -q dm-crypt >/dev/null 2>&1
7 if [ -e "/sys/class/misc/device-mapper" ]; then
8 if [ ! -e "/dev/mapper/control" ]; then
10 mknod "/dev/mapper/control" c $(cat /sys/class/misc/device-mapper/dev | sed 's|:| |')
12 [ "${quiet}" = "y" ] && CSQUIET=">/dev/null"
14 # Get keyfile if specified
15 ckeyfile="/crypto_keyfile.bin"
16 if [ "x${cryptkey}" != "x" ]; then
17 ckdev="$(echo "${cryptkey}" | cut -d: -f1)"
18 ckarg1="$(echo "${cryptkey}" | cut -d: -f2)"
19 ckarg2="$(echo "${cryptkey}" | cut -d: -f3)"
20 if poll_device "${ckdev}" ${rootdelay}; then
23 # Use a file on the device
24 # ckarg1 is not numeric: ckarg1=filesystem, ckarg2=path
26 mount -r -t ${ckarg1} ${ckdev} /ckey
27 dd if=/ckey/${ckarg2} of=${ckeyfile} >/dev/null 2>&1
31 # Read raw data from the block device
32 # ckarg1 is numeric: ckarg1=offset, ckarg2=length
33 dd if=${ckdev} of=${ckeyfile} bs=1 skip=${ckarg1} count=${ckarg2} >/dev/null 2>&1
37 [ ! -f ${ckeyfile} ] && echo "Keyfile could not be opened. Reverting to passphrase."
40 if [ -n "${cryptdevice}" ]; then
42 cryptdev="$(echo "${cryptdevice}" | cut -d: -f1)"
43 cryptname="$(echo "${cryptdevice}" | cut -d: -f2)"
51 echo "The syntax 'root=${root}' where '${root}' is an encrypted volume is deprecated"
52 echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
55 if poll_device "${cryptdev}" ${rootdelay}; then
56 if /sbin/cryptsetup isLuks ${cryptdev} >/dev/null 2>&1; then
57 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
59 # If keyfile exists, try to use that
60 if [ -f ${ckeyfile} ]; then
61 if eval /sbin/cryptsetup --key-file ${ckeyfile} luksOpen ${cryptdev} ${cryptname} ${CSQUIET}; then
64 echo "Invalid keyfile. Reverting to passphrase."
67 # Ask for a passphrase
68 if [ ${dopassphrase} -gt 0 ]; then
70 echo "A password is required to access the ${cryptname} volume:"
72 #loop until we get a real password
73 while ! eval /sbin/cryptsetup luksOpen ${cryptdev} ${cryptname} ${CSQUIET}; do
77 if [ -e "/dev/mapper/${cryptname}" ]; then
78 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
79 export root="/dev/mapper/root"
82 err "Password succeeded, but ${cryptname} creation failed, aborting..."
85 elif [ -n "${crypto}" ]; then
86 [ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
87 msg "Non-LUKS encrypted device found..."
89 err "Verify parameter format: crypto=hash:cipher:keysize:offset:skip"
90 err "Non-LUKS decryption not attempted..."
93 exe="/sbin/cryptsetup create ${cryptname} ${cryptdev}"
94 tmp=$(echo "${crypto}" | cut -d: -f1)
95 [ -n "${tmp}" ] && exe="${exe} --hash \"${tmp}\""
96 tmp=$(echo "${crypto}" | cut -d: -f2)
97 [ -n "${tmp}" ] && exe="${exe} --cipher \"${tmp}\""
98 tmp=$(echo "${crypto}" | cut -d: -f3)
99 [ -n "${tmp}" ] && exe="${exe} --key-size \"${tmp}\""
100 tmp=$(echo "${crypto}" | cut -d: -f4)
101 [ -n "${tmp}" ] && exe="${exe} --offset \"${tmp}\""
102 tmp=$(echo "${crypto}" | cut -d: -f5)
103 [ -n "${tmp}" ] && exe="${exe} --skip \"${tmp}\""
104 if [ -f ${ckeyfile} ]; then
105 exe="${exe} --key-file ${ckeyfile}"
107 exe="${exe} --verify-passphrase"
109 echo "A password is required to access the ${cryptname} volume:"
111 eval "${exe} ${CSQUIET}"
113 if [ $? -ne 0 ]; then
114 err "Non-LUKS device decryption failed. verify format: "
115 err " crypto=hash:cipher:keysize:offset:skip"
118 if [ -e "/dev/mapper/${cryptname}" ]; then
119 if [ ${DEPRECATED_CRYPT} -eq 1 ]; then
120 export root="/dev/mapper/root"
123 err "Password succeeded, but ${cryptname} creation failed, aborting..."
127 err "Failed to open encryption mapping: The device ${cryptdev} is not a LUKS volume and the crypto= paramater was not specified."