Encrypt debian partition

Hello all, here is a simple howto on encrypting a linux partition: in my example, I will be using sda3 partition mounted on /opt.

Warning: partition sda3 will be erased!

First of all we need to install the package to allow it all:
apt-get install cryptsetup

Then load the necessary modules:

modprobe aes-i586
modprobe dm_mod
modprobe dm_crypt

Next we create the secure partition:
cryptsetup luksFormat -c aes-cbc-essiv:sha256 /dev/sda3

You will be prompted for password... This password will be used to open the partition

To open the secure partition:
cryptsetup luksOpen /dev/sda3 secure

Next we need to format the partition to EXT3:
mkfs.ext3 /dev/mapper/secure

Let's create two scripts to mount and unmount the newly created device:

First script's usage will be for unlocking the device and mounting the encrypted partition:

#! /bin/sh
cryptsetup luksOpen /dev/sda3 secure
mount -t ext3 /dev/mapper/secure /opt/

Second script's usage will be for unmounting the encrypted partition and lock the device:

#! /bin/sh
umount /opt/
cryptsetup luksClose secure

That's it!