This is useful to conveniently store data securely, handling like a virtual encrypted USB stick.
Create a disk image:
In order to create a 2 GB image file, execute the following command:
Code: Select all
$ dd if=/dev/zero of=4gb_sd.bin bs=1G count=4
The following command should return the name of a loop device that's free for you to use:
Code: Select all
$ sudo losetup -f
But if you do, then it will list the next "free" loop device
Setup partition encryption (LUKS):
$DEV is a variable for the loop device, assigned to this image. In our example it's "/dev/loop0".
$IMAGE is the image file, created previously using "dd".
Code: Select all
$ sudo losetup $DEV $IMAGE
$ sudo cryptsetup luksFormat $DEV
The "cryptsetup luksFormat" dialog will look somewhat like this:
Now, open the encrypted partition:WARNING!
========
This will overwrite data on /dev/loop3 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Code: Select all
$ sudo cryptsetup luksOpen $DEV $NAME
Enter it.Enter passphrase for /dev/loop3:
If everything works correctly, it will return nothing.
Partition / format it:
Code: Select all
$ sudo mkfs.ext4 -F -L "$PARTITON_LABEL" "$/dev/mapper/$NAME"
Code: Select all
$ sudo cryptsetup luksClose /dev/mapper/$NAME