Thu 09 of Sep, 2010 [12:44 UTC]  
Menu

mkcfs

mkcfs
edit print PDF
Português Brasileiro
This scripts creates a crypted device using dm_crypt and formats it with the given filesystem. There is some error checking and you have the possibillity to create commands like mkcfs.ext3 to make the filesystem type parameter obsolete.

Simply link the script to all file system types you want:
ln -s mkcfs mkcfs.ext3
ln -s mkcfs mkcfs.ext2
ln -s mkcfs mkcfs.xfs
...

These links will use the commands mkfs.??? to format the encrypted device.

To use the links use the following syntax: mkcfs.??? <device> <cypher> <keysize>
Remember: The keysize has to be entered in bits.

If you use the standard script only, you have to this syntax: mkcfs <filesystem> <device> <cypher> <keysize>

You should save the main script as /bin/mkcfs and make it executable with: chmod +x /bin/mkcfs

Ok, now comes the script:

fsType=`echo $0 | cut -d'.' -f2`

if test $fsType == $0
then
#filesystem type is not part of the executable name
        if test $# != 4
        then
        #filesystem type was NOT given as parameter
                echo "filesystem type missing!"
                echo "$0 <filesystem> <device> <cypher> <keysize>"
                exit 100
        else
        #filesystem type was given as parameter
                fsType=`echo $1`
                dev=`echo $2`
                cypher=`echo $3`
                keysize=`echo $4`
        fi
else
        if test $# != 3
        then
                echo "$0 <device> <cypher> <keysize>"
                exit 105
        else
                dev=`echo $1`
                cypher=`echo $2`
                keysize=`echo $3`
        fi
fi

#check if the device to format exists
if test $dev
then
        if test -b $dev
        then
                echo "device \"$dev\": OK "
        else
                echo "device \"$dev\": not found!"
                exit 101
        fi
else
        echo "no device name given!"
        exit 102
fi

#check for the formating programm
if test -f /sbin/mkfs.$fsType
then
        echo "format command \"mkfs.$fsType\" found"
else
        echo "can't find formating programm for \"$fsType\"!"
        exit 103
fi

mappername=`echo $dev | sed 's/\//_/g'`

cryptsetup remove $mappername 2> /dev/null
cryptsetup -y -c $cypher -s $keysize create $mappername $dev
mkfs.$fsType /dev/mapper/$mappername




Help = Ajuda

Created by: hhabermann last modification: Thursday 05 of August, 2010 [12:43:57 UTC] by Anonymous