mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
1.7 KiB
1.7 KiB
Create, mount and use an encrypted disk
Table of contents
TL;DR
# Encrypt the device.
sudo cryptsetup luksFormat '/dev/sda'
# Open the encrypted device.
# 'mapper_name' is any name you want. It will be used by the device mapper.
sudo cryptsetup open '/dev/sda' 'mapper_name'
# Format the volume.
sudo mkfs.btrfs -f --label 'label' -m 'dup' '/dev/mapper/mapper_name'
# Mount the volume.
mkdir -p 'path/to/mount/point'
sudo mount -t 'filesystem' -o 'mount,options' '/dev/mapper/mapper_name' 'path/to/mount/point'
# Do something.
sudo chown 'user':'group' 'path/to/subvolume/in/mount/point'
btrfs subvolume create 'path/to/subvolume/in/mount/point'
parallel -j1 \
'sudo btrfs send source/volume/.snapshots/{} | sudo btrfs receive destination/volume' \
::: $(ls source/volume/.snapshots)
parallel -q \
btrfs subvolume snapshot -r volume/{} volume/.snapshots/$(date +%FT%T)/{} \
::: $(ls source/volume)
# Umount the volume.
sudo umount 'path/to/mount/point'
# Close the device.
sudo cryptsetup close '/dev/mapper/mapper_name'
Further readings
Sources
All the references in the further readings section, plus the following:
- script: Create an encrypted BTRFS device
- script: Create an encrypted ZFS device