luks encrypted container
may 2, 2026
create a contaniner file
touch vault.img
chattr +C vault.img # for btrfs only to disable NoCow
allocate storage to the vault, choose it wisely its not that simple to resize later
fallocate -l 20G vault.img
encrypt the container with luks
cryptsetup luksFormat vault.img
you can open and close the vault using cryptsetup command
# to open
sudo cryptsetup open vault.img vault
# to close
sudo cryptsetup close vault
now since the vault is open and encrypted, but what is a contiainer without a file system we are going to make the container ext4 you can anything else.
sudo mkfs.ext4 /dev/mapper/vault
well thats it for it to start working and showing up in your file manager but you can mount it to a mount point like
sudo mount /dev/mapper/vault /mnt/vault
add alias to open and close vaults
alias vaultmount="sudo cryptsetup open ~/.local/state/vault.img vault && sudo mount /dev/mapper/vault /mnt/vault"
alias vaultumount="sudo umount /mnt/vault && sudo cryptsetup close vault"
thats it everything is done now, you can add it in fstab to auto mount but i dont want to do that.