Encrypt partition with dm-crypt
Wednesday, November 30th, 2011
Ever wnated to have your external disk or USB stick encrypted? This is a way to get there on a Debian-based system using dm-crypt and LUKS.
First, make sure dm-crypt module is loaded (see if /dev/mapper/ is present), and if not, load the module:
modprobe dm-crypt
Now you can use cryptsetup to encrypt your device (you’ll be asked for a password):
cryptsetup --verbose --key-size 256 --verify-passphrase luksFormat /dev/sdd1
After this step, you can open the encrypted disk.
cryptsetup luksOpen /dev/sbd1 mydisk
The disk is not ready yet, we need to format it first, just as if we connected an empty device. In theis example, I’ll format it using ext3 file system.
mkfs.ext3 -j -m 1 -O dir_index,filetype /dev/mapper/mydisk
Now you can finally mount and access your disk.
mount -t ext3 /dev/mapper/mydisk /media/mydisk
When you’re done and want to unplug the device, you unmount it the usual way:
umount /dev/mapper/encr-zipdisk
and then use LUKS to close the encrypted connection:
cryptsetup luksClose encr-zipdisk
Now you can remove the device.
I ran across a problem when trying to run a program located in “Program Files” directory from within a Python application using os.system(). It was obvious that the problem was caused by the space character in the name of the directory. I didn’t know how to solve the issue as I’m not proficient in Python and also not very comfortable in the Windows environment. Luckily, once again, there were others before me, who had found the way:

