dmcryptThis is instructions for using dm-crypt. Dm-crypt is faster than cryptloop and easier than loop-aes. See elsewhere for cryptloop (obsolete) or loop-aes (more secure, faster).From the websiteDevice-mapper is a new infrastructure in the Linux 2.6 kernel that provides a generic way to create virtual layers of block devices that can do different things on top of real block devices like striping, concatenation, mirroring, snapshotting, etc... The device-mapper is used by the LVM2 and EVMS 2.x tools. dm-crypt is such a device-mapper target that provides transparent encryption of block devices using the new Linux 2.6 cryptoapi. Writes to this device will be encrypted and reads decrypted. You can mount your filesystem on it as usual. But without the key you can't access your data. It does basically the same as cryptoloop only that it's a much cleaner code and better suits the need of a block device and has a more flexible configuration interface. The on-disk format is also compatible.website: www.saout.de/misc/dm-crypt/ a dm-crypt wiki: www.saout.de/tikiwiki/ cipher speed comparisons: fp.gladman.plus.com/cryptography_technology/aesr2/ set up kernelThe stock debian 2.6 kernel-images seem to work fine. If you are compiling your own, these are what you must choose:
# ls -L /dev/mapper/control
# cat /proc/crypto
name : aes
# insmod /lib/modules/2.6.7-1-386/kernel/crypto/aes.ko
# modprobe aes
install user space toolsdmsetupInstall dmsetup, the linux kernel Device Mapper userspace library:# apt-get install dmsetup
# dmsetup targets
cryptsetupcryptsetup is a tool to make it easier to use dm-crypt, so that you don't have to make dmsetup calls directly.# apt-get install cryptsetup
next stepsnow you must decide if you want to use a partition or a loop file as the underlying device used by device mapper.encrypted partitionsThis is instructions for using dm-crypt to create a filesystem in a partition. See below for how to do set up dm-crypt with a loopback file instead.creating the encrypted partitionIt is a three step process to create our encrypted partition:
# cryptsetup -y create maildir /dev/sda9
# cryptsetup -c aes -h ripemd160 -s 32 create maildir /dev/sda9
# dmsetup ls
# mkfs.reiserfs /dev/mapper/maildir
# mount /dev/mapper/maildir /var/maildir
real world usageEvery time we restart, we need to re-run the cryptsetup command and enter the same password. If we enter the wrong password, the encrypted device created won't be mountable and we need to destroy it and try again. Don't worry: as long as we don't reformat the device created with the wrong password, no data will be lost. There are two ways we can do all this: on boot, or by manually running a scripton boot wayYou can edit fstab to have /dev/mapper/maildir mounted to /var/maildir. This will only work if cryptsetup is run before partitions are read from fstab. /etc/init.d/cryptinit:if [ -b /dev/mapper/home ]; then
# cd/etc/rcS.d
manuallyjust run this script to get the partition up:if [ -b /dev/mapper/maildir ]; then
dmcrypt home partitionsto have pam mount your encrypted home partition automatically at login, make these changes:apt-get install libpam-mount cryptsetup openssl
auth optional pam_mount.so use_first_pass
session optional pam_mount.so
volume elijah crypt - /dev/hda4 /home/elijah cipher=aes aes-256-ecb /home/elijah.key
echo "my dmcrypt password" | openssl aes-256-ecb > /home/elijah.key
volume elijah crypt - /dev/hda4 /home/elijah cipher=aes - -
CLOSE_SESSIONS yes
volume elijah crypt - /home/home.img /home/elijah loop,cipher=aes aes-256-ecb /home/home.key
encrypted loopbackThis is instructions for using dm-crypt to create a filesystem in a loopback file, this means storing an encrypted filesystem in one individual file. This is useful if you cannot or do not want to encrypt your entire partition. See above for how to do an entire partition. What if you already have a filesystem, such as your /home directory, that you realize later that you want to encrypt but you cannot destroy that filesystem and then recreate it. Or perhaps you just want to encrypt part of it, you can do this with a dm_crypt loopback encrypted file.setupFollow the same setup instructions as for partitions, but stop after installing cryptsetup.creating the loopbackYou must create a loopback file, this is just going to be a regular file on your filesystem made up of random data. Make the loopback file as large as you are going to want your encrypted loopback to be. The following creates a 100 meg file of random data at the location /home/secret:# dd if=/dev/urandom of=/home/secret bs=1M count=100
# losetup /dev/loop0 /home/secret
encrypt the loopbackIt is a three step process to create our encrypted partition:
# cryptsetup -y create mycryprt /dev/loop0
# dmsetup ls
# mkfs.ext3 /dev/mapper/mycrypt
# mount /dev/mapper/mycrypt /mnt/sekret
# /dev/mapper/mycrypt /mnt/sekret ext3 noauto,noatime 0 0
# umount /mnt/sekret
#!/bin/sh
lvm2 over dmcryptBy default, lvm2 does not consider device-mapper block devices (such as a dm-crypt device) for use as physical volumes. In order to use a dm-crypt device as an lvm2 pv, add this line to the devices block in /etc/lvm/lvm.conf:types = [ "device-mapper", 16 ]
# lvm dumpconfig > /etc/lvm/lvm.conf |
