Kali Encrypted Persistence

For my own reference, here’s a script. Use at your own risk, if at all.

Must be run using sudo or as root.

#!/usr/bin/env bash

if [[ "$1" == "" ]]; then
    echo "A partition must be passed in."
    exit
fi

partition=$1

cryptsetup --verbose --verify-passphrase luksFormat $partition
cryptsetup luksOpen $partition persistence
mkfs.ext4 -L persistence /dev/mapper/persistence
mkdir -p /tmp/persistence
mount /dev/mapper/persistence /tmp/persistence
echo '/ union' > /tmp/persistence/persistence.conf
umount /tmp/persistence
cryptsetup luksClose /dev/mapper/persistence
sync
eject $partition