Skip to content

Instantly share code, notes, and snippets.

@fellipec
Created July 7, 2023 15:54
Show Gist options
  • Save fellipec/2e41bfd8a015646fcb17388deea961a2 to your computer and use it in GitHub Desktop.
Save fellipec/2e41bfd8a015646fcb17388deea961a2 to your computer and use it in GitHub Desktop.
Create a LUKS Encrypted Disk Image

Create LUKS Encrypted Disk Image

Create an empty virtual disk

dd if=/dev/zero of=/home/user/luksvolume1 bs=1M count=512

Format/encrypt it with LUKS

cryptsetup -vy luksFormat /home/user/luksvolume1

You will be asked to provide a passphrase.

Open the new encrypted container

sudo cryptsetup luksOpen /home/user/luksvolume1 myluksvol1

This will prompt for the passphrase.

Format it

sudo mkfs.ext4 /dev/mapper/myluksvol1

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.

Unmount and Close

sudo umount /mnt && sudo cryptsetup luksClose myluksvol1

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

Open the encrypted container

sudo cryptsetup luksOpen /home/user/luksvolume1 myluksvol1

File system check

sudo fsck /dev/mapper/myluksvol1

Mount and etc. then close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment