Skip to content

Instantly share code, notes, and snippets.

@mbr0wn
Last active March 10, 2019 02:15
Show Gist options
  • Save mbr0wn/28ac9644c243cf428ff696fdaedf64af to your computer and use it in GitHub Desktop.
Save mbr0wn/28ac9644c243cf428ff696fdaedf64af to your computer and use it in GitHub Desktop.
Create LUKS encrypted storage, remount

Setup

$DEV=/dev/sdXY # This is the device that gets blown away and encrypted
$MAP=backup # This is an identifier, will create a node at /dev/mapper/$MAP

Create encrypted volume:

cryptsetup -y -v luksFormat $DEV

To open it, check status:

cryptsetup luksOpen $DEV $MAP
ls -l /dev/mapper/$MAP
cryptsetup -v status $MAP
cryptsetup luksDump $DEV

This will erase all patterns, helps keeping it safe (takes forever, though):

dd if=/dev/zero of=/dev/mapper/backup2 status=progress

Now create a FS:

mkfs.ext4 /dev/mapper/$MAP

If OS doesn't auto-mount:

mkdir /mnt/$MAP
mount /dev/mapper/$MAP /mnt/$MAP

Now check it's there:

df -H
cd /mnt/$MAP
ls -l

You're good!

Unmount

umount /mnt/$MAP
cryptsetup luksClose $MAP

Remount

cryptsetup luksOpen $DEV $MAP
mount /dev/mapper/$MAP /mnt/$MAP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment