On Sat, Apr 23, 2005 at 22:32:24 +0200, Tino Keitel wrote:
> Hi,
> 
> here is a patch for mkinitrd to parse the cryptsetup options from
> /etc/cryptdisks, as it is already done by the initscript from the
> cryptsetup package.
> 
> Regards,
> Tino

...and here is the patch. :-)
diff -ur initrd-tools-0.1.78.orig/mkinitrd initrd-tools-0.1.78/mkinitrd
--- initrd-tools-0.1.78.orig/mkinitrd   2005-04-10 16:06:44.000000000 +0200
+++ initrd-tools-0.1.78/mkinitrd        2005-04-23 22:30:03.000000000 +0200
@@ -322,6 +322,66 @@
        fi
 }
 
+dmcrypt_parse_crypttab() {
+    TABFILE=/etc/crypttab
+
+    egrep "^$dmname" $TABFILE | while read dst src key opt ; do
+       if [ "x$key" != "x" ] && [ "x$key" != "xnone" ]; then
+           INTERACTIVE="no"
+       else
+           INTERACTIVE="yes"
+       fi
+
+       PARAMS=""
+
+       # Parse the options field, convert to cryptsetup parameters
+       # and contruct the command line
+       while test "x$opt" != "x" ; do
+           ARG=`echo $opt | sed "s/,.*//"`
+           opt=${opt##$ARG}
+           opt=${opt##,}
+           PARAM=`echo $ARG | sed "s/=.*//"`
+           VALUE=${ARG##$PARAM=}
+
+           case "$PARAM" in
+               cipher)
+                   PARAM=-c
+                   if test "x$VALUE" = "x" ; then
+                       echo "No value for cipher option." >&2
+                       exit 1
+                   fi
+                   ;;
+               size)
+                   PARAM=-s
+                   if test "x$VALUE" = "x" ; then
+                       echo "No value for size option." >&2
+                       exit 1
+                   fi
+                   ;;
+               hash)
+                   PARAM=-h
+                   if test "x$VALUE" = "x" ; then
+                       echo "No value for hash option." >&2
+                       exit 1
+                   fi
+                   ;;
+               verify)
+                   PARAM=-y
+                   VALUE=""
+                   ;;
+               esac
+
+           PARAMS="$PARAMS $PARAM $VALUE"
+       done
+
+       if test "x$INTERACTIVE" = "xyes" ; then
+           echo "$PARAMS"
+       else
+           echo "$PARAMS -d $key"
+       fi
+    done
+}
+
 dmcrypt() {
        local cipher_mode devname submajor subminor
        
@@ -340,6 +400,8 @@
                exit 1
        fi
        
+       export dmname
+       cryptcmd=`dmcrypt_parse_crypttab`
        eval "$(stat -c 'submajor=$((0x%t)); subminor=$((0x%T))' $(readlink -f 
"$devname"))"
        
        if [ $submajor != $(dmsetup deps $dmname | sed 's/^.*(\([0-9]*\), 
\([0-9]*\))$/\1/') \
@@ -349,7 +411,6 @@
        fi
                
        getroot $devname
-       
        cat <<EOF >&5
 mount_tmpfs dev2
 
@@ -364,6 +425,7 @@
 export device
 export dmname="$dmname"
 export cipher_mode="$cipher_mode"
+export cryptcmd="$cryptcmd"
 for i in /keyscripts/*; do
        [ -f "\$i" ] || continue
        case "\$i" in
@@ -376,7 +438,7 @@
        esac
 done
 [ -b /dev/mapper/\$dmname ] || \\
-       /sbin/cryptsetup -c \$cipher_mode create \$dmname \$device
+       /sbin/cryptsetup \$cryptcmd create \$dmname \$device
 
 umount -n dev2
 EOF
Only in initrd-tools-0.1.78: mkinitrd~

Reply via email to