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.

How to create an encrypted LUKS disk image

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

Leave a comment