Creating a LUKS Encrypted Partition

# fdisk /dev/sdb
p
Difference between total and end block is the free space.
n > primary > 2 > Default sector > +100MB
p > w
Update kernel partition tabel:
# partprobe /dev/sdb
# cat /proc/partitions
Now I can create the crypt volume.
Use cryptsetup
# cryptsetup luksFormat /dev/sdb2
yes >
Now the partition encrypted is created.
In order to use it, make mount point:
# mkdir /secret
Open before mount. Need to provide a name to partition. In this case is “secret”
# cryptsetup luksOpen /dev/sdb2 secret
/dev/mapper – should contain the encrypted partition: /dev/mapper/secret.
Make a file system on this device. This time mkfs.ext4
# mkfs.ext4 /dev/mapper/secret
Now I can mount it:
# mount /dev/mapper/secret /secret
NEVER disconnect an encrypted partition but if have to do it:
# umount /secret
# cryptsetup lucksClose /dev/mapper/secret
Now the secret device is secured unmounted and closed.
Add the partition to fstab:
# vi /etc/fstab
/dev/mapper/secret /secret ext4 defaults 1 2
At this moment will not work because there is no /dev/mapper/secret.
I have to create a file /etc/crypttab
vi /etc/cryptatab
nameOfDevice nameOfPartition passwordUsage
secret /dev/sdb2 none

The only way to test is by reboot.