How to create an encrypted LUKS disk image

This could be a great alternative if you have used TrueCrypt encrypted volumes.

I’ve been a TrueCrypt lover for a long time, even after it was allegedly killed. But now I’m starting to think that it’s not a good option for long term safekeeping of my memories. At time point in a future release of Linux if dependencies for TrueCrypt stop working that’s death to my archives.  Fortunately we have LUKS since 2004! After using LUKS for a couple of years I think it’s very reliable.

Now, it’s time to replace TrueCrypt volumes with LUKS disk images. I experimented with a 512 MB virtual disk and it worked like a charm. Here are my steps in a basic example (Ubuntu).

  1. Create an empty virtual disk
    dd if=/dev/zero of=/home/shaakunthala/luksvolume1 bs=1M count=512
  2. Format/ encrypt it with LUKS
    cryptsetup -vy luksFormat /home/shaakunthala/luksvolume1

    You will be asked to provide a passphrase.

  3. Open the new encrypted container
    sudo cryptsetup luksOpen /home/shaakunthala/luksvolume1 myluksvol1

    This will prompt for the passphrase.

  4. Format it
    sudo mkfs.ext4 /dev/mapper/myluksvol1
  5. Mount
    sudo mount /dev/mapper/myluksvol1 /mnt

    If you are using Ubuntu, you will be see a removable device icon. Without using the command line, you can alternatively use it to do one-click mount/ unmount.

  6. Unmount and Close
    sudo umount /mnt && sudo cryptsetup luksClose myluksvol1

In case of an abnormal shutdown/ power failure while using the encrypted volume,

  1. Open the encrypted container
    sudo cryptsetup luksOpen /home/shaakunthala/luksvolume1 myluksvol1
  2. File system check
    sudo fsck /dev/mapper/myluksvol1
  3. Mount and etc. then close.

Now, just create one big as you want, mount and then copy your files. Don’t forget to unmount and properly close the encrypted volume once you are done with your work every time.

Advertisements
How to create an encrypted LUKS disk image

2 thoughts on “How to create an encrypted LUKS disk image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s